summaryrefslogtreecommitdiff
path: root/python
diff options
context:
space:
mode:
authorJonathan Lange <jml@mumak.net>2012-04-10 14:39:10 +0100
committerJonathan Lange <jml@mumak.net>2012-04-10 14:39:10 +0100
commit3cbc2211d91877f2c24c9bed2f50c5a68cfa9deb (patch)
tree89e436e0dbb6fe7061b9b7414a62b41224fbbdb1 /python
parent8ff7d39c1e1e247d860053026d6fd0867379adb0 (diff)
downloadsubunit-git-3cbc2211d91877f2c24c9bed2f50c5a68cfa9deb.tar.gz
Make sure all of our predicates support tags.
Diffstat (limited to 'python')
-rw-r--r--python/subunit/test_results.py35
-rw-r--r--python/subunit/tests/test_subunit_filter.py14
2 files changed, 36 insertions, 13 deletions
diff --git a/python/subunit/test_results.py b/python/subunit/test_results.py
index 0c6fbd5..25c5c77 100644
--- a/python/subunit/test_results.py
+++ b/python/subunit/test_results.py
@@ -308,11 +308,7 @@ class _PredicateFilter(TestResultDecorator):
# XXX: ExtendedToOriginalDecorator doesn't properly wrap current_tags.
# https://bugs.launchpad.net/testtools/+bug/978027
tags = getattr(self.decorated, 'current_tags', frozenset())
- # 0.0.7 and earlier did not support the 'tags' parameter.
- try:
- return self._predicate(test, outcome, error, details, tags)
- except TypeError:
- return self._predicate(test, outcome, error, details)
+ return self._predicate(test, outcome, error, details, tags)
def addError(self, test, err=None, details=None):
if (self.filter_predicate(test, 'error', err, details)):
@@ -425,20 +421,33 @@ class TestResultFilter(_PredicateFilter):
"""
predicates = []
if filter_error:
- predicates.append(lambda t, outcome, e, d: outcome != 'error')
+ predicates.append(
+ lambda t, outcome, e, d, tags: outcome != 'error')
if filter_failure:
- predicates.append(lambda t, outcome, e, d: outcome != 'failure')
+ predicates.append(
+ lambda t, outcome, e, d, tags: outcome != 'failure')
if filter_success:
- predicates.append(lambda t, outcome, e, d: outcome != 'success')
+ predicates.append(
+ lambda t, outcome, e, d, tags: outcome != 'success')
if filter_skip:
- predicates.append(lambda t, outcome, e, d: outcome != 'skip')
+ predicates.append(
+ lambda t, outcome, e, d, tags: outcome != 'skip')
if filter_xfail:
- predicates.append(lambda t, outcome, e, d: outcome != 'expectedfailure')
+ predicates.append(
+ lambda t, outcome, e, d, tags: outcome != 'expectedfailure')
if filter_predicate is not None:
- predicates.append(filter_predicate)
+ def compat(test, outcome, error, details, tags):
+ # 0.0.7 and earlier did not support the 'tags' parameter.
+ try:
+ return filter_predicate(
+ test, outcome, error, details, tags)
+ except TypeError:
+ return filter_predicate(test, outcome, error, details)
+ predicates.append(compat)
predicate = (
- lambda test, outcome, err, details:
- all_true(p(test, outcome, err, details) for p in predicates))
+ lambda test, outcome, err, details, tags:
+ all_true(p(test, outcome, err, details, tags)
+ for p in predicates))
super(TestResultFilter, self).__init__(result, predicate)
if fixup_expected_failures is None:
self._fixup_expected_failures = frozenset()
diff --git a/python/subunit/tests/test_subunit_filter.py b/python/subunit/tests/test_subunit_filter.py
index 83b9240..5bbf581 100644
--- a/python/subunit/tests/test_subunit_filter.py
+++ b/python/subunit/tests/test_subunit_filter.py
@@ -151,6 +151,8 @@ xfail todo
def test_filter_predicate(self):
"""You can filter by predicate callbacks"""
+ # 0.0.7 and earlier did not support the 'tags' parameter, so we need
+ # to test that we still support behaviour without it.
filtered_result = unittest.TestResult()
def filter_cb(test, outcome, err, details):
return outcome == 'success'
@@ -161,6 +163,18 @@ xfail todo
# Only success should pass
self.assertEqual(1, filtered_result.testsRun)
+ def test_filter_predicate_with_tags(self):
+ """You can filter by predicate callbacks that accept tags"""
+ filtered_result = unittest.TestResult()
+ def filter_cb(test, outcome, err, details, tags):
+ return outcome == 'success'
+ result_filter = TestResultFilter(filtered_result,
+ filter_predicate=filter_cb,
+ filter_success=False)
+ self.run_tests(result_filter)
+ # Only success should pass
+ self.assertEqual(1, filtered_result.testsRun)
+
def test_time_ordering_preserved(self):
# Passing a subunit stream through TestResultFilter preserves the
# relative ordering of 'time' directives and any other subunit