On windows, ProtocolTestCase and TestProtocolClient will set their streams to
authorRobert Collins <robertc@robertcollins.net>
Wed, 12 May 2010 15:22:47 +0000 (03:22 +1200)
committerRobert Collins <robertc@robertcollins.net>
Wed, 12 May 2010 15:22:47 +0000 (03:22 +1200)
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)

NEWS
python/subunit/__init__.py
python/subunit/tests/test_test_protocol.py

diff --git a/NEWS b/NEWS
index 7c933c8f6e68cc37f4822528d2c59d16a4a1319f..45a3f66131f74ed9359f80796d32baa0e994d069 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -15,6 +15,11 @@ BUG FIXES
   is purely cosmetic as the parameters are passed down with no interpretation.
   (Robert Collins, #537611)
 
+* 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)
+
 0.0.5
 -----
 
index 4b25ca3a39fc7a3dfd44aad75966e95f5108b052..bcba63ee11d78750fcffac94d3399a4c0d4cc006 100644 (file)
@@ -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)
index f10380b09b69323c850a9ae6daa9e267a137d0f9..ae9cf53011e86fe4fe881e1358e665b468592992 100644 (file)
@@ -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):