summaryrefslogtreecommitdiff
path: root/python/subunit
diff options
context:
space:
mode:
authorRobert Collins <robertc@robertcollins.net>2013-02-25 23:11:04 +1300
committerRobert Collins <robertc@robertcollins.net>2013-02-25 23:11:04 +1300
commitab7d4a5e0298ff075c2039746a34872e55cf0f8b (patch)
treebbbe737906f078b7581704a37274c84309fb0584 /python/subunit
parent96643dac00a588e683744815130cdb9d867b29a5 (diff)
downloadsubunit-ab7d4a5e0298ff075c2039746a34872e55cf0f8b.tar.gz
Make streams all binary and fix incorrect ordering of mime encoding.
Diffstat (limited to 'python/subunit')
-rw-r--r--python/subunit/v2.py17
1 files changed, 11 insertions, 6 deletions
diff --git a/python/subunit/v2.py b/python/subunit/v2.py
index 1245ae9..4380e05 100644
--- a/python/subunit/v2.py
+++ b/python/subunit/v2.py
@@ -18,6 +18,7 @@ import datetime
import struct
import zlib
+import subunit
import subunit.iso8601 as iso8601
__all__ = [
@@ -68,8 +69,10 @@ class StreamResultToBytes(object):
:param output_stream: A file-like object. Must support write(bytes)
and flush() methods. Flush will be called after each write.
+ The stream will be passed through subunit.make_stream_binary,
+ to handle regular cases such as stdout.
"""
- self.output_stream = output_stream
+ self.output_stream = subunit.make_stream_binary(output_stream)
def startTestRun(self):
pass
@@ -120,13 +123,13 @@ class StreamResultToBytes(object):
self._write_utf8(tag, packet)
if runnable:
flags = flags | FLAG_RUNNABLE
+ if mime_type:
+ flags = flags | FLAG_MIME_TYPE
+ self._write_utf8(mime_type, packet)
if file_name is not None:
flags = flags | FLAG_FILE_CONTENT
self._write_utf8(file_name, packet)
packet.append(file_bytes)
- if mime_type:
- flags = flags | FLAG_MIME_TYPE
- self._write_utf8(mime_type, packet)
if eof:
flags = flags | FLAG_EOF
# 0x0008 - not used in v2.
@@ -177,13 +180,15 @@ class ByteStreamToStreamResult(object):
"""Create a ByteStreamToStreamResult.
:param source: A file like object to read bytes from. Must support
- read(<count>). The file is not closed by ByteStreamToStreamResult.
+ read(<count>) and return bytes. The file is not closed by
+ ByteStreamToStreamResult. subunit.make_stream_binary() is
+ called on the stream to get it into bytes mode.
:param non_subunit_name: If set to non-None, non subunit content
encountered in the stream will be converted into file packets
labelled with this name.
"""
self.non_subunit_name = non_subunit_name
- self.source = source
+ self.source = subunit.make_stream_binary(source)
def run(self, result):
"""Parse source and emit events to result.