From 7fd32930b2d9bff0c4f8f823a313c03beedce451 Mon Sep 17 00:00:00 2001 From: Jonathan Lange Date: Sun, 13 Feb 2011 14:39:43 +0000 Subject: Add a time collapsing decorator. --- python/subunit/test_results.py | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) (limited to 'python/subunit/test_results.py') diff --git a/python/subunit/test_results.py b/python/subunit/test_results.py index 12849f5..b3228c6 100644 --- a/python/subunit/test_results.py +++ b/python/subunit/test_results.py @@ -247,6 +247,25 @@ class TagCollapsingDecorator(TestResultDecorator): return self.decorated.tags(new_tags, gone_tags) +class TimeCollapsingDecorator(HookedTestResultDecorator): + """Only pass on the first and last of a consecutive sequence of times.""" + + def __init__(self, decorated): + HookedTestResultDecorator.__init__(self, decorated) + self._last_time = None + + def _before_event(self): + self.decorated.time(self._last_time) + self._last_time = None + + def time(self, a_time): + # Don't upcall, because we don't want to call _before_event, it's only + # for non-time events. + if self._last_time is None: + self.decorated.time(a_time) + self._last_time = a_time + + def all_true(bools): """Return True if all of 'bools' are True. False otherwise.""" for b in bools: -- cgit v1.2.1