Merge lp:~jml/testrepository/load-implies-init into lp:~testrepository/testrepository/trunk

Proposed by Jonathan Lange
Status: Merged
Merged at revision: 134
Proposed branch: lp:~jml/testrepository/load-implies-init
Merge into: lp:~testrepository/testrepository/trunk
Diff against target: 85 lines (+39/-2)
2 files modified
testrepository/commands/load.py (+12/-1)
testrepository/tests/commands/test_load.py (+27/-1)
To merge this branch: bzr merge lp:~jml/testrepository/load-implies-init
Reviewer Review Type Date Requested Status
Robert Collins Needs Information
Review via email: mp+31677@code.launchpad.net

Description of the change

I keep being bugged by having to run "testr init" every time I make a new branch. So I've fixed the bug.

The branch does this by modifying the interface to RepositoryFactory, requiring it to raise RepositoryNotFound when it cannot find a repository at the given URL. The branch adds the new exception type and tests for the interface, and then modifies the file and memory repositories to provide the interface correctly.

The upshot of this change is that bug 530010 gets fixed automatically. Which is nice.

The branch then adds a new test for the 'load' command to show that it tries to open a repository and then initializes[1] the repository if it is not found.

[1] Following OED preferred spelling.

To post a comment you must log in.
Revision history for this message
Robert Collins (lifeless) wrote :

I'm really torn on this. I like the potential improvements in repository error output (especially if we use exception chaining or some such).

However, auto-initialising a repo really rubs me badly.

How would you feel if I merged all but the last revision?

review: Needs Information
95. By Jonathan Lange

Merge trunk. Resolve conflicts.

96. By Jonathan Lange

NEWS message.

Revision history for this message
Jonathan Lange (jml) wrote :

I'd be OK with that (assuming you mean r94). It's still a net improvement. I do, however, think that testr still has some way to go to work in a pleasing way as part of a directory-per-branch workflow.

Revision history for this message
Robert Collins (lifeless) wrote :

I'd be ok with a flag to say 'just do it'.

Revision history for this message
Robert Collins (lifeless) wrote :

This is blocked pending a flag to control this being added. E.g. --auto, --force, --magic - whatever.

Revision history for this message
Jonathan Lange (jml) wrote :

Updated to be --force-init.

97. By Jonathan Lange

Merge trunk

98. By Jonathan Lange

Merge trunk

99. By Jonathan Lange

Add a '--force-init' option and only initialize repo on load if it's passed.

100. By Jonathan Lange

Restore NEWS item lost in conflict

101. By Jonathan Lange

Use assertThat

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'testrepository/commands/load.py'
2--- testrepository/commands/load.py 2010-12-07 03:16:41 +0000
3+++ testrepository/commands/load.py 2011-01-14 00:14:11 +0000
4@@ -20,6 +20,7 @@
5 from testtools import ConcurrentTestSuite, MultiTestResult
6
7 from testrepository.commands import Command
8+from testrepository.repository import RepositoryNotFound
9 from testrepository.results import TestResultFilter
10
11
12@@ -37,11 +38,21 @@
13 options = [
14 optparse.Option("--partial", action="store_true",
15 default=False, help="The stream being loaded was a partial run."),
16+ optparse.Option(
17+ "--force-init", action="store_true",
18+ default=False,
19+ help="Initialise the repository if it does not exist already"),
20 ]
21
22 def run(self):
23 path = self.ui.here
24- repo = self.repository_factory.open(path)
25+ try:
26+ repo = self.repository_factory.open(path)
27+ except RepositoryNotFound:
28+ if self.ui.options.force_init:
29+ repo = self.repository_factory.initialise(path)
30+ else:
31+ raise
32 run_id = None
33 # Not a full implementation of TestCase, but we only need to iterate
34 # back to it. Needs to be a callable - its a head fake for
35
36=== modified file 'testrepository/tests/commands/test_load.py'
37--- testrepository/tests/commands/test_load.py 2010-12-07 03:16:41 +0000
38+++ testrepository/tests/commands/test_load.py 2011-01-14 00:14:11 +0000
39@@ -15,12 +15,13 @@
40 """Tests for the load command."""
41
42 import testtools
43+from testtools.matchers import MatchesException
44
45 from testrepository.commands import load
46 from testrepository.ui.model import UI
47 from testrepository.tests import ResourcedTestCase, Wildcard
48 from testrepository.tests.test_repository import RecordingRepositoryFactory
49-from testrepository.repository import memory
50+from testrepository.repository import memory, RepositoryNotFound
51
52
53 class TestCommandLoad(ResourcedTestCase):
54@@ -42,6 +43,31 @@
55 # Results loaded
56 self.assertEqual(1, repo.count())
57
58+ def test_load_initialises_repo_if_doesnt_exist_and_init_forced(self):
59+ ui = UI([('subunit', '')], options=[('force_init', True)])
60+ cmd = load.load(ui)
61+ ui.set_command(cmd)
62+ calls = []
63+ cmd.repository_factory = RecordingRepositoryFactory(calls,
64+ memory.RepositoryFactory())
65+ del calls[:]
66+ cmd.execute()
67+ self.assertEqual([('open', ui.here), ('initialise', ui.here)], calls)
68+
69+ def test_load_errors_if_repo_doesnt_exist(self):
70+ ui = UI([('subunit', '')])
71+ cmd = load.load(ui)
72+ ui.set_command(cmd)
73+ calls = []
74+ cmd.repository_factory = RecordingRepositoryFactory(calls,
75+ memory.RepositoryFactory())
76+ del calls[:]
77+ cmd.execute()
78+ self.assertEqual([('open', ui.here)], calls)
79+ self.assertEqual([('error', Wildcard)], ui.outputs)
80+ self.assertThat(
81+ ui.outputs[0][1], MatchesException(RepositoryNotFound('memory:')))
82+
83 def test_load_returns_0_normally(self):
84 ui = UI([('subunit', '')])
85 cmd = load.load(ui)

Subscribers

People subscribed via source and target branches