tests: force \n newlines when writing to sys.stdout
authorGregory Szorc <gregory.szorc@gmail.com>
Sun, 29 Mar 2020 13:51:26 -0700
changeset 44656 d359f0d1a3d3
parent 44655 02fa5392bab6
child 44657 47e6ec977555
tests: force \n newlines when writing to sys.stdout Without this, Python 3 on Windows inserts some \r that aren't present in the input, causing test-http-bad-server.t to fail. After this change, the test passes on Python 3 on Windows! Differential Revision: https://phab.mercurial-scm.org/D8341
tests/filtertraceback.py
--- a/tests/filtertraceback.py	Sun Mar 29 13:06:59 2020 -0700
+++ b/tests/filtertraceback.py	Sun Mar 29 13:51:26 2020 -0700
@@ -4,8 +4,19 @@
 
 from __future__ import absolute_import, print_function
 
+import io
 import sys
 
+if sys.version_info[0] >= 3:
+    # Prevent \r from being inserted on Windows.
+    sys.stdout = io.TextIOWrapper(
+        sys.stdout.buffer,
+        sys.stdout.encoding,
+        sys.stdout.errors,
+        newline="\n",
+        line_buffering=sys.stdout.line_buffering,
+    )
+
 state = 'none'
 
 for line in sys.stdin: