diff options
| author | Jonathan Lange <jml@canonical.com> | 2012-02-01 18:46:25 +0000 |
|---|---|---|
| committer | Jonathan Lange <jml@canonical.com> | 2012-02-01 18:46:25 +0000 |
| commit | c4924ff01abc2805a137c27de7ea18747abdcd04 (patch) | |
| tree | ebacc12013ef6084014ebbddbb73f86a5c00f24c /python/subunit/tests/test_run.py | |
| parent | 6033d5b90991de13604f7de3ed6e42581b01d2c2 (diff) | |
| parent | 29021cef8d10e194c1229b73c5388502b8c8aa74 (diff) | |
| download | subunit-git-c4924ff01abc2805a137c27de7ea18747abdcd04.tar.gz | |
Merge trunk
Diffstat (limited to 'python/subunit/tests/test_run.py')
| -rw-r--r-- | python/subunit/tests/test_run.py | 52 |
1 files changed, 52 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..5a96bcf --- /dev/null +++ b/python/subunit/tests/test_run.py @@ -0,0 +1,52 @@ +# +# subunit: extensions to python unittest to get test results from subprocesses. +# Copyright (C) 2011 Robert Collins <robertc@robertcollins.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) |
