diff options
| author | Thomi Richards <thomi.richards@canonical.com> | 2013-11-19 08:22:46 +1300 |
|---|---|---|
| committer | Thomi Richards <thomi.richards@canonical.com> | 2013-11-19 08:22:46 +1300 |
| commit | b705438d10498be7b4aad77cd0650f7a0c4614e0 (patch) | |
| tree | 32f45aac58113bddbcb2964b4e5809b6b1cd9ea5 /python | |
| parent | c3dc5dd05d7676a32fc7027dd1cd9d73116bd6ff (diff) | |
| download | subunit-git-b705438d10498be7b4aad77cd0650f7a0c4614e0.tar.gz | |
Generate a timestamp for all messages, and refactor argument parser to use common arguments.
Diffstat (limited to 'python')
| -rw-r--r-- | python/subunit/_output.py | 46 | ||||
| -rw-r--r-- | python/subunit/tests/test_output_filter.py | 43 |
2 files changed, 74 insertions, 15 deletions
diff --git a/python/subunit/_output.py b/python/subunit/_output.py index e513639..9b467c1 100644 --- a/python/subunit/_output.py +++ b/python/subunit/_output.py @@ -14,6 +14,7 @@ # limitations under that license. from argparse import ArgumentParser +import datetime from sys import stdout from subunit.v2 import StreamResultToBytes @@ -36,19 +37,23 @@ def parse_arguments(args=None): prog='subunit-output', description="A tool to generate a subunit result byte-stream", ) + + common_args = ArgumentParser(add_help=False) + common_args.add_argument("test_id", help="""A string that uniquely + identifies this test.""") sub_parsers = parser.add_subparsers(dest="action") - parser_start = sub_parsers.add_parser("start", help="Start a test.") - parser_start.add_argument("test_id", help="The test id you want to start.") + parser_start = sub_parsers.add_parser("start", help="Start a test.", + parents=[common_args]) - parser_pass = sub_parsers.add_parser("pass", help="Pass a test.") - parser_pass.add_argument("test_id", help="The test id you want to pass.") + parser_pass = sub_parsers.add_parser("pass", help="Pass a test.", + parents=[common_args]) - parser_fail = sub_parsers.add_parser("fail", help="Fail a test.") - parser_fail.add_argument("test_id", help="The test id you want to fail.") + parser_fail = sub_parsers.add_parser("fail", help="Fail a test.", + parents=[common_args]) - parser_skip = sub_parsers.add_parser("skip", help="Skip a test.") - parser_skip.add_argument("test_id", help="The test id you want to skip.") + parser_skip = sub_parsers.add_parser("skip", help="Skip a test.", + parents=[common_args]) return parser.parse_args(args) @@ -69,7 +74,30 @@ def get_output_stream_writer(): def generate_bytestream(args, output_writer): + output_writer.startTestRun() output_writer.status( test_id=args.test_id, - test_status=translate_command_name(args.action) + test_status=translate_command_name(args.action), + timestamp=create_timestamp() ) + output_writer.stopTestRun() + + +_ZERO = datetime.timedelta(0) + + +class UTC(datetime.tzinfo): + """UTC""" + def utcoffset(self, dt): + return _ZERO + def tzname(self, dt): + return "UTC" + def dst(self, dt): + return _ZERO + + +utc = UTC() + + +def create_timestamp(): + return datetime.datetime.now(utc) diff --git a/python/subunit/tests/test_output_filter.py b/python/subunit/tests/test_output_filter.py index 03f4f26..05b6267 100644 --- a/python/subunit/tests/test_output_filter.py +++ b/python/subunit/tests/test_output_filter.py @@ -22,6 +22,7 @@ from testtools import TestCase from testtools.matchers import ( Equals, Matcher, + Mismatch, MatchesListwise, ) from testtools.testresult.doubles import StreamResult @@ -84,24 +85,54 @@ class ByteStreamCompatibilityTests(TestCase): case = ByteStreamToStreamResult(source=stream) result = StreamResult() - result.startTestRun() case.run(result) - result.stopTestRun() return result - def test_start(self): + def test_start_generates_inprogress(self): result = self._get_result_for( ['start', 'foo'], - ['pass', 'foo'], ) self.assertThat( result._events, MatchesListwise([ - MatchesCall(call='startTestRun'), MatchesCall(call='status', test_id='foo', test_status='inprogress'), + ]) + ) + + def test_pass_generates_success(self): + result = self._get_result_for( + ['pass', 'foo'], + ) + + self.assertThat( + result._events, + MatchesListwise([ MatchesCall(call='status', test_id='foo', test_status='success'), - MatchesCall(call='stopTestRun'), + ]) + ) + + def test_fail_generates_fail(self): + result = self._get_result_for( + ['fail', 'foo'], + ) + + self.assertThat( + result._events, + MatchesListwise([ + MatchesCall(call='status', test_id='foo', test_status='fail'), + ]) + ) + + def test_skip_generates_skip(self): + result = self._get_result_for( + ['skip', 'foo'], + ) + + self.assertThat( + result._events, + MatchesListwise([ + MatchesCall(call='status', test_id='foo', test_status='skip'), ]) ) |
