diff options
author | Robert Collins <robertc@robertcollins.net> | 2010-12-06 19:22:46 +1300 |
---|---|---|
committer | Robert Collins <robertc@robertcollins.net> | 2010-12-06 19:22:46 +1300 |
commit | 4045f2c89535934178df895e8b369cd63f82da03 (patch) | |
tree | 3f8f85de6fb27d3176133eb2442a5da9b5657dfd /testrepository/tests | |
parent | 5369521457f1de8307fe4c5d3a3897bf768067be (diff) | |
download | testrepository-4045f2c89535934178df895e8b369cd63f82da03.tar.gz |
* ``testr list-tests`` is a new command that will list the tests for a project
when ``.testr.conf`` has been configured with a ``test_list_option``.
(Robert Collins)
Diffstat (limited to 'testrepository/tests')
-rw-r--r-- | testrepository/tests/commands/__init__.py | 1 | ||||
-rw-r--r-- | testrepository/tests/commands/test_list_tests.py | 90 | ||||
-rw-r--r-- | testrepository/tests/test_commands.py | 6 | ||||
-rw-r--r-- | testrepository/tests/test_testcommand.py | 18 |
4 files changed, 112 insertions, 3 deletions
diff --git a/testrepository/tests/commands/__init__.py b/testrepository/tests/commands/__init__.py index 54b00fb..117221c 100644 --- a/testrepository/tests/commands/__init__.py +++ b/testrepository/tests/commands/__init__.py @@ -23,6 +23,7 @@ def test_suite(): 'help', 'init', 'last', + 'list_tests', 'load', 'quickstart', 'run', diff --git a/testrepository/tests/commands/test_list_tests.py b/testrepository/tests/commands/test_list_tests.py new file mode 100644 index 0000000..8d4e167 --- /dev/null +++ b/testrepository/tests/commands/test_list_tests.py @@ -0,0 +1,90 @@ +# +# Copyright (c) 2010 Testrepository Contributors +# +# 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. + +"""Tests for the list_tests command.""" + +import os.path +from subprocess import PIPE + +from testtools.matchers import MatchesException + +from testrepository.commands import list_tests +from testrepository.ui.model import UI +from testrepository.repository import memory +from testrepository.tests import ResourcedTestCase, Wildcard +from testrepository.tests.stubpackage import TempDirResource +from testrepository.tests.test_repository import make_test +from testrepository.tests.test_testcommand import FakeTestCommand + + +class TestCommand(ResourcedTestCase): + + resources = [('tempdir', TempDirResource())] + + def get_test_ui_and_cmd(self, options=(), args=()): + self.dirty() + ui = UI(options=options, args=args) + ui.here = self.tempdir + cmd = list_tests.list_tests(ui) + ui.set_command(cmd) + return ui, cmd + + def dirty(self): + # Ugly: TODO - improve testresources to make this go away. + dict(self.resources)['tempdir']._dirty = True + + def config_path(self): + return os.path.join(self.tempdir, '.testr.conf') + + def set_config(self, bytes): + stream = file(self.config_path(), 'wb') + try: + stream.write(bytes) + finally: + stream.close() + + def setup_repo(self, cmd, ui): + repo = cmd.repository_factory.initialise(ui.here) + inserter = repo.get_inserter() + inserter.startTestRun() + make_test('passing', True).run(inserter) + make_test('failing', False).run(inserter) + inserter.stopTestRun() + + def test_no_config_file_errors(self): + ui, cmd = self.get_test_ui_and_cmd() + self.assertEqual(3, cmd.execute()) + self.assertEqual(1, len(ui.outputs)) + self.assertEqual('error', ui.outputs[0][0]) + self.assertThat(ui.outputs[0][1], + MatchesException(ValueError('No .testr.conf config file'))) + + def test_calls_list_tests(self): + ui, cmd = self.get_test_ui_and_cmd(args=('bar', 'quux')) + cmd.repository_factory = memory.RepositoryFactory() + ui.proc_outputs = ['returned\n\nvalues\n'] + self.setup_repo(cmd, ui) + self.set_config( + '[DEFAULT]\ntest_command=foo $LISTOPT $IDOPTION\n' + 'test_id_option=--load-list $IDFILE\n' + 'test_list_option=--list\n') + self.assertEqual(0, cmd.execute()) + expected_cmd = 'foo --list bar quux' + self.assertEqual([ + ('values', [('running', expected_cmd)]), + ('popen', (expected_cmd,), + {'shell': True, 'stdout': PIPE, 'stdin': PIPE}), + ('communicate',), + ('stream', 'returned\nvalues\n'), + ], ui.outputs) diff --git a/testrepository/tests/test_commands.py b/testrepository/tests/test_commands.py index 3472b7f..130493e 100644 --- a/testrepository/tests/test_commands.py +++ b/testrepository/tests/test_commands.py @@ -90,9 +90,9 @@ class TestNameMangling(ResourcedTestCase): def test_sets_name(self): cmd = commands._find_command('foo-bar') - # This is arbitrary in the absence of a reason to do it any particular - # way. - self.assertEqual('foo_bar', cmd.name) + # The name is preserved, so that 'testr commands' shows something + # sensible. + self.assertEqual('foo-bar', cmd.name) class TestIterCommands(ResourcedTestCase): diff --git a/testrepository/tests/test_testcommand.py b/testrepository/tests/test_testcommand.py index a3ad6aa..d275304 100644 --- a/testrepository/tests/test_testcommand.py +++ b/testrepository/tests/test_testcommand.py @@ -161,3 +161,21 @@ class TestTestCommand(ResourcedTestCase): testargs=('bar', 'quux'))) expected_cmd = 'foo bar quux' self.assertEqual(expected_cmd, fixture.cmd) + + def test_list_tests_cmd(self): + ui, command = self.get_test_ui_and_cmd() + self.set_config( + '[DEFAULT]\ntest_command=foo $LISTOPT $IDLIST\ntest_id_list_default=whoo yea\n' + 'test_list_option=--list\n') + fixture = self.useFixture(command.get_run_command()) + expected_cmd = 'foo --list whoo yea' + self.assertEqual(expected_cmd, fixture.list_cmd) + + def test_list_tests_parsing(self): + ui, command = self.get_test_ui_and_cmd() + ui.proc_outputs = ['returned\nids\n'] + self.set_config( + '[DEFAULT]\ntest_command=foo $LISTOPT $IDLIST\ntest_id_list_default=whoo yea\n' + 'test_list_option=--list\n') + fixture = self.useFixture(command.get_run_command()) + self.assertEqual(set(['returned', 'ids']), set(fixture.list_tests())) |