Patchwork py3: use bytes stdout in test-check-help.t

login
register
mail settings
Submitter Matt Harbison
Date Dec. 18, 2018, 7:11 p.m.
Message ID <b287acea09a9edfce8f8.1545160263@Envy>
Download mbox | patch
Permalink /patch/37237/
State Accepted
Headers show

Comments

Matt Harbison - Dec. 18, 2018, 7:11 p.m.
# HG changeset patch
# User Matt Harbison <matt_harbison@yahoo.com>
# Date 1545159666 18000
#      Tue Dec 18 14:01:06 2018 -0500
# Node ID b287acea09a9edfce8f8045e489b590645f92567
# Parent  932ed8a051de1d7ef7aee5af66395b48080f17b3
py3: use bytes stdout in test-check-help.t

Setting stdout to binary seemed to have no effect on Windows, as it was
appending a literal '\r' to each topic keyword.  This also stops prepending 'b'
to the topic on all platforms as well.
Yuya Nishihara - Dec. 19, 2018, 11:24 a.m.
On Tue, 18 Dec 2018 14:11:03 -0500, Matt Harbison wrote:
> # HG changeset patch
> # User Matt Harbison <matt_harbison@yahoo.com>
> # Date 1545159666 18000
> #      Tue Dec 18 14:01:06 2018 -0500
> # Node ID b287acea09a9edfce8f8045e489b590645f92567
> # Parent  932ed8a051de1d7ef7aee5af66395b48080f17b3
> py3: use bytes stdout in test-check-help.t

Queued, thanks.

> Setting stdout to binary seemed to have no effect on Windows,

It's needed for Python 2 (i.e. libc), and sys.stdout.buffer is required for
Python 3.

Patch

diff --git a/tests/test-check-help.t b/tests/test-check-help.t
--- a/tests/test-check-help.t
+++ b/tests/test-check-help.t
@@ -10,13 +10,14 @@ 
   >     import msvcrt
   >     import os
   >     msvcrt.setmode(sys.stdout.fileno(), os.O_BINARY)
+  > stdout = getattr(sys.stdout, 'buffer', sys.stdout)
   > topics = set()
   > topicre = re.compile(br':hg:`help ([a-z0-9\-.]+)`')
   > for fname in sys.argv:
   >     with open(fname, 'rb') as f:
   >         topics.update(m.group(1) for m in topicre.finditer(f.read()))
   > for s in sorted(topics):
-  >     print(s)
+  >     stdout.write(b'%s\n' % s)
   > EOF
 
   $ cd "$TESTDIR"/..