From c93b0eb620841d4dffbb028278e91dde58a51899 Mon Sep 17 00:00:00 2001 From: Jonathan Lange Date: Thu, 9 Feb 2012 18:04:37 +0000 Subject: Fix to call the public API in testtools. --- python/subunit/__init__.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'python') diff --git a/python/subunit/__init__.py b/python/subunit/__init__.py index b4c9397..2b494de 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')) + content = TracebackContent(error, test) + for bytes in content.iter_bytes(): + self._stream.write(bytes) elif details is not None: self._write_details(details) else: -- cgit v1.2.1 From 09464f83ccfb2d99342a887973cc39ead91a1ced Mon Sep 17 00:00:00 2001 From: Jonathan Lange Date: Thu, 9 Feb 2012 18:40:15 +0000 Subject: Don't make so many assumptions about how testtools formats details. --- python/subunit/tests/test_test_protocol.py | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) (limited to 'python') diff --git a/python/subunit/tests/test_test_protocol.py b/python/subunit/tests/test_test_protocol.py index c93aabd..1c8bc05 100644 --- a/python/subunit/tests/test_test_protocol.py +++ b/python/subunit/tests/test_test_protocol.py @@ -19,9 +19,10 @@ import unittest import os from testtools import skipIf, TestCase -from testtools.compat import _b, _u, BytesIO, StringIO -from testtools.content import Content, TracebackContent +from testtools.compat import _b, _u, BytesIO +from testtools.content import Content, TracebackContent, text_content from testtools.content_type import ContentType +from testtools.testresult.real import _details_to_str try: from testtools.testresult.doubles import ( Python26TestResult, @@ -87,11 +88,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 +104,8 @@ class TestTestProtocolServerPipe(unittest.TestCase): [(an_error, _remote_exception_str + '\n')]) self.assertEqual( client.failures, - [(bing, _remote_exception_str + ": Text attachment: traceback\n" - "------------\nfoo.c:53:ERROR invalid state\n" - "------------\n\n")]) + [(bing, _remote_exception_str + ": " + + _details_to_str({'traceback': text_content(traceback)}, 'traceback') + "\n")]) self.assertEqual(client.testsRun, 3) def test_non_test_characters_forwarded_immediately(self): @@ -559,9 +560,8 @@ class TestTestProtocolServerAddxFail(unittest.TestCase): value = details else: if error_message is not None: - value = subunit.RemoteError(_u("Text attachment: traceback\n" - "------------\n") + _u(error_message) + - _u("------------\n")) + value = subunit.RemoteError( + _details_to_str(details, special='traceback')) else: value = subunit.RemoteError() self.assertEqual([ -- cgit v1.2.1 From de8252553e37188f05ca1e0dcb039edcc37f80eb Mon Sep 17 00:00:00 2001 From: Jonathan Lange Date: Thu, 9 Feb 2012 19:01:04 +0000 Subject: Code that works for 0.9.11 and against testtools trunk --- python/subunit/tests/test_test_protocol.py | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) (limited to 'python') diff --git a/python/subunit/tests/test_test_protocol.py b/python/subunit/tests/test_test_protocol.py index 1c8bc05..e0710f4 100644 --- a/python/subunit/tests/test_test_protocol.py +++ b/python/subunit/tests/test_test_protocol.py @@ -18,11 +18,10 @@ 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, text_content from testtools.content_type import ContentType -from testtools.testresult.real import _details_to_str try: from testtools.testresult.doubles import ( Python26TestResult, @@ -41,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): @@ -105,7 +108,7 @@ class TestTestProtocolServerPipe(unittest.TestCase): self.assertEqual( client.failures, [(bing, _remote_exception_str + ": " - + _details_to_str({'traceback': text_content(traceback)}, 'traceback') + "\n")]) + + details_to_str({'traceback': text_content(traceback)}) + "\n")]) self.assertEqual(client.testsRun, 3) def test_non_test_characters_forwarded_immediately(self): @@ -560,8 +563,7 @@ class TestTestProtocolServerAddxFail(unittest.TestCase): value = details else: if error_message is not None: - value = subunit.RemoteError( - _details_to_str(details, special='traceback')) + value = subunit.RemoteError(details_to_str(details)) else: value = subunit.RemoteError() self.assertEqual([ -- cgit v1.2.1 From 407c7088c7ea48af25546102d1861295f3a9ec60 Mon Sep 17 00:00:00 2001 From: Jonathan Lange Date: Thu, 16 Feb 2012 09:59:12 +0000 Subject: Make sure the tests pass with 0.9.11 as well as 0.9.12 & 13 --- python/subunit/tests/test_test_protocol.py | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) (limited to 'python') diff --git a/python/subunit/tests/test_test_protocol.py b/python/subunit/tests/test_test_protocol.py index 60f05b3..ec6830d 100644 --- a/python/subunit/tests/test_test_protocol.py +++ b/python/subunit/tests/test_test_protocol.py @@ -107,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): @@ -564,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([ -- cgit v1.2.1 From 7b94c24469146ec7844cd678806403db3c3ebfeb Mon Sep 17 00:00:00 2001 From: Jonathan Lange Date: Thu, 16 Feb 2012 10:18:09 +0000 Subject: Clean up a flake --- python/subunit/__init__.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'python') diff --git a/python/subunit/__init__.py b/python/subunit/__init__.py index 93092b1..8f2a9ed 100644 --- a/python/subunit/__init__.py +++ b/python/subunit/__init__.py @@ -683,8 +683,8 @@ class TestProtocolClient(testresult.TestResult): raise ValueError if error is not None: self._stream.write(self._start_simple) - content = TracebackContent(error, test) - for bytes in content.iter_bytes(): + 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) -- cgit v1.2.1