From 27fd8d82b07159d03c7b306808427b703615841b Mon Sep 17 00:00:00 2001 From: Thomi Richards Date: Mon, 9 Dec 2013 16:22:37 +1300 Subject: [PATCH] Use the 'append' action, instead of specifying tags as a comma-separated list of values. --- python/subunit/_output.py | 18 +++++------------- python/subunit/tests/test_output_filter.py | 18 ++++++++++-------- 2 files changed, 15 insertions(+), 21 deletions(-) diff --git a/python/subunit/_output.py b/python/subunit/_output.py index 8d6f169..51aaa8f 100644 --- a/python/subunit/_output.py +++ b/python/subunit/_output.py @@ -115,11 +115,10 @@ def parse_arguments(args=None, ParserClass=OptionParser): parser.add_option_group(file_commands) parser.add_option( - "--tags", - help="A comma-separated list of tags to associate with a test. This " - "option may only be used with a status command.", - action="callback", - callback=set_tags_cb, + "--tag", + help="Specifies a tag. May be used multiple times", + action="append", + dest="tags", default=[] ) @@ -139,7 +138,7 @@ def parse_arguments(args=None, ParserClass=OptionParser): except IOError as e: parser.error("Cannot open %s (%s)" % (options.attach_file, e.strerror)) if options.tags and not options.action: - parser.error("Cannot specify --tags without a status command") + parser.error("Cannot specify --tag without a status command") if not (options.attach_file or options.action): parser.error("Must specify either --attach-file or a status command") @@ -156,12 +155,6 @@ def set_status_cb(option, opt_str, value, parser, status_name): parser.values.test_id = parser.rargs.pop(0) -def set_tags_cb(option, opt_str, value, parser): - if not parser.rargs: - raise OptionValueError("Must specify at least one tag with --tags") - parser.values.tags = parser.rargs.pop(0).split(',') - - def generate_stream_results(args, output_writer): output_writer.startTestRun() @@ -202,7 +195,6 @@ def generate_stream_results(args, output_writer): write_status = partial(write_status, test_id=args.test_id) if is_last_packet: - write_status = partial(write_status, eof=True) if args.action in _FINAL_ACTIONS: write_status = partial(write_status, test_status=args.action) diff --git a/python/subunit/tests/test_output_filter.py b/python/subunit/tests/test_output_filter.py index 9a54a42..f01d66a 100644 --- a/python/subunit/tests/test_output_filter.py +++ b/python/subunit/tests/test_output_filter.py @@ -103,7 +103,7 @@ class TestStatusArgParserTests(WithScenarios, TestCaseWithPatchedStderr): def test_all_commands_accept_tags_argument(self): args = safe_parse_arguments( - args=[self.option, 'foo', '--tags', "foo,bar,baz"] + args=[self.option, 'foo', '--tag', "foo", "--tag", "bar", "--tag", "baz"] ) self.assertThat(args.tags, Equals(["foo", "bar", "baz"])) @@ -180,18 +180,18 @@ class ArgParserTests(TestCaseWithPatchedStderr): ) def test_cannot_specify_tags_without_status_command(self): - fn = lambda: safe_parse_arguments(['--tags', 'foo']) + fn = lambda: safe_parse_arguments(['--tag', 'foo']) self.assertThat( fn, raises(RuntimeError('subunit-output: error: Cannot specify ' - '--tags without a status command\n')) + '--tag without a status command\n')) ) def test_must_specify_tags_with_tags_options(self): - fn = lambda: safe_parse_arguments(['--fail', 'foo', '--tags']) + fn = lambda: safe_parse_arguments(['--fail', 'foo', '--tag']) self.assertThat( fn, - raises(RuntimeError('subunit-output: error: Must specify at least one tag with --tags\n')) + raises(RuntimeError('subunit-output: error: --tag option requires 1 argument\n')) ) @@ -255,7 +255,7 @@ class StatusStreamResultTests(WithScenarios, TestCase): ) def test_all_commands_generate_tags(self): - result = get_result_for([self.option, self.test_id, '--tags', 'hello,world']) + result = get_result_for([self.option, self.test_id, '--tag', 'hello', '--tag', 'world']) self.assertThat( result._events[0], MatchesStatusCall(test_tags=set(['hello', 'world'])) @@ -387,8 +387,10 @@ class StatusStreamResultTests(WithScenarios, TestCase): self.test_id, '--attach-file', f.name, - '--tags', - 'foo,bar', + '--tag', + 'foo', + '--tag', + 'bar', ]) self.assertThat( -- 2.34.1