summaryrefslogtreecommitdiff
path: root/python
diff options
context:
space:
mode:
Diffstat (limited to 'python')
-rw-r--r--python/subunit/__init__.py12
-rw-r--r--python/subunit/tests/test_test_protocol.py20
2 files changed, 18 insertions, 14 deletions
diff --git a/python/subunit/__init__.py b/python/subunit/__init__.py
index b30b8fe..8f2a9ed 100644
--- a/python/subunit/__init__.py
+++ b/python/subunit/__init__.py
@@ -123,6 +123,7 @@ import sys
import unittest
from testtools import content, content_type, ExtendedToOriginalDecorator
+from testtools.content import TracebackContent
from testtools.compat import _b, _u, BytesIO, StringIO
try:
from testtools.testresult.real import _StringException
@@ -682,10 +683,9 @@ class TestProtocolClient(testresult.TestResult):
raise ValueError
if error is not None:
self._stream.write(self._start_simple)
- # XXX: this needs to be made much stricter, along the lines of
- # Martin[gz]'s work in testtools. Perhaps subunit can use that?
- for line in self._exc_info_to_unicode(error, test).splitlines():
- self._stream.write(("%s\n" % line).encode('utf8'))
+ tb_content = TracebackContent(error, test)
+ for bytes in tb_content.iter_bytes():
+ self._stream.write(bytes)
elif details is not None:
self._write_details(details)
else:
@@ -1131,7 +1131,7 @@ class ProtocolTestCase(object):
:seealso: TestProtocolServer (the subunit wire protocol parser).
"""
- def __init__(self, stream, passthrough=None, forward=False):
+ def __init__(self, stream, passthrough=None, forward=None):
"""Create a ProtocolTestCase reading from stream.
:param stream: A filelike object which a subunit stream can be read
@@ -1144,6 +1144,8 @@ class ProtocolTestCase(object):
self._stream = stream
_make_stream_binary(stream)
self._passthrough = passthrough
+ if forward is not None:
+ _make_stream_binary(forward)
self._forward = forward
def __call__(self, result=None):
diff --git a/python/subunit/tests/test_test_protocol.py b/python/subunit/tests/test_test_protocol.py
index e513ca8..ec6830d 100644
--- a/python/subunit/tests/test_test_protocol.py
+++ b/python/subunit/tests/test_test_protocol.py
@@ -18,9 +18,9 @@ import datetime
import unittest
import os
-from testtools import skipIf, TestCase
+from testtools import skipIf, TestCase, TestResult
from testtools.compat import _b, _u, BytesIO
-from testtools.content import Content, TracebackContent
+from testtools.content import Content, TracebackContent, text_content
from testtools.content_type import ContentType
try:
from testtools.testresult.doubles import (
@@ -40,6 +40,10 @@ from subunit import _remote_exception_str, _remote_exception_str_chunked
import subunit.iso8601 as iso8601
+def details_to_str(details):
+ return TestResult()._err_details_to_string(None, details=details)
+
+
class TestTestImports(unittest.TestCase):
def test_imports(self):
@@ -87,11 +91,12 @@ class TestTestProtocolServerPipe(unittest.TestCase):
def test_story(self):
client = unittest.TestResult()
protocol = subunit.TestProtocolServer(client)
+ traceback = "foo.c:53:ERROR invalid state\n"
pipe = BytesIO(_b("test old mcdonald\n"
"success old mcdonald\n"
"test bing crosby\n"
"failure bing crosby [\n"
- "foo.c:53:ERROR invalid state\n"
+ + traceback +
"]\n"
"test an error\n"
"error an error\n"))
@@ -102,9 +107,8 @@ class TestTestProtocolServerPipe(unittest.TestCase):
[(an_error, _remote_exception_str + '\n')])
self.assertEqual(
client.failures,
- [(bing, _remote_exception_str +
- ": foo.c:53:ERROR invalid state\n"
- "\n")])
+ [(bing, _remote_exception_str + ": "
+ + details_to_str({'traceback': text_content(traceback)}) + "\n")])
self.assertEqual(client.testsRun, 3)
def test_non_test_characters_forwarded_immediately(self):
@@ -559,9 +563,7 @@ class TestTestProtocolServerAddxFail(unittest.TestCase):
value = details
else:
if error_message is not None:
- if not len(error_message.strip()):
- error_message = _u("Empty attachments:\n traceback\n")
- value = subunit.RemoteError(_u(error_message))
+ value = subunit.RemoteError(details_to_str(details))
else:
value = subunit.RemoteError()
self.assertEqual([