summaryrefslogtreecommitdiff
path: root/python
diff options
context:
space:
mode:
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):