summaryrefslogtreecommitdiff
path: root/python
diff options
context:
space:
mode:
authorJonathan Lange <jml@mumak.net>2012-04-13 00:12:32 +0100
committerJonathan Lange <jml@mumak.net>2012-04-13 00:12:32 +0100
commit994467ea854c08498baac63f01a653a240514526 (patch)
treeaee41464272a06c2e7973225186e91606be9f95f /python
parent8141fda3abe0ba97903dca15a40f37dfa4eebcb7 (diff)
downloadsubunit-git-994467ea854c08498baac63f01a653a240514526.tar.gz
Progress, of a sort.
Diffstat (limited to 'python')
-rw-r--r--python/subunit/test_results.py22
-rw-r--r--python/subunit/tests/test_subunit_filter.py35
2 files changed, 53 insertions, 4 deletions
diff --git a/python/subunit/test_results.py b/python/subunit/test_results.py
index 3e597ef..deaea1b 100644
--- a/python/subunit/test_results.py
+++ b/python/subunit/test_results.py
@@ -289,6 +289,22 @@ def and_predicates(predicates):
return lambda *args, **kwargs: all(p(*args, **kwargs) for p in predicates)
+def _make_tag_filter(with_tags, without_tags):
+ """Make a callback that checks tests against tags."""
+
+ with_tags = with_tags and set(with_tags) or None
+ without_tags = without_tags and set(without_tags) or None
+
+ def check_tags(test, outcome, err, details, tags):
+ if with_tags and not with_tags <= tags:
+ return False
+ if without_tags and bool(without_tags & tags):
+ return False
+ return True
+
+ return check_tags
+
+
class _PredicateFilter(TestResultDecorator):
def __init__(self, result, predicate):
@@ -306,8 +322,8 @@ class _PredicateFilter(TestResultDecorator):
def filter_predicate(self, test, outcome, error, details):
# XXX: ExtendedToOriginalDecorator doesn't properly wrap current_tags.
# https://bugs.launchpad.net/testtools/+bug/978027
- tags = getattr(self.decorated, 'current_tags', frozenset())
- return self._predicate(test, outcome, error, details, tags)
+ return self._predicate(
+ test, outcome, error, details, self.current_tags)
def addError(self, test, err=None, details=None):
if (self.filter_predicate(test, 'error', err, details)):
@@ -538,7 +554,7 @@ class TestIdPrintingResult(testtools.TestResult):
class TestByTestResult(testtools.TestResult):
"""Call something every time a test completes."""
- # XXX: Arguably belongs in testtools.
+# XXX: Arguably belongs in testtools.
def __init__(self, on_test):
"""Construct a ``TestByTestResult``.
diff --git a/python/subunit/tests/test_subunit_filter.py b/python/subunit/tests/test_subunit_filter.py
index 1cae791..d5f204a 100644
--- a/python/subunit/tests/test_subunit_filter.py
+++ b/python/subunit/tests/test_subunit_filter.py
@@ -28,7 +28,7 @@ from testtools.compat import _b, BytesIO
from testtools.testresult.doubles import ExtendedTestResult
import subunit
-from subunit.test_results import TestResultFilter
+from subunit.test_results import _make_tag_filter, TestResultFilter
class TestTestResultFilter(TestCase):
@@ -80,6 +80,22 @@ xfail todo
filtered_result.failures])
self.assertEqual(4, filtered_result.testsRun)
+ def test_tag_filter(self):
+ tag_filter = _make_tag_filter(['global'], ['local'])
+ result = ExtendedTestResult()
+ result_filter = TestResultFilter(
+ result, filter_success=False, filter_predicate=tag_filter)
+ self.run_tests(result_filter)
+ test = subunit.RemotedTestCase('passed')
+ self.assertEquals(
+ [('tags', set(['global']), set()),
+ ('startTest', test),
+ ('addSuccess', test),
+ ('stopTest', test),
+ ('tags', set(['local']), set()),
+ ],
+ result._events)
+
def test_exclude_errors(self):
filtered_result = unittest.TestResult()
result_filter = TestResultFilter(filtered_result, filter_error=True)
@@ -270,6 +286,23 @@ xfail todo
('stopTest', foo)],
events)
+ def test_tags(self):
+ output = self.run_command(['-s', '--with-tag', 'a'], (
+ "tags: a\n"
+ "test: foo\n"
+ "success: foo\n"
+ "tags: -a\n"
+ "test: bar\n"
+ "success: bar\n"
+ ))
+ events = self.to_events(output)
+ foo = subunit.RemotedTestCase('foo')
+ self.assertEqual(
+ [('startTest', foo),
+ ('addSuccess', foo),
+ ('stopTest', foo)],
+ events)
+
def test_suite():
loader = subunit.tests.TestUtil.TestLoader()