diff options
| author | James Westby <james.westby@linaro.org> | 2011-11-01 11:59:58 -0400 |
|---|---|---|
| committer | James Westby <james.westby@linaro.org> | 2011-11-01 11:59:58 -0400 |
| commit | 4b1040bee710cd126df2847a933d0960b5fd568f (patch) | |
| tree | 06a0cbade27dfe95d42101b31ba613e03e994f20 /python/subunit/tests/test_run.py | |
| parent | 60fea6784a456673fd9e42e93d8c5bf3f4a0e6f1 (diff) | |
| download | subunit-4b1040bee710cd126df2847a933d0960b5fd568f.tar.gz | |
Have the output of subunit.run include timing information.
Diffstat (limited to 'python/subunit/tests/test_run.py')
| -rw-r--r-- | python/subunit/tests/test_run.py | 53 |
1 files changed, 53 insertions, 0 deletions
diff --git a/python/subunit/tests/test_run.py b/python/subunit/tests/test_run.py new file mode 100644 index 0000000..e695703 --- /dev/null +++ b/python/subunit/tests/test_run.py @@ -0,0 +1,53 @@ +# +# subunit: extensions to python unittest to get test results from subprocesses. +# Copyright (C) 2005 Robert Collins <robertc@robertcollins.net> +# Copyright (C) 2011 Martin Pool <mbp@sourcefrog.net> +# +# Licensed under either the Apache License, Version 2.0 or the BSD 3-clause +# license at the users choice. A copy of both licenses are available in the +# project source as Apache-2.0 and BSD. You may not use this file except in +# compliance with one of these two licences. +# +# Unless required by applicable law or agreed to in writing, software +# distributed under these licenses is distributed on an "AS IS" BASIS, WITHOUT +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +# license you chose for the specific language governing permissions and +# limitations under that license. +# + +from cStringIO import StringIO +import unittest + +from testtools import PlaceHolder + +import subunit +from subunit.run import SubunitTestRunner + + +def test_suite(): + loader = subunit.tests.TestUtil.TestLoader() + result = loader.loadTestsFromName(__name__) + 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): + io = StringIO() + 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) |
