* Clients of subunit did not expect memoryview objects in StreamResult events.
authorRobert Collins <robertc@robertcollins.net>
Sat, 24 Aug 2013 13:51:28 +0000 (01:51 +1200)
committerRobert Collins <robertc@robertcollins.net>
Sat, 24 Aug 2013 13:51:28 +0000 (01:51 +1200)
  (Robert Collins)

NEWS
python/subunit/tests/test_test_protocol2.py
python/subunit/v2.py

diff --git a/NEWS b/NEWS
index 1e47c1325a1dad13b483f272a8e4737d37bd511a..391a6c0c475c9452365da0566a1f85a49a6f6796 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -5,6 +5,12 @@ subunit release notes
 NEXT (In development)
 ---------------------
 
+BUG FIXES
+~~~~~~~~~
+
+* Clients of subunit did not expect memoryview objects in StreamResult events.
+  (Robert Collins)
+
 0.0.14
 ------
 
index ded56b8616303b47656ab85523eb7d3db97cfb28..f88e0aa07b76fff3d6a8d77275bfff30c7eef625 100644 (file)
@@ -303,6 +303,10 @@ class TestByteStreamToStreamResult(TestCase):
             source, non_subunit_name="stdout").run(result)
         self.assertEqual(b'', source.read())
         self.assertEqual(events, result._events)
+        #- any file attachments should be byte contents [as users assume that].
+        for event in result._events:
+            if event[5] is not None:
+                self.assertIsInstance(event[6], bytes)
 
     def check_event(self, source_bytes, test_status=None, test_id="foo",
         route_code=None, timestamp=None, tags=None, mime_type=None,
index 0a7796f19d1091bb7d6b5a55aba1899f777354b2..1f5bfc1277ee9ab99cd8585a220567446b05bcb0 100644 (file)
@@ -385,8 +385,10 @@ class ByteStreamToStreamResult(object):
                         % (crc, packet_crc))
             if safe_hasattr(builtins, 'memoryview'):
                 body = memoryview(packet[-1])
+                view = True
             else:
                 body = packet[-1]
+                view = False
             # Discard CRC-32
             body = body[:-4]
             # One packet could have both file and status data; the Python API
@@ -421,6 +423,8 @@ class ByteStreamToStreamResult(object):
                 content_length, consumed = self._parse_varint(body, pos)
                 pos += consumed
                 file_bytes = body[pos:pos+content_length]
+                if view:
+                    file_bytes = file_bytes.tobytes()
                 if len(file_bytes) != content_length:
                     raise ParseError('File content extends past end of packet: '
                         'claimed %d bytes, %d available' % (