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/subunit') 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 0e14d8be6126315c19c40905d75e55b2bfe7ba09 Mon Sep 17 00:00:00 2001 From: Matthew Treinish Date: Mon, 4 Jan 2016 18:29:56 -0500 Subject: Add options to output filter to set timestamps This commit adds 2 new options to subunit-output, --start-time and --stop-time, to specify a timestamp for the start and end of a test in the output. --- python/subunit/_output.py | 29 +++++++++++++- python/subunit/tests/test_output_filter.py | 63 ++++++++++++++++++++++++++++++ 2 files changed, 91 insertions(+), 1 deletion(-) (limited to 'python/subunit') diff --git a/python/subunit/_output.py b/python/subunit/_output.py index aa92646..c598c81 100644 --- a/python/subunit/_output.py +++ b/python/subunit/_output.py @@ -22,6 +22,8 @@ from optparse import ( ) import sys +from dateutil import parser as date_parser + from subunit import make_stream_binary from subunit.iso8601 import UTC from subunit.v2 import StreamResultToBytes @@ -121,6 +123,18 @@ def parse_arguments(args=None, ParserClass=OptionParser): dest="tags", default=[] ) + parser.add_option( + "--start-time", + help="Specify a time for the test to start", + dest="start_time", + default=None + ) + parser.add_option( + "--stop-time", + help="Specify a time for the test to finish executing", + dest="stop_time", + default=None + ) (options, args) = parser.parse_args(args) if options.mimetype and not options.attach_file: @@ -152,6 +166,14 @@ def set_status_cb(option, opt_str, value, parser, status_name): def generate_stream_results(args, output_writer): + if args.start_time: + start_time = date_parser.parse(args.start_time) + else: + start_time = None + if args.stop_time: + stop_time = date_parser.parse(args.stop_time) + else: + stop_time = None output_writer.startTestRun() if args.attach_file: @@ -170,6 +192,7 @@ def generate_stream_results(args, output_writer): write_status = partial(write_status, mime_type=args.mimetype) if args.tags: write_status = partial(write_status, test_tags=set(args.tags)) + timestamp = start_time or create_timestamp() write_status = partial(write_status, timestamp=create_timestamp()) if args.action not in _FINAL_ACTIONS: write_status = partial(write_status, test_status=args.action) @@ -192,7 +215,11 @@ def generate_stream_results(args, output_writer): if is_last_packet: if args.action in _FINAL_ACTIONS: - write_status = partial(write_status, test_status=args.action) + if stop_time: + write_status = partial(write_status, test_status=args.action, + timestamp=stop_time) + else: + write_status = partial(write_status, test_status=args.action) write_status() diff --git a/python/subunit/tests/test_output_filter.py b/python/subunit/tests/test_output_filter.py index 0f61ac5..8444c75 100644 --- a/python/subunit/tests/test_output_filter.py +++ b/python/subunit/tests/test_output_filter.py @@ -472,6 +472,69 @@ class StatusStreamResultTests(TestCase): ]) ) +class TimeStampTests(TestCase): + scenarios = [ + (s, dict(status=s, option='--' + s)) for s in _FINAL_ACTIONS + ] + + _dummy_timestamp = datetime.datetime(1914, 6, 28, 10, 45, 2, 0, UTC) + + def setUp(self): + super(StatusStreamResultTests, self).setUp() + self.patch(_o, 'create_timestamp', lambda: self._dummy_timestamp) + self.test_id = self.getUniqueString() + + def test_no_timestamps(self): + result = get_result_for([self.option, self.test_id, f.name]) + self.assertThat( + result._events, + MatchesListwise([ + MatchesStatusCall(call='startTestRun'), + MatchesStatusCall(test_id=self.test_id, timestamp=self._dummy_timestamp), + MatchesStatusCall(test_id=self.test_id, timestamp=None), + MatchesStatusCall(call='stopTestRun'), + ])) + + def test_only_start_timestamp(self): + timestamp = datetime.datetime.utcnow() + result = get_result_for([self.option, self.test_id, f.name, + '--start-time', timestamp.isoformat()]) + self.assertThat( + result._events, + MatchesListwise([ + MatchesStatusCall(call='startTestRun'), + MatchesStatusCall(test_id=self.test_id, timestamp=timestamp), + MatchesStatusCall(test_id=self.test_id, timestamp=None), + MatchesStatusCall(call='stopTestRun'), + ])) + + def test_only_stop_timestamp(self): + timestamp = datetime.datetime.utcnow() + result = get_result_for([self.option, self.test_id, f.name, + '--stop-time', timestamp.isoformat()]) + self.assertThat( + result._events, + MatchesListwise([ + MatchesStatusCall(call='startTestRun'), + MatchesStatusCall(test_id=self.test_id, timestamp=self._dummy_timestamp), + MatchesStatusCall(test_id=self.test_id, timestamp=timestamp), + MatchesStatusCall(call='stopTestRun'), + ])) + + def test_start_and_stop_timestamp(self): + timestamp_start = datetime.datetime.utcnow() + timestamp_stop = timestamp_start + datetime.timedelta(minutes=5) + result = get_result_for([self.option, self.test_id, f.name, + '--start-time', timestamp_start.isoformat(), + '--stop-time', timestamp_stop.isoformat()]) + self.assertThat( + result._events, + MatchesListwise([ + MatchesStatusCall(call='startTestRun'), + MatchesStatusCall(test_id=self.test_id, timestamp=timestamp_start), + MatchesStatusCall(test_id=self.test_id, timestamp=timestamp_stop), + MatchesStatusCall(call='stopTestRun'), + ])) class FileDataTests(TestCase): -- cgit v1.2.1 From 71a0f0766215cadf60feb1687c1fdd5fa7e23015 Mon Sep 17 00:00:00 2001 From: Matthew Treinish Date: Sat, 14 Mar 2020 09:36:22 -0400 Subject: Fix timestamp test copy paste error --- python/subunit/tests/test_output_filter.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'python/subunit') diff --git a/python/subunit/tests/test_output_filter.py b/python/subunit/tests/test_output_filter.py index 8444c75..587fd06 100644 --- a/python/subunit/tests/test_output_filter.py +++ b/python/subunit/tests/test_output_filter.py @@ -480,7 +480,7 @@ class TimeStampTests(TestCase): _dummy_timestamp = datetime.datetime(1914, 6, 28, 10, 45, 2, 0, UTC) def setUp(self): - super(StatusStreamResultTests, self).setUp() + super(TimeStampTests, self).setUp() self.patch(_o, 'create_timestamp', lambda: self._dummy_timestamp) self.test_id = self.getUniqueString() -- cgit v1.2.1 From 0e9f67b9683bf2c8c82edb4e511d9b2c7708d900 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jelmer=20Vernoo=C4=B3?= Date: Sat, 14 Mar 2020 14:59:45 +0000 Subject: Release 1.4.0. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Jelmer Vernooij --- python/subunit/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'python/subunit') diff --git a/python/subunit/__init__.py b/python/subunit/__init__.py index 81b773c..17a970a 100644 --- a/python/subunit/__init__.py +++ b/python/subunit/__init__.py @@ -153,7 +153,7 @@ from subunit.v2 import ByteStreamToStreamResult, StreamResultToBytes # If the releaselevel is 'final', then the tarball will be major.minor.micro. # Otherwise it is major.minor.micro~$(revno). -__version__ = (1, 3, 0, 'final', 0) +__version__ = (1, 4, 0, 'final', 0) PROGRESS_SET = 0 PROGRESS_CUR = 1 -- 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/subunit') 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/subunit') 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 From cb7c754b75a1803507cfcc871fa33a5bbbbecf1d Mon Sep 17 00:00:00 2001 From: Thomas Grainger Date: Thu, 4 Mar 2021 10:26:45 +0000 Subject: add missing reference --- python/subunit/tests/test_subunit_tags.py | 2 ++ 1 file changed, 2 insertions(+) (limited to 'python/subunit') diff --git a/python/subunit/tests/test_subunit_tags.py b/python/subunit/tests/test_subunit_tags.py index a16edc1..3722eb2 100644 --- a/python/subunit/tests/test_subunit_tags.py +++ b/python/subunit/tests/test_subunit_tags.py @@ -56,6 +56,8 @@ class TestSubUnitTags(testtools.TestCase): b'\x83\x1b\x04test\x03\x03bar\x03foo\x04quux\xd2\x18\x1bC', b'\xb3)\x82\x17\x04test\x02\x03foo\x04quux\xa6\xe1\xde\xec\xb3)' b'\x83\x1b\x04test\x03\x03foo\x03bar\x04quux:\x05e\x80', + b'\xb3)\x82\x17\x04test\x02\x03foo\x04quux\xa6\xe1\xde\xec\xb3)' + b'\x83\x1b\x04test\x03\x04quux\x03foo\x03bar\xaf\xbd\x9d\xd6', ] stream = subunit.StreamResultToBytes(self.original) stream.status( -- cgit v1.2.1