summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRobert Collins <robertc@robertcollins.net>2009-07-20 18:34:39 +1000
committerRobert Collins <robertc@robertcollins.net>2009-07-20 18:34:39 +1000
commit83e2424fbb77ca1ea6cf4b3fefddd10616b4e95c (patch)
treeac1f95b949fc14e4481930fc70c196eca2fb99a6
parent0dc614b47e7ec1b191cfd27ea65d2526b8fde45e (diff)
downloadsubunit-git-83e2424fbb77ca1ea6cf4b3fefddd10616b4e95c.tar.gz
Add support for showing test durations in subunit-ls
-rw-r--r--README2
-rwxr-xr-xfilters/subunit-ls40
2 files changed, 34 insertions, 8 deletions
diff --git a/README b/README
index 3d958b5..8b37ff9 100644
--- a/README
+++ b/README
@@ -44,7 +44,7 @@ Subunit supplies the following filters:
* tap2subunit - convert perl's TestAnythingProtocol to subunit.
* subunit2pyunit - convert a subunit stream to pyunit test results.
* subunit-filter - filter out tests from a subunit stream.
- * subunit-ls - list the tests present in a subunit stream.
+ * subunit-ls - list info about tests present in a subunit stream.
* subunit-stats - generate a summary of a subunit stream.
* subunit-tags - add or remove tags from a stream.
diff --git a/filters/subunit-ls b/filters/subunit-ls
index 15f5c07..4060ffa 100755
--- a/filters/subunit-ls
+++ b/filters/subunit-ls
@@ -19,6 +19,7 @@
"""List tests in a subunit stream."""
+from optparse import OptionParser
import sys
import unittest
@@ -26,32 +27,57 @@ from subunit import ProtocolTestCase
class TestIdPrintingResult(unittest.TestResult):
- def __init__(self, stream):
+ def __init__(self, stream, show_times=False):
"""Create a FilterResult object outputting to stream."""
unittest.TestResult.__init__(self)
self._stream = stream
self.failed_tests = 0
+ self.__time = 0
+ self.show_times = show_times
+ self._test = None
+ self._test_duration = 0
def addError(self, test, err):
self.failed_tests += 1
- self.reportTest(test)
+ self._test = test
def addFailure(self, test, err):
self.failed_tests += 1
- self.reportTest(test)
+ self._test = test
def addSuccess(self, test):
- self.reportTest(test)
+ self._test = test
- def reportTest(self, test):
- self._stream.write(test.id() + '\n')
+ def reportTest(self, test, duration):
+ if self.show_times:
+ self._stream.write(test.id() + ' %s\n' % duration)
+ else:
+ self._stream.write(test.id() + '\n')
+
+ def startTest(self, test):
+ self._start_time = self._time()
+
+ def stopTest(self, test):
+ test_duration = self._time() - self._start_time
+ self.reportTest(self._test, test_duration)
+
+ def time(self, time):
+ self.__time = time
+
+ def _time(self):
+ return self.__time
def wasSuccessful(self):
"Tells whether or not this result was a success"
return self.failed_tests == 0
-result = TestIdPrintingResult(sys.stdout)
+parser = OptionParser(description=__doc__)
+parser.add_option("--times", action="store_true",
+ help="list the time each test took in seconds "
+ "(requires a timestamped stream)", default=False)
+(options, args) = parser.parse_args()
+result = TestIdPrintingResult(sys.stdout, options.times)
test = ProtocolTestCase(sys.stdin)
test.run(result)
if result.wasSuccessful():