diff options
author | Robert Collins <robertc@robertcollins.net> | 2010-01-14 19:00:37 +1100 |
---|---|---|
committer | Robert Collins <robertc@robertcollins.net> | 2010-01-14 19:00:37 +1100 |
commit | 641bfc36974c673512f8bd2b5e82f55b2e6092d8 (patch) | |
tree | 77bc67c061ac35bd48bb0e7611ec9d90dfd942e6 | |
parent | a0ec5a99b91832f96684852bce5941dd25cc759f (diff) | |
download | testrepository-git-641bfc36974c673512f8bd2b5e82f55b2e6092d8.tar.gz |
Add stream output support for the UI.
-rw-r--r-- | testrepository/tests/test_ui.py | 5 | ||||
-rw-r--r-- | testrepository/tests/ui/test_cli.py | 6 | ||||
-rw-r--r-- | testrepository/ui/__init__.py | 11 | ||||
-rw-r--r-- | testrepository/ui/cli.py | 6 | ||||
-rw-r--r-- | testrepository/ui/model.py | 3 |
5 files changed, 31 insertions, 0 deletions
diff --git a/testrepository/tests/test_ui.py b/testrepository/tests/test_ui.py index d16cdaf..e5c24d8 100644 --- a/testrepository/tests/test_ui.py +++ b/testrepository/tests/test_ui.py @@ -100,6 +100,11 @@ class TestUIContract(ResourcedTestCase): pass ui.output_results(Case('method')) + def test_output_stream(self): + # a stream of bytes can be output. + ui = self.get_test_ui() + ui.output_stream(StringIO()) + def test_output_table(self): # output_table shows a table. ui = self.get_test_ui() diff --git a/testrepository/tests/ui/test_cli.py b/testrepository/tests/ui/test_cli.py index cf4b6cf..67a95c3 100644 --- a/testrepository/tests/ui/test_cli.py +++ b/testrepository/tests/ui/test_cli.py @@ -90,6 +90,12 @@ AssertionError: quux ------------ """, doctest.ELLIPSIS)) + def test_outputs_stream_to_stdout(self): + ui, cmd = self.get_test_ui_and_cmd() + stream = StringIO("Foo \n bar") + ui.output_stream(stream) + self.assertEqual("Foo \n bar", ui._stdout.getvalue()) + def test_outputs_tables_to_stdout(self): ui, cmd = self.get_test_ui_and_cmd() ui.output_table([('foo', 1), ('b', 'quux')]) diff --git a/testrepository/ui/__init__.py b/testrepository/ui/__init__.py index eac93a1..d6d4339 100644 --- a/testrepository/ui/__init__.py +++ b/testrepository/ui/__init__.py @@ -102,6 +102,17 @@ class AbstractUI(object): """ raise NotImplementedError(self.output_results) + def output_stream(self, stream): + """Show a byte stream to the user. + + This is not currently typed, but in future a MIME type may be + permitted. + + :param stream: A file like object that can be read from. The UI will + not close the file. + """ + raise NotImplementedError(self.output_results) + def output_table(self, table): """Show a table to the user. diff --git a/testrepository/ui/cli.py b/testrepository/ui/cli.py index 0ad4cd3..3f2ff81 100644 --- a/testrepository/ui/cli.py +++ b/testrepository/ui/cli.py @@ -77,6 +77,12 @@ class UI(ui.AbstractUI): finally: result.stopTestRun() + def output_stream(self, stream): + contents = stream.read(65536) + while contents: + self._stdout.write(contents) + contents = stream.read(65536) + def output_table(self, table): # stringify contents = [] diff --git a/testrepository/ui/model.py b/testrepository/ui/model.py index 267cdd5..494c4e5 100644 --- a/testrepository/ui/model.py +++ b/testrepository/ui/model.py @@ -81,6 +81,9 @@ class UI(ui.AbstractUI): def output_results(self, suite_or_test): self.outputs.append(('results', suite_or_test)) + def output_stream(self, stream): + self.outputs.append(('stream', stream)) + def output_table(self, table): self.outputs.append(('table', table)) |