From 056579b9befb55978ed71aad9a5745df48c7681e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mat=C4=9Bj=20Cepl?= Date: Thu, 13 Sep 2018 16:39:47 +0200 Subject: Remove dependency on unittest2 It is questionable whether it is actually the right way how to do it. I would need a review from somebody who actually understands API and the protocol, whether I am not unintentionally changing API. --- python/subunit/tests/test_test_protocol.py | 34 ++++++++++++++++++++---------- 1 file changed, 23 insertions(+), 11 deletions(-) (limited to 'python') diff --git a/python/subunit/tests/test_test_protocol.py b/python/subunit/tests/test_test_protocol.py index 7427b12..3d042ef 100644 --- a/python/subunit/tests/test_test_protocol.py +++ b/python/subunit/tests/test_test_protocol.py @@ -16,10 +16,10 @@ import datetime import io -import unittest2 as unittest import os import sys import tempfile +import unittest from testtools import PlaceHolder, skipIf, TestCase, TestResult from testtools.compat import _b, _u, BytesIO @@ -152,13 +152,20 @@ class TestTestProtocolServerPipe(unittest.TestCase): protocol.readFrom(pipe) bing = subunit.RemotedTestCase("bing crosby") an_error = subunit.RemotedTestCase("an error") - self.assertEqual( - client.errors, - [(an_error, tb_prelude + _remote_exception_repr + '\n')]) - self.assertEqual( - client.failures, - [(bing, tb_prelude + _remote_exception_repr + ": " - + details_to_str({'traceback': text_content(traceback)}) + "\n")]) + if sys.version_info[0] >= 3: + self.assertEqual(client.errors, + [(an_error, _remote_exception_repr + '\n')]) + self.assertEqual( + client.failures, + [(bing, _remote_exception_repr + ": " + + details_to_str({'traceback': text_content(traceback)}) + "\n")]) + else: + self.assertEqual(client.errors, + [(an_error, '_StringException\n')]) + self.assertEqual( + client.failures, + [(bing, "_StringException: " + + details_to_str({'traceback': text_content(traceback)}) + "\n")]) self.assertEqual(client.testsRun, 3) def test_non_test_characters_forwarded_immediately(self): @@ -1012,9 +1019,14 @@ class TestRemotedTestCase(unittest.TestCase): "'A test description'>", "%r" % test) result = unittest.TestResult() test.run(result) - self.assertEqual([(test, tb_prelude + _remote_exception_repr + ": " - "Cannot run RemotedTestCases.\n\n")], - result.errors) + if sys.version_info[0] >= 3: + self.assertEqual([(test, _remote_exception_repr + ': ' + + "Cannot run RemotedTestCases.\n\n")], + result.errors) + else: + self.assertEqual([(test, "_StringException: " + + "Cannot run RemotedTestCases.\n\n")], + result.errors) self.assertEqual(1, result.testsRun) another_test = subunit.RemotedTestCase("A test description") self.assertEqual(test, another_test) -- cgit v1.2.1 From 00cae3a57f5bbe56b0763e2fbdd6df13eb924a3e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mat=C4=9Bj=20Cepl?= Date: Fri, 5 Jun 2020 10:26:21 +0200 Subject: Acommodate review requests. --- python/subunit/tests/test_test_protocol.py | 10 +++++----- 1 file changed, 5 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 3d042ef..c5f5c1d 100644 --- a/python/subunit/tests/test_test_protocol.py +++ b/python/subunit/tests/test_test_protocol.py @@ -19,9 +19,9 @@ import io import os import sys import tempfile -import unittest from testtools import PlaceHolder, skipIf, TestCase, TestResult +from testtools.testcase import six, unittest from testtools.compat import _b, _u, BytesIO from testtools.content import Content, TracebackContent, text_content from testtools.content_type import ContentType @@ -60,7 +60,7 @@ class TestHelpers(TestCase): fd, file_path = tempfile.mkstemp() self.addCleanup(os.remove, file_path) fake_file = os.fdopen(fd, 'r') - if sys.version_info > (3, 0): + if six.PY3: self.assertEqual(fake_file.buffer, subunit._unwrap_text(fake_file)) else: @@ -70,7 +70,7 @@ class TestHelpers(TestCase): fd, file_path = tempfile.mkstemp() self.addCleanup(os.remove, file_path) fake_file = os.fdopen(fd, 'w') - if sys.version_info > (3, 0): + if six.PY3: self.assertEqual(fake_file.buffer, subunit._unwrap_text(fake_file)) else: @@ -152,7 +152,7 @@ class TestTestProtocolServerPipe(unittest.TestCase): protocol.readFrom(pipe) bing = subunit.RemotedTestCase("bing crosby") an_error = subunit.RemotedTestCase("an error") - if sys.version_info[0] >= 3: + if six.PY3: self.assertEqual(client.errors, [(an_error, _remote_exception_repr + '\n')]) self.assertEqual( @@ -1019,7 +1019,7 @@ class TestRemotedTestCase(unittest.TestCase): "'A test description'>", "%r" % test) result = unittest.TestResult() test.run(result) - if sys.version_info[0] >= 3: + if six.PY3: self.assertEqual([(test, _remote_exception_repr + ': ' + "Cannot run RemotedTestCases.\n\n")], result.errors) -- cgit v1.2.1 From 4b1686df78729388a6d687fec3db1d96f22c6f7b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mat=C4=9Bj=20Cepl?= Date: Fri, 5 Jun 2020 11:22:35 +0200 Subject: Unittest from testtools doesn't work, use the one from stdlib. --- python/subunit/tests/test_test_protocol.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'python') diff --git a/python/subunit/tests/test_test_protocol.py b/python/subunit/tests/test_test_protocol.py index c5f5c1d..86aa4a6 100644 --- a/python/subunit/tests/test_test_protocol.py +++ b/python/subunit/tests/test_test_protocol.py @@ -17,11 +17,10 @@ import datetime import io import os -import sys import tempfile +import unittest from testtools import PlaceHolder, skipIf, TestCase, TestResult -from testtools.testcase import six, unittest from testtools.compat import _b, _u, BytesIO from testtools.content import Content, TracebackContent, text_content from testtools.content_type import ContentType @@ -38,6 +37,7 @@ except ImportError: ExtendedTestResult, ) from testtools.matchers import Contains +from testtools.testcase import six import subunit from subunit.tests import ( @@ -48,7 +48,7 @@ from subunit.tests import ( import subunit.iso8601 as iso8601 -tb_prelude = "Traceback (most recent call last):\n" +tb_prelude = "Traceback (most recent call last):\n" def details_to_str(details): -- cgit v1.2.1