From 7ae3b8ff3d861923877a273cf6818eaf86f220e5 Mon Sep 17 00:00:00 2001 From: Jonathan Lange Date: Fri, 20 Apr 2012 11:00:14 +0100 Subject: Make sure tags directives are sent before addSuccess etc. --- python/subunit/test_results.py | 15 +++++++------ python/subunit/tests/test_test_results.py | 35 +++++++++++++++++++++++++++++++ 2 files changed, 42 insertions(+), 8 deletions(-) (limited to 'python') diff --git a/python/subunit/test_results.py b/python/subunit/test_results.py index fb7affd..b5ac0f1 100644 --- a/python/subunit/test_results.py +++ b/python/subunit/test_results.py @@ -205,7 +205,7 @@ 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): @@ -223,16 +223,15 @@ class TagCollapsingDecorator(TestResultDecorator): self._current_test_tags = set(), set() def stopTest(self, test): - """Stop a test. + super(TagCollapsingDecorator, self).stopTest(test) + self._current_test_tags = None - Not directly passed to the client, but used for handling of tags - correctly. - """ - # Tags to output for this test. + def _before_event(self): + if not self._current_test_tags: + return if self._current_test_tags[0] or self._current_test_tags[1]: self.decorated.tags(*self._current_test_tags) - self.decorated.stopTest(test) - self._current_test_tags = None + self._current_test_tags = set(), set() def tags(self, new_tags, gone_tags): """Handle tag instructions. diff --git a/python/subunit/tests/test_test_results.py b/python/subunit/tests/test_test_results.py index 6beb57a..750958e 100644 --- a/python/subunit/tests/test_test_results.py +++ b/python/subunit/tests/test_test_results.py @@ -208,6 +208,22 @@ class TestTagCollapsingDecorator(TestCase): self.assertEquals( [('tags', set(['a', 'b']), set([]))], result._events) + def test_tags_forwarded_after_tests(self): + test = subunit.RemotedTestCase('foo') + result = ExtendedTestResult() + tag_collapser = subunit.test_results.TagCollapsingDecorator(result) + tag_collapser.startTest(test) + tag_collapser.addSuccess(test) + tag_collapser.stopTest(test) + tag_collapser.tags(set(['a']), set(['b'])) + self.assertEqual( + [('startTest', test), + ('addSuccess', test), + ('stopTest', test), + ('tags', set(['a']), set(['b'])), + ], + result._events) + def test_tags_collapsed_inside_of_tests(self): result = ExtendedTestResult() tag_collapser = subunit.test_results.TagCollapsingDecorator(result) @@ -238,6 +254,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): -- cgit v1.2.1 From 89eb5aede70157e89c93df2e6bf988ecb6fcba02 Mon Sep 17 00:00:00 2001 From: Jonathan Lange Date: Fri, 20 Apr 2012 11:11:43 +0100 Subject: Collapse tags outside of tests too. --- python/subunit/test_results.py | 39 +++++++++++++++++++------------ python/subunit/tests/test_test_results.py | 16 +++++++++---- 2 files changed, 36 insertions(+), 19 deletions(-) (limited to 'python') diff --git a/python/subunit/test_results.py b/python/subunit/test_results.py index b5ac0f1..4a55cf8 100644 --- a/python/subunit/test_results.py +++ b/python/subunit/test_results.py @@ -210,16 +210,28 @@ class TagCollapsingDecorator(HookedTestResultDecorator): 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): @@ -227,11 +239,11 @@ class TagCollapsingDecorator(HookedTestResultDecorator): self._current_test_tags = None def _before_event(self): - if not self._current_test_tags: - return - if self._current_test_tags[0] or self._current_test_tags[1]: - self.decorated.tags(*self._current_test_tags) - self._current_test_tags = set(), set() + 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() def tags(self, new_tags, gone_tags): """Handle tag instructions. @@ -242,14 +254,11 @@ class TagCollapsingDecorator(HookedTestResultDecorator): :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 750958e..09b4c2f 100644 --- a/python/subunit/tests/test_test_results.py +++ b/python/subunit/tests/test_test_results.py @@ -201,26 +201,34 @@ 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([]))], result._events) + [('tags', set(['a', 'b']), set([])), + ('startTest', self), + ], 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( - [('startTest', test), + [('startTestRun',), + ('startTest', test), ('addSuccess', test), ('stopTest', test), ('tags', set(['a']), set(['b'])), + ('stopTestRun',), ], result._events) -- cgit v1.2.1