summaryrefslogtreecommitdiff
path: root/python
diff options
context:
space:
mode:
authorRobert Collins <robertc@robertcollins.net>2010-05-13 03:22:47 +1200
committerRobert Collins <robertc@robertcollins.net>2010-05-13 03:22:47 +1200
commit15319ea5c759d6128845035b356092106ad95864 (patch)
tree526500154f9763b39daf6e4e885fe1449b35e69c /python
parent76ef047c1ef4545aa10655e9acdb31a280fc7203 (diff)
downloadsubunit-git-15319ea5c759d6128845035b356092106ad95864.tar.gz
On windows, ProtocolTestCase and TestProtocolClient will set their streams to
binary mode by calling into msvcrt; this avoids having their input or output mangled by the default line ending translation on that platform. (Robert Collins, Martin [gz], #579296)
Diffstat (limited to 'python')
-rw-r--r--python/subunit/__init__.py14
-rw-r--r--python/subunit/tests/test_test_protocol.py3
2 files changed, 17 insertions, 0 deletions
diff --git a/python/subunit/__init__.py b/python/subunit/__init__.py
index 4b25ca3..bcba63e 100644
--- a/python/subunit/__init__.py
+++ b/python/subunit/__init__.py
@@ -552,6 +552,7 @@ class TestProtocolClient(unittest.TestResult):
def __init__(self, stream):
unittest.TestResult.__init__(self)
self._stream = stream
+ _make_stream_binary(stream)
def addError(self, test, error=None, details=None):
"""Report an error in test test.
@@ -1045,8 +1046,10 @@ class ProtocolTestCase(object):
subunit input is not forwarded.
"""
self._stream = stream
+ _make_stream_binary(stream)
self._passthrough = passthrough
self._forward = forward
+ _make_stream_binary(forward)
def __call__(self, result=None):
return self.run(result)
@@ -1124,3 +1127,14 @@ def get_default_formatter():
else:
return sys.stdout
+
+def _make_stream_binary(stream):
+ """Ensure that a stream will be binary safe. See _make_binary_on_windows."""
+ if getattr(stream, 'fileno', None) is not None:
+ _make_binary_on_windows(stream.fileno())
+
+def _make_binary_on_windows(fileno):
+ """Win32 mangles \r\n to \n and that breaks streams. See bug lp:505078."""
+ if sys.platform == "win32":
+ import msvcrt
+ msvcrt.setmode(fileno, os.O_BINARY)
diff --git a/python/subunit/tests/test_test_protocol.py b/python/subunit/tests/test_test_protocol.py
index f10380b..ae9cf53 100644
--- a/python/subunit/tests/test_test_protocol.py
+++ b/python/subunit/tests/test_test_protocol.py
@@ -102,6 +102,9 @@ class TestTestProtocolServerPipe(unittest.TestCase):
"------------\n\n")])
self.assertEqual(client.testsRun, 3)
+ def test_non_test_characters_forwarded_immediately(self):
+ pass
+
class TestTestProtocolServerStartTest(unittest.TestCase):