diff options
author | Robert Collins <robertc@robertcollins.net> | 2013-04-14 04:40:43 +1200 |
---|---|---|
committer | Robert Collins <robertc@robertcollins.net> | 2013-04-14 04:40:43 +1200 |
commit | 8d5e227ebf36deb8c5aab665b90a46e7630e0032 (patch) | |
tree | 516dd23fcdf1b42e237ad2d31ce80205ee4196f0 | |
parent | e6fa368625b8319c860a06f72cd52d4326db36c4 (diff) | |
download | testrepository-8d5e227ebf36deb8c5aab665b90a46e7630e0032.tar.gz |
Only return streams from CLI._iter_stream if the type matches the first type the command declared.
-rw-r--r-- | NEWS | 8 | ||||
-rw-r--r-- | testrepository/commands/load.py | 3 | ||||
-rw-r--r-- | testrepository/tests/ui/test_cli.py | 15 | ||||
-rw-r--r-- | testrepository/ui/cli.py | 7 |
4 files changed, 32 insertions, 1 deletions
@@ -5,6 +5,14 @@ testrepository release notes NEXT (In development) +++++++++++++++++++++ +CHANGES +------- + +* The cli UI now has primitive differentiation between multiple stream types. + This is not yet exposed to the end user, but is sufficient to enable the + load command to take interactive input without it reading from the raw + subunit stream on stdin. (Robert Collins) + 0.0.15 ++++++ diff --git a/testrepository/commands/load.py b/testrepository/commands/load.py index 3ba05ff..96d15f5 100644 --- a/testrepository/commands/load.py +++ b/testrepository/commands/load.py @@ -72,7 +72,8 @@ class load(Command): # back to it. Needs to be a callable - its a head fake for # testsuite.add. # XXX: Be nice if we could declare that the argument, which is a path, - # is to be an input stream. + # is to be an input stream - and thus push this conditional down into + # the UI object. if self.ui.arguments.get('streams'): opener = partial(open, mode='rb') streams = map(opener, self.ui.arguments['streams']) diff --git a/testrepository/tests/ui/test_cli.py b/testrepository/tests/ui/test_cli.py index 06a3dc4..e75caa7 100644 --- a/testrepository/tests/ui/test_cli.py +++ b/testrepository/tests/ui/test_cli.py @@ -79,6 +79,21 @@ class TestCLIUI(ResourcedTestCase): results.append(stream.read()) self.assertEqual([_b('foo\n')], results) + def test_stream_type_honoured(self): + # The CLI UI has only one stdin, so when a command asks for a stream + # type it didn't declare, no streams are found. + stdout = BytesIO() + stdin = BytesIO(_b('foo\n')) + stderr = BytesIO() + ui = cli.UI([], stdin, stdout, stderr) + cmd = commands.Command(ui) + cmd.input_streams = ['subunit+', 'interactive?'] + ui.set_command(cmd) + results = [] + for stream in ui.iter_streams('interactive'): + results.append(stream.read()) + self.assertEqual([], results) + def test_dash_d_sets_here_option(self): stdout = BytesIO() stdin = BytesIO(_b('foo\n')) diff --git a/testrepository/ui/cli.py b/testrepository/ui/cli.py index e5cd9ff..d387b50 100644 --- a/testrepository/ui/cli.py +++ b/testrepository/ui/cli.py @@ -95,6 +95,13 @@ class UI(ui.AbstractUI): self._stderr = stderr def _iter_streams(self, stream_type): + # Only the first stream declared in a command can be accepted at the + # moment - as there is only one stdin and alternate streams are not yet + # configurable in the CLI. + first_stream_type = self.cmd.input_streams[0] + if (stream_type != first_stream_type + and stream_type != first_stream_type[:-1]): + return yield subunit.make_stream_binary(self._stdin) def make_result(self, get_id, test_command, previous_run=None): |