summaryrefslogtreecommitdiff
path: root/python
diff options
context:
space:
mode:
authorJonathan Lange <jml@mumak.net>2012-04-26 11:48:35 +0100
committerJonathan Lange <jml@mumak.net>2012-04-26 11:48:35 +0100
commit88fb8f5bb9d1eaa3807d597661e4215b4727b894 (patch)
tree1c6988c89d20124be641089d4b1f6e4078dbddf1 /python
parenteff5dc6d9da686ebbb2de9444c5bdc46e5a0539f (diff)
parenta61e333822723ca40c9e7423228bd1f240eddd91 (diff)
downloadsubunit-git-88fb8f5bb9d1eaa3807d597661e4215b4727b894.tar.gz
Merge tag-collapsing-rigor.
Diffstat (limited to 'python')
-rw-r--r--python/subunit/test_results.py50
-rw-r--r--python/subunit/tests/test_test_results.py68
2 files changed, 95 insertions, 23 deletions
diff --git a/python/subunit/test_results.py b/python/subunit/test_results.py
index fb7affd..8db40e1 100644
--- a/python/subunit/test_results.py
+++ b/python/subunit/test_results.py
@@ -205,35 +205,48 @@ class AutoTimingTestResultDecorator(HookedTestResultDecorator):
return self.decorated.time(a_datetime)
-class TagCollapsingDecorator(TestResultDecorator):
+class TagCollapsingDecorator(HookedTestResultDecorator):
"""Collapses many 'tags' calls into one where possible."""
def __init__(self, result):
super(TagCollapsingDecorator, self).__init__(result)
- # The (new, gone) tags for the current test.
+ self._clear_tags()
+
+ def _clear_tags(self):
+ self._global_tags = set(), set()
self._current_test_tags = None
+ def _get_current_tags(self):
+ if self._current_test_tags:
+ return self._current_test_tags
+ return self._global_tags
+
+ def startTestRun(self):
+ super(TagCollapsingDecorator, self).startTestRun()
+ self._clear_tags()
+
def startTest(self, test):
"""Start a test.
Not directly passed to the client, but used for handling of tags
correctly.
"""
- self.decorated.startTest(test)
+ super(TagCollapsingDecorator, self).startTest(test)
self._current_test_tags = set(), set()
def stopTest(self, test):
- """Stop a test.
-
- Not directly passed to the client, but used for handling of tags
- correctly.
- """
- # Tags to output for this test.
- if self._current_test_tags[0] or self._current_test_tags[1]:
- self.decorated.tags(*self._current_test_tags)
- self.decorated.stopTest(test)
+ super(TagCollapsingDecorator, self).stopTest(test)
self._current_test_tags = None
+ def _before_event(self):
+ new_tags, gone_tags = self._get_current_tags()
+ if new_tags or gone_tags:
+ self.decorated.tags(new_tags, gone_tags)
+ if self._current_test_tags:
+ self._current_test_tags = set(), set()
+ else:
+ self._global_tags = set(), set()
+
def tags(self, new_tags, gone_tags):
"""Handle tag instructions.
@@ -243,14 +256,11 @@ class TagCollapsingDecorator(TestResultDecorator):
:param new_tags: Tags to add,
:param gone_tags: Tags to remove.
"""
- if self._current_test_tags is not None:
- # gather the tags until the test stops.
- self._current_test_tags[0].update(new_tags)
- self._current_test_tags[0].difference_update(gone_tags)
- self._current_test_tags[1].update(gone_tags)
- self._current_test_tags[1].difference_update(new_tags)
- else:
- return self.decorated.tags(new_tags, gone_tags)
+ current_new_tags, current_gone_tags = self._get_current_tags()
+ current_new_tags.update(new_tags)
+ current_new_tags.difference_update(gone_tags)
+ current_gone_tags.update(gone_tags)
+ current_gone_tags.difference_update(new_tags)
class TimeCollapsingDecorator(HookedTestResultDecorator):
diff --git a/python/subunit/tests/test_test_results.py b/python/subunit/tests/test_test_results.py
index 6beb57a..3c4f686 100644
--- a/python/subunit/tests/test_test_results.py
+++ b/python/subunit/tests/test_test_results.py
@@ -201,12 +201,55 @@ class TestAutoTimingTestResultDecorator(unittest.TestCase):
class TestTagCollapsingDecorator(TestCase):
- def test_tags_forwarded_outside_of_tests(self):
+ def test_tags_collapsed_outside_of_tests(self):
result = ExtendedTestResult()
tag_collapser = subunit.test_results.TagCollapsingDecorator(result)
- tag_collapser.tags(set(['a', 'b']), set())
+ tag_collapser.tags(set(['a']), set())
+ tag_collapser.tags(set(['b']), set())
+ tag_collapser.startTest(self)
+ self.assertEquals(
+ [('tags', set(['a', 'b']), set([])),
+ ('startTest', self),
+ ], result._events)
+
+ def test_tags_collapsed_outside_of_tests_are_flushed(self):
+ result = ExtendedTestResult()
+ tag_collapser = subunit.test_results.TagCollapsingDecorator(result)
+ tag_collapser.startTestRun()
+ tag_collapser.tags(set(['a']), set())
+ tag_collapser.tags(set(['b']), set())
+ tag_collapser.startTest(self)
+ tag_collapser.addSuccess(self)
+ tag_collapser.stopTest(self)
+ tag_collapser.stopTestRun()
self.assertEquals(
- [('tags', set(['a', 'b']), set([]))], result._events)
+ [('startTestRun',),
+ ('tags', set(['a', 'b']), set([])),
+ ('startTest', self),
+ ('addSuccess', self),
+ ('stopTest', self),
+ ('stopTestRun',),
+ ], result._events)
+
+ def test_tags_forwarded_after_tests(self):
+ test = subunit.RemotedTestCase('foo')
+ result = ExtendedTestResult()
+ tag_collapser = subunit.test_results.TagCollapsingDecorator(result)
+ tag_collapser.startTestRun()
+ tag_collapser.startTest(test)
+ tag_collapser.addSuccess(test)
+ tag_collapser.stopTest(test)
+ tag_collapser.tags(set(['a']), set(['b']))
+ tag_collapser.stopTestRun()
+ self.assertEqual(
+ [('startTestRun',),
+ ('startTest', test),
+ ('addSuccess', test),
+ ('stopTest', test),
+ ('tags', set(['a']), set(['b'])),
+ ('stopTestRun',),
+ ],
+ result._events)
def test_tags_collapsed_inside_of_tests(self):
result = ExtendedTestResult()
@@ -238,6 +281,25 @@ class TestTagCollapsingDecorator(TestCase):
('stopTest', test)],
result._events)
+ def test_tags_sent_before_result(self):
+ # Because addSuccess and friends tend to send subunit output
+ # immediately, and because 'tags:' before a result line means
+ # something different to 'tags:' after a result line, we need to be
+ # sure that tags are emitted before 'addSuccess' (or whatever).
+ result = ExtendedTestResult()
+ tag_collapser = subunit.test_results.TagCollapsingDecorator(result)
+ test = subunit.RemotedTestCase('foo')
+ tag_collapser.startTest(test)
+ tag_collapser.tags(set(['a']), set())
+ tag_collapser.addSuccess(test)
+ tag_collapser.stopTest(test)
+ self.assertEquals(
+ [('startTest', test),
+ ('tags', set(['a']), set()),
+ ('addSuccess', test),
+ ('stopTest', test)],
+ result._events)
+
class TestTimeCollapsingDecorator(TestCase):