Patchwork D8341: tests: force \n newlines when writing to sys.stdout

login
register
mail settings
Submitter phabricator
Date March 30, 2020, 1:30 a.m.
Message ID <differential-rev-PHID-DREV-l57uf4xn2ebaiugaswgq-req@mercurial-scm.org>
Download mbox | patch
Permalink /patch/45940/
State Superseded
Headers show

Comments

phabricator - March 30, 2020, 1:30 a.m.
indygreg created this revision.
Herald added a subscriber: mercurial-devel.
Herald added a reviewer: hg-reviewers.

REVISION SUMMARY
  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!

REPOSITORY
  rHG Mercurial

BRANCH
  default

REVISION DETAIL
  https://phab.mercurial-scm.org/D8341

AFFECTED FILES
  tests/filtertraceback.py

CHANGE DETAILS




To: indygreg, #hg-reviewers
Cc: mercurial-devel

Patch

diff --git a/tests/filtertraceback.py b/tests/filtertraceback.py
--- a/tests/filtertraceback.py
+++ b/tests/filtertraceback.py
@@ -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: