Mercurial > hg-stable
changeset 52015:2924676d4728
tests: force `seq` to print with '\n' EOL
It looks like consistent EOL is the reason for 0605726179a0, but now on py3,
`print()` uses the platform EOL without regard to binary mode. The tests mostly
use this to loop over a sequence of number in the shell, but there are a handful
that redirect output to a file. Specifically, this fixes Windows runs of
`test-bundle2-multiple-changegroups.t`, but there may be other tests this fixes.
Some other `tests/*.py` files also set binary mode on stdout, but they also
write bytes directly to `sys.stdout.buffer`. I'm not doing that here because
PyCharm flags these write calls for passing bytes instead of str (PyCharm is
likely wrong, but possibly confused because the code falls back to `sys.stdout`
if there is no `.buffer` attribute), and it's annoying.
author | Matt Harbison <matt_harbison@yahoo.com> |
---|---|
date | Mon, 07 Oct 2024 16:20:07 -0400 |
parents | a878d260ec57 |
children | 92a708af7b05 |
files | tests/seq.py |
diffstat | 1 files changed, 7 insertions(+), 9 deletions(-) [+] |
line wrap: on
line diff
--- a/tests/seq.py Mon Oct 07 15:48:06 2024 -0400 +++ b/tests/seq.py Mon Oct 07 16:20:07 2024 -0400 @@ -7,17 +7,15 @@ # seq START STOP [START, STOP] stepping by 1 # seq START STEP STOP [START, STOP] stepping by STEP -import os +import io import sys -try: - import msvcrt - - msvcrt.setmode(sys.stdin.fileno(), os.O_BINARY) - msvcrt.setmode(sys.stdout.fileno(), os.O_BINARY) - msvcrt.setmode(sys.stderr.fileno(), os.O_BINARY) -except ImportError: - pass +sys.stdout = io.TextIOWrapper( + sys.stdout.buffer, + sys.stdout.encoding, + sys.stdout.errors, + newline="\n", +) start = 1 if len(sys.argv) > 2: