Add support for tags.
authorThomi Richards <thomi.richards@canonical.com>
Mon, 18 Nov 2013 23:34:53 +0000 (12:34 +1300)
committerThomi Richards <thomi.richards@canonical.com>
Mon, 18 Nov 2013 23:34:53 +0000 (12:34 +1300)
python/subunit/_output.py
python/subunit/tests/test_output_filter.py

index 4bd93d1..788a19f 100644 (file)
@@ -17,6 +17,7 @@ from argparse import ArgumentParser
 import datetime
 from functools import partial
 from sys import stdout
+from string import split
 
 from subunit.v2 import StreamResultToBytes
 
@@ -59,6 +60,12 @@ def parse_arguments(args=None, ParserClass=ArgumentParser):
         "not specified, the file will be sent wihtout a mime type.",
         default=None
     )
+    common_args.add_argument(
+        "--tags",
+        help="A comma-separated list of tags to associate with this test.",
+        type=partial(split, sep=','),
+        default=None
+    )
     sub_parsers = parser.add_subparsers(dest="action")
 
     final_state = "This is a final action: No more actions may be generated " \
@@ -124,7 +131,8 @@ def generate_bytestream(args, output_writer):
     output_writer.status(
         test_id=args.test_id,
         test_status=translate_command_name(args.action),
-        timestamp=create_timestamp()
+        timestamp=create_timestamp(),
+        test_tags=args.tags,
         )
     output_writer.stopTestRun()
 
index bddcc99..8b2f54b 100644 (file)
@@ -89,6 +89,13 @@ class OutputFilterArgumentParserTests(TestCase):
             )
             self.assertThat(args.mimetype, Equals("text/plain"))
 
+    def test_all_commands_accept_tags_argument(self):
+        for command in self._all_supported_commands:
+            args = safe_parse_arguments(
+                args=[command, 'foo', '--tags', "foo,bar,baz"]
+            )
+            self.assertThat(args.tags, Equals(["foo","bar","baz"]))
+
 
 class ByteStreamCompatibilityTests(TestCase):
 
@@ -196,6 +203,20 @@ class ByteStreamCompatibilityTests(TestCase):
             )
         )
 
+    def test_tags_are_generated(self):
+        result = self._get_result_for(
+            ['exists', 'foo', '--tags', 'hello,world']
+        )
+        self.assertThat(
+            result._events[0],
+            MatchesCall(
+                call='status',
+                test_id='foo',
+                test_tags=set(['hello','world']),
+                timestamp=self._dummy_timestamp,
+            )
+        )
+
 
 class FileChunkingTests(TestCase):