summaryrefslogtreecommitdiff
path: root/python
diff options
context:
space:
mode:
authorJonathan Lange <jml@mumak.net>2012-04-20 17:18:26 +0100
committerJonathan Lange <jml@mumak.net>2012-04-20 17:18:26 +0100
commit16cedbf9742761138fde9be482a118550a69dd1b (patch)
tree5960d7c65ef808ab0202ee9fd9ff59869602de79 /python
parent72054b561629ef3bb03faff0b28bcb9ad4c787c3 (diff)
downloadsubunit-git-16cedbf9742761138fde9be482a118550a69dd1b.tar.gz
Use the TagsMixin on the predicate so local and global tags are tracked correctly.
Diffstat (limited to 'python')
-rw-r--r--python/subunit/test_results.py12
-rw-r--r--python/subunit/tests/test_subunit_filter.py29
2 files changed, 30 insertions, 11 deletions
diff --git a/python/subunit/test_results.py b/python/subunit/test_results.py
index 7cce660..59477f9 100644
--- a/python/subunit/test_results.py
+++ b/python/subunit/test_results.py
@@ -325,14 +325,14 @@ def _make_tag_filter(with_tags, without_tags):
return check_tags
-class _PredicateFilter(TestResultDecorator):
+class _PredicateFilter(TestResultDecorator, TagsMixin):
def __init__(self, result, predicate):
super(_PredicateFilter, self).__init__(result)
+ self._clear_tags()
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)
@@ -344,7 +344,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._get_active_tags())
def addError(self, test, err=None, details=None):
if (self.filter_predicate(test, 'error', err, details)):
@@ -394,6 +394,7 @@ class _PredicateFilter(TestResultDecorator):
Not directly passed to the client, but used for handling of tags
correctly.
"""
+ TagsMixin.startTest(self, test)
self._current_test = test
self._current_test_filtered = False
self._buffered_calls.append(('startTest', [test], {}))
@@ -411,11 +412,10 @@ class _PredicateFilter(TestResultDecorator):
self._current_test = None
self._current_test_filtered = None
self._buffered_calls = []
+ TagsMixin.stopTest(self, test)
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)
+ TagsMixin.tags(self, new_tags, gone_tags)
if self._current_test is not None:
self._buffered_calls.append(('tags', [new_tags, gone_tags], {}))
else:
diff --git a/python/subunit/tests/test_subunit_filter.py b/python/subunit/tests/test_subunit_filter.py
index 7eca4cd..d6da8ce 100644
--- a/python/subunit/tests/test_subunit_filter.py
+++ b/python/subunit/tests/test_subunit_filter.py
@@ -86,12 +86,31 @@ xfail todo
result_filter = TestResultFilter(
result, filter_success=False, filter_predicate=tag_filter)
self.run_tests(result_filter)
- test = subunit.RemotedTestCase('passed')
+ tests_included = [
+ event[1] for event in result._events if event[0] == 'startTest']
+ tests_expected = map(
+ subunit.RemotedTestCase,
+ ['passed', 'error', 'skipped', 'todo'])
+ self.assertEquals(tests_expected, tests_included)
+
+ def test_tags_tracked_correctly(self):
+ tag_filter = _make_tag_filter(['a'], [])
+ result = ExtendedTestResult()
+ result_filter = TestResultFilter(
+ result, filter_success=False, filter_predicate=tag_filter)
+ input_stream = (
+ "test: foo\n"
+ "tags: a\n"
+ "successful: foo\n"
+ "test: bar\n"
+ "successful: bar\n")
+ self.run_tests(result_filter, input_stream)
+ foo = subunit.RemotedTestCase('foo')
self.assertEquals(
- [('tags', set(['global']), set()),
- ('startTest', test),
- ('addSuccess', test),
- ('stopTest', test),
+ [('startTest', foo),
+ ('tags', set(['a']), set()),
+ ('addSuccess', foo),
+ ('stopTest', foo),
],
result._events)