Allow the use of the --tag argument without specifying a test id.
authorThomi Richards <thomi.richards@canonical.com>
Mon, 9 Dec 2013 04:28:26 +0000 (17:28 +1300)
committerThomi Richards <thomi.richards@canonical.com>
Mon, 9 Dec 2013 04:28:26 +0000 (17:28 +1300)
python/subunit/_output.py
python/subunit/tests/test_output_filter.py

index 51aaa8f..14d7ad5 100644 (file)
@@ -137,10 +137,6 @@ def parse_arguments(args=None, ParserClass=OptionParser):
                 options.attach_file = open(options.attach_file, 'rb')
             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 --tag without a status command")
-    if not (options.attach_file or options.action):
-        parser.error("Must specify either --attach-file or a status command")
 
     return options
 
index f01d66a..673f89d 100644 (file)
@@ -147,13 +147,8 @@ class ArgParserTests(TestCaseWithPatchedStderr):
             )
             self.assertThat(args.attach_file.name, Equals(tmp_file.name))
 
-    def test_must_specify_argument(self):
-        fn = lambda: safe_parse_arguments([])
-        self.assertThat(
-            fn,
-            raises(RuntimeError('subunit-output: error: Must specify either '
-                '--attach-file or a status command\n'))
-        )
+    def test_can_run_without_args(self):
+        args = safe_parse_arguments([])
 
     def test_cannot_specify_more_than_one_status_command(self):
         fn = lambda: safe_parse_arguments(['--fail', 'foo', '--skip', 'bar'])
@@ -179,13 +174,9 @@ class ArgParserTests(TestCaseWithPatchedStderr):
                 '--file-name without --attach-file\n'))
         )
 
-    def test_cannot_specify_tags_without_status_command(self):
-        fn = lambda: safe_parse_arguments(['--tag', 'foo'])
-        self.assertThat(
-            fn,
-            raises(RuntimeError('subunit-output: error: Cannot specify '
-                '--tag without a status command\n'))
-        )
+    def test_can_specify_tags_without_status_command(self):
+        args = safe_parse_arguments(['--tag', 'foo'])
+        self.assertEqual(['foo'], args.tags)
 
     def test_must_specify_tags_with_tags_options(self):
         fn = lambda: safe_parse_arguments(['--fail', 'foo', '--tag'])
@@ -531,6 +522,18 @@ class FileDataTests(TestCase):
                 ])
             )
 
+    def test_can_specify_tags_without_test_status(self):
+        result = get_result_for([
+            '--tag',
+            'foo',
+        ])
+
+        self.assertThat(
+            result._events,
+            MatchesListwise([
+                MatchesStatusCall(test_tags=set(['foo'])),
+            ])
+        )
 
 class MatchesStatusCall(Matcher):