diff options
| author | Robert Collins <robertc@robertcollins.net> | 2013-03-03 23:11:19 +1300 |
|---|---|---|
| committer | Robert Collins <robertc@robertcollins.net> | 2013-03-03 23:11:19 +1300 |
| commit | 7444588c895e2dc3946d6ca3e6650d4549cd4d43 (patch) | |
| tree | 5c531fbf57533cde4fc0ea9b262c9375958d10e4 /python | |
| parent | b1d5d5881f378273ce0dc8d8301d4ba25bcd4988 (diff) | |
| download | subunit-git-7444588c895e2dc3946d6ca3e6650d4549cd4d43.tar.gz | |
Convert subunit.run to v2.
Diffstat (limited to 'python')
| -rwxr-xr-x | python/subunit/run.py | 12 | ||||
| -rw-r--r-- | python/subunit/tests/test_run.py | 19 |
2 files changed, 15 insertions, 16 deletions
diff --git a/python/subunit/run.py b/python/subunit/run.py index b5ccea4..479691d 100755 --- a/python/subunit/run.py +++ b/python/subunit/run.py @@ -22,7 +22,9 @@ import sys -from subunit import TestProtocolClient, get_default_formatter +from testtools import ExtendedToStreamDecorator + +from subunit import StreamResultToBytes, get_default_formatter from subunit.test_results import AutoTimingTestResultDecorator from testtools.run import ( BUFFEROUTPUT, @@ -46,11 +48,15 @@ class SubunitTestRunner(object): def run(self, test): "Run the given test case or test suite." - result = TestProtocolClient(self.stream) + result = ExtendedToStreamDecorator(StreamResultToBytes(self.stream)) result = AutoTimingTestResultDecorator(result) if self.failfast is not None: result.failfast = self.failfast - test(result) + result.startTestRun() + try: + test(result) + finally: + result.stopTestRun() return result diff --git a/python/subunit/tests/test_run.py b/python/subunit/tests/test_run.py index 10519ed..2944419 100644 --- a/python/subunit/tests/test_run.py +++ b/python/subunit/tests/test_run.py @@ -18,6 +18,7 @@ from testtools.compat import BytesIO import unittest from testtools import PlaceHolder +from testtools.testresult.doubles import StreamResult import subunit from subunit.run import SubunitTestRunner @@ -29,16 +30,6 @@ def test_suite(): return result -class TimeCollectingTestResult(unittest.TestResult): - - def __init__(self, *args, **kwargs): - super(TimeCollectingTestResult, self).__init__(*args, **kwargs) - self.time_called = [] - - def time(self, a_time): - self.time_called.append(a_time) - - class TestSubunitTestRunner(unittest.TestCase): def test_includes_timing_output(self): @@ -46,7 +37,9 @@ class TestSubunitTestRunner(unittest.TestCase): runner = SubunitTestRunner(stream=io) test = PlaceHolder('name') runner.run(test) - client = TimeCollectingTestResult() io.seek(0) - subunit.TestProtocolServer(client).readFrom(io) - self.assertTrue(len(client.time_called) > 0) + eventstream = StreamResult() + subunit.ByteStreamToStreamResult(io).run(eventstream) + timestamps = [event[-1] for event in eventstream._events + if event is not None] + self.assertNotEqual([], timestamps) |
