Use the 'append' action, instead of specifying tags as a comma-separated list of values.
This commit is contained in:
parent
a0530ff5fc
commit
27fd8d82b0
|
@ -115,11 +115,10 @@ def parse_arguments(args=None, ParserClass=OptionParser):
|
||||||
parser.add_option_group(file_commands)
|
parser.add_option_group(file_commands)
|
||||||
|
|
||||||
parser.add_option(
|
parser.add_option(
|
||||||
"--tags",
|
"--tag",
|
||||||
help="A comma-separated list of tags to associate with a test. This "
|
help="Specifies a tag. May be used multiple times",
|
||||||
"option may only be used with a status command.",
|
action="append",
|
||||||
action="callback",
|
dest="tags",
|
||||||
callback=set_tags_cb,
|
|
||||||
default=[]
|
default=[]
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -139,7 +138,7 @@ def parse_arguments(args=None, ParserClass=OptionParser):
|
||||||
except IOError as e:
|
except IOError as e:
|
||||||
parser.error("Cannot open %s (%s)" % (options.attach_file, e.strerror))
|
parser.error("Cannot open %s (%s)" % (options.attach_file, e.strerror))
|
||||||
if options.tags and not options.action:
|
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):
|
if not (options.attach_file or options.action):
|
||||||
parser.error("Must specify either --attach-file or a status command")
|
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)
|
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):
|
def generate_stream_results(args, output_writer):
|
||||||
output_writer.startTestRun()
|
output_writer.startTestRun()
|
||||||
|
|
||||||
|
@ -202,7 +195,6 @@ def generate_stream_results(args, output_writer):
|
||||||
write_status = partial(write_status, test_id=args.test_id)
|
write_status = partial(write_status, test_id=args.test_id)
|
||||||
|
|
||||||
if is_last_packet:
|
if is_last_packet:
|
||||||
write_status = partial(write_status, eof=True)
|
|
||||||
if args.action in _FINAL_ACTIONS:
|
if args.action in _FINAL_ACTIONS:
|
||||||
write_status = partial(write_status, test_status=args.action)
|
write_status = partial(write_status, test_status=args.action)
|
||||||
|
|
||||||
|
|
|
@ -103,7 +103,7 @@ class TestStatusArgParserTests(WithScenarios, TestCaseWithPatchedStderr):
|
||||||
|
|
||||||
def test_all_commands_accept_tags_argument(self):
|
def test_all_commands_accept_tags_argument(self):
|
||||||
args = safe_parse_arguments(
|
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"]))
|
self.assertThat(args.tags, Equals(["foo", "bar", "baz"]))
|
||||||
|
|
||||||
|
@ -180,18 +180,18 @@ class ArgParserTests(TestCaseWithPatchedStderr):
|
||||||
)
|
)
|
||||||
|
|
||||||
def test_cannot_specify_tags_without_status_command(self):
|
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(
|
self.assertThat(
|
||||||
fn,
|
fn,
|
||||||
raises(RuntimeError('subunit-output: error: Cannot specify '
|
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):
|
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(
|
self.assertThat(
|
||||||
fn,
|
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):
|
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(
|
self.assertThat(
|
||||||
result._events[0],
|
result._events[0],
|
||||||
MatchesStatusCall(test_tags=set(['hello', 'world']))
|
MatchesStatusCall(test_tags=set(['hello', 'world']))
|
||||||
|
@ -387,8 +387,10 @@ class StatusStreamResultTests(WithScenarios, TestCase):
|
||||||
self.test_id,
|
self.test_id,
|
||||||
'--attach-file',
|
'--attach-file',
|
||||||
f.name,
|
f.name,
|
||||||
'--tags',
|
'--tag',
|
||||||
'foo,bar',
|
'foo',
|
||||||
|
'--tag',
|
||||||
|
'bar',
|
||||||
])
|
])
|
||||||
|
|
||||||
self.assertThat(
|
self.assertThat(
|
||||||
|
|
Loading…
Reference in New Issue