don't rely on current_tags, implement it ourselves.
authorJonathan Lange <jml@mumak.net>
Thu, 19 Apr 2012 18:13:36 +0000 (19:13 +0100)
committerJonathan Lange <jml@mumak.net>
Thu, 19 Apr 2012 18:13:36 +0000 (19:13 +0100)
python/subunit/test_results.py
python/subunit/tests/test_subunit_filter.py
python/subunit/tests/test_test_results.py

index ce8f67abb39e56ef64d56d87c330833f6319a146..b6e9be8a42b24145cf5c2fb50e6913a3bc362e35 100644 (file)
@@ -84,10 +84,6 @@ class TestResultDecorator(object):
     def wasSuccessful(self):
         return self.decorated.wasSuccessful()
 
-    @property
-    def current_tags(self):
-        return self.decorated.current_tags
-
     @property
     def shouldStop(self):
         return self.decorated.shouldStop
@@ -315,6 +311,7 @@ class _PredicateFilter(TestResultDecorator):
         self.decorated = TimeCollapsingDecorator(
             TagCollapsingDecorator(self.decorated))
         self._predicate = predicate
+        self._current_tags = set()
         # The current test (for filtering tags)
         self._current_test = None
         # Has the current test been filtered (for outputting test tags)
@@ -326,7 +323,7 @@ class _PredicateFilter(TestResultDecorator):
         # XXX: ExtendedToOriginalDecorator doesn't properly wrap current_tags.
         # https://bugs.launchpad.net/testtools/+bug/978027
         return self._predicate(
-            test, outcome, error, details, self.current_tags)
+            test, outcome, error, details, self._current_tags)
 
     def addError(self, test, err=None, details=None):
         if (self.filter_predicate(test, 'error', err, details)):
@@ -387,7 +384,6 @@ class _PredicateFilter(TestResultDecorator):
         correctly.
         """
         if not self._current_test_filtered:
-            # Tags to output for this test.
             for method, args, kwargs in self._buffered_calls:
                 getattr(self.decorated, method)(*args, **kwargs)
             self.decorated.stopTest(test)
@@ -395,6 +391,15 @@ class _PredicateFilter(TestResultDecorator):
         self._current_test_filtered = None
         self._buffered_calls = []
 
+    def tags(self, new_tags, gone_tags):
+        new_tags, gone_tags = set(new_tags), set(gone_tags)
+        self._current_tags.update(new_tags)
+        self._current_tags.difference_update(gone_tags)
+        if self._current_test is not None:
+            self._buffered_calls.append(('tags', [new_tags, gone_tags], {}))
+        else:
+            return super(_PredicateFilter, self).tags(new_tags, gone_tags)
+
     def time(self, a_time):
         if self._current_test is not None:
             self._buffered_calls.append(('time', [a_time], {}))
index d5f204ad106e5585483d474c7a7289acef4e7116..35d4603563f8126a9e346a8206249f896ac065bd 100644 (file)
@@ -92,7 +92,6 @@ xfail todo
              ('startTest', test),
              ('addSuccess', test),
              ('stopTest', test),
-             ('tags', set(['local']), set()),
              ],
             result._events)
 
@@ -298,9 +297,12 @@ xfail todo
         events = self.to_events(output)
         foo = subunit.RemotedTestCase('foo')
         self.assertEqual(
-            [('startTest', foo),
+            [('tags', set(['a']), set()),
+             ('startTest', foo),
              ('addSuccess', foo),
-             ('stopTest', foo)],
+             ('stopTest', foo),
+             ('tags', set(), set(['a'])),
+             ],
             events)
 
 
index 2bec7e38fd3a188af73d1ef64df7e8513bab36ec..6beb57aa650f6544189651ed6b9ca0b1c25e244a 100644 (file)
@@ -56,16 +56,6 @@ class AssertBeforeTestResult(LoggingDecorator):
         super(AssertBeforeTestResult, self)._before_event()
 
 
-class TestTestResultDecorator(unittest.TestCase):
-
-    def test_current_tags(self):
-        result = ExtendedTestResult()
-        decorator = subunit.test_results.TestResultDecorator(result)
-        decorator.tags(set('foo'), set())
-        self.assertEqual(set('foo'), decorator.current_tags)
-        self.assertEqual(decorator.current_tags, result.current_tags)
-
-
 class TimeCapturingResult(unittest.TestResult):
 
     def __init__(self):