Tag support has been implemented for TestProtocolClient.
authorRobert Collins <robertc@robertcollins.net>
Wed, 11 Jan 2012 05:42:53 +0000 (18:42 +1300)
committerRobert Collins <robertc@robertcollins.net>
Wed, 11 Jan 2012 05:42:53 +0000 (18:42 +1300)
(Robert Collins, #518016)

NEWS
python/subunit/__init__.py
python/subunit/tests/test_test_protocol.py

diff --git a/NEWS b/NEWS
index 47de06a..2f36c3f 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -22,6 +22,9 @@ BUG FIXES
   '--no-xfail', '--no-passthrough, '--no-success', and gives you just the
   failure stream. (John Arbash Meinel)
 
+* Tag support has been implemented for TestProtocolClient.
+  (Robert Collins, #518016)
+
 * Test suite works with latest testtools (but not older ones - formatting
   changes only). (Robert Collins)
 
index b4c9397..b30b8fe 100644 (file)
@@ -755,6 +755,15 @@ class TestProtocolClient(testresult.TestResult):
         self._stream.write(self._progress_fmt + prefix + offset +
             self._bytes_eol)
 
+    def tags(self, new_tags, gone_tags):
+        """Inform the client about tags added/removed from the stream."""
+        if not new_tags and not gone_tags:
+            return
+        tags = set([tag.encode('utf8') for tag in new_tags])
+        tags.update([_b("-") + tag.encode('utf8') for tag in gone_tags])
+        tag_line = _b("tags: ") + _b(" ").join(tags) + _b("\n")
+        self._stream.write(tag_line)
+
     def time(self, a_datetime):
         """Inform the client of the time.
 
index 019c080..091b370 100644 (file)
@@ -1299,6 +1299,22 @@ class TestTestProtocolClient(unittest.TestCase):
                 "something\n"
                 "F\r\nserialised\nform0\r\n]\n" % self.test.id()))
 
+    def test_tags_empty(self):
+        self.protocol.tags(set(), set())
+        self.assertEqual(_b(""), self.io.getvalue())
+
+    def test_tags_add(self):
+        self.protocol.tags(set(['foo']), set())
+        self.assertEqual(_b("tags: foo\n"), self.io.getvalue())
+
+    def test_tags_both(self):
+        self.protocol.tags(set(['quux']), set(['bar']))
+        self.assertEqual(_b("tags: quux -bar\n"), self.io.getvalue())
+
+    def test_tags_gone(self):
+        self.protocol.tags(set(), set(['bar']))
+        self.assertEqual(_b("tags: -bar\n"), self.io.getvalue())
+
 
 def test_suite():
     loader = subunit.tests.TestUtil.TestLoader()