diff options
author | Robert Collins <robertc@robertcollins.net> | 2013-04-08 00:05:05 +1200 |
---|---|---|
committer | Robert Collins <robertc@robertcollins.net> | 2013-04-08 00:05:05 +1200 |
commit | c64ec4fe698cc337a415baafe562f6d45d7e78f9 (patch) | |
tree | fd2d7d8e168b38de6715e416add0305106158801 | |
parent | 15124cb50d441bd007b10a5361d53b938f47ae50 (diff) | |
download | testrepository-c64ec4fe698cc337a415baafe562f6d45d7e78f9.tar.gz |
Add test for --subunit support - the UI was previously only loosely tested.
-rw-r--r-- | testrepository/tests/ui/test_cli.py | 16 | ||||
-rw-r--r-- | testrepository/ui/cli.py | 11 |
2 files changed, 23 insertions, 4 deletions
diff --git a/testrepository/tests/ui/test_cli.py b/testrepository/tests/ui/test_cli.py index eaa4193..01ac8cc 100644 --- a/testrepository/tests/ui/test_cli.py +++ b/testrepository/tests/ui/test_cli.py @@ -320,12 +320,16 @@ class TestCLITestResult(TestCase): except ZeroDivisionError: return sys.exc_info() - def make_result(self, stream=None): + def make_result(self, stream=None, argv=None): if stream is None: stream = BytesIO() - argv = [] + argv = argv or [] ui = cli.UI(argv, None, stream, None) cmd = commands.Command(ui) + cmd.options = [ + optparse.Option("--subunit", action="store_true", + default=False, help="Display results in subunit format."), + ] ui.set_command(cmd) return ui.make_result(lambda: None, StubTestCommand()) @@ -393,3 +397,11 @@ class TestCLITestResult(TestCase): self.assertThat( stream.getvalue().decode('utf8'), DocTestMatches(pattern, doctest.ELLIPSIS)) + + def test_subunit_output(self): + bytestream = BytesIO() + stream = TextIOWrapper(bytestream, 'utf8', line_buffering=True) + result = self.make_result(stream, argv=['--subunit'])[0] + result.startTestRun() + result.stopTestRun() + self.assertEqual(b'', bytestream.getvalue()) diff --git a/testrepository/ui/cli.py b/testrepository/ui/cli.py index b0de823..1c8840d 100644 --- a/testrepository/ui/cli.py +++ b/testrepository/ui/cli.py @@ -20,6 +20,9 @@ import signal import subunit import sys +from extras import try_import +v2_avail = try_import('subunit.ByteStreamToStreamResult') +import testtools from testtools import ExtendedToStreamDecorator, StreamToExtendedDecorator from testtools.compat import unicode_output_stream, _u @@ -80,10 +83,14 @@ class UI(ui.AbstractUI): def make_result(self, get_id, test_command, previous_run=None): if getattr(self.options, 'subunit', False): + if v2_avail: + serializer = subunit.StreamResultToBytes(self._stdout) + else: + serializer = StreamToExtendedDecorator( + subunit.TestProtocolClient(self._stdout)) # By pass user transforms - just forward it all and interpret # everything as success. - result = ExtendedToStreamDecorator(StreamToExtendedDecorator( - subunit.TestProtocolClient(self._stdout))) + result = ExtendedToStreamDecorator(serializer) summary = testtools.StreamSummary() summary.startTestRun() summary.stopTestRun() |