diff options
author | Jelmer Vernooij <jelmer@jelmer.uk> | 2018-06-15 16:26:15 +0100 |
---|---|---|
committer | Jelmer Vernooij <jelmer@jelmer.uk> | 2018-06-15 16:26:15 +0100 |
commit | d58b830a94013a977e9bcac6fc15e7b914616082 (patch) | |
tree | dd305b67e99876ca94b02effd2009be73d5e92b7 | |
parent | 5ba2819498be5b7616cbb14dec40336455a600f1 (diff) | |
download | testrepository-git-d58b830a94013a977e9bcac6fc15e7b914616082.tar.gz |
Add --force-init support to 'testr run'.
-rw-r--r-- | testrepository/commands/run.py | 13 | ||||
-rw-r--r-- | testrepository/tests/commands/test_run.py | 26 |
2 files changed, 37 insertions, 2 deletions
diff --git a/testrepository/commands/run.py b/testrepository/commands/run.py index 3c21e25..13816f9 100644 --- a/testrepository/commands/run.py +++ b/testrepository/commands/run.py @@ -32,6 +32,7 @@ from testrepository.arguments.doubledash import DoubledashArgument from testrepository.arguments.string import StringArgument from testrepository.commands import Command from testrepository.commands.load import load +from testrepository.repository import RepositoryNotFound from testrepository.ui import decorator from testrepository.testcommand import TestCommand, testrconf_help from testrepository.testlist import parse_list @@ -134,6 +135,10 @@ class run(Command): help="Only some tests will be run. Implied by --failing."), optparse.Option("--subunit", action="store_true", default=False, help="Display results in subunit format."), + optparse.Option( + "--force-init", action="store_true", + default=False, + help="Initialise the repository if it does not exist already"), optparse.Option("--full-results", action="store_true", default=False, help="No-op - deprecated and kept only for backwards compat."), @@ -168,7 +173,13 @@ class run(Command): return ids def run(self): - repo = self.repository_factory.open(self.ui.here) + try: + repo = self.repository_factory.open(self.ui.here) + except RepositoryNotFound: + if self.ui.options.force_init: + repo = self.repository_factory.initialise(self.ui.here) + else: + raise if self.ui.options.failing or self.ui.options.analyze_isolation: ids = self._find_failing(repo) else: diff --git a/testrepository/tests/commands/test_run.py b/testrepository/tests/commands/test_run.py index a6d9ce1..c63ac66 100644 --- a/testrepository/tests/commands/test_run.py +++ b/testrepository/tests/commands/test_run.py @@ -38,7 +38,7 @@ from testtools.matchers import ( from testrepository.commands import run from testrepository.ui.model import UI, ProcessModel -from testrepository.repository import memory +from testrepository.repository import memory, RepositoryNotFound from testrepository.testlist import write_list from testrepository.tests import ResourcedTestCase, Wildcard from testrepository.tests.stubpackage import TempDirResource @@ -475,6 +475,30 @@ class TestCommand(ResourcedTestCase): self.assertThat(params[2][1], Equals(['cd'])) self.assertThat(params[3][1], Equals(['ef'])) + def test_fails_if_repo_doesnt_exist(self): + ui, cmd = self.get_test_ui_and_cmd(args=()) + cmd.repository_factory = memory.RepositoryFactory() + self.set_config( + '[DEFAULT]\ntest_command=foo $IDOPTION\ntest_id_option=--load-list $IDFILE\n') + 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(RepositoryNotFound)) + + def test_force_init(self): + ui, cmd = self.get_test_ui_and_cmd(options=[('force_init', True)]) + cmd.repository_factory = memory.RepositoryFactory() + self.set_config( + '[DEFAULT]\ntest_command=foo $IDOPTION\ntest_id_option=--load-list $IDFILE\n') + self.assertEqual(0, cmd.execute()) + self.assertEqual([ + ('values', [('running', 'foo ')]), + ('popen', ('foo ',), + {'shell': True, 'stdin': PIPE, 'stdout': PIPE}), + ('results', Wildcard), + ('summary', True, 0, None, Wildcard, Wildcard, [('id', 0, None)]), + ], ui.outputs) + def read_all(stream): return stream.read() |