Merge ~cjwatson/launchpad:tidy-bzr-code into launchpad:master

Proposed by Colin Watson
Status: Merged
Approved by: Colin Watson
Approved revision: f863d94f01680bbff664aeeea68026a0d137e315
Merge reported by: Otto Co-Pilot
Merged at revision: not available
Proposed branch: ~cjwatson/launchpad:tidy-bzr-code
Merge into: launchpad:master
Diff against target: 159 lines (+30/-36)
4 files modified
lib/lp/code/scripts/tests/test_reclaim_branch_space.py (+16/-0)
lib/lp/codehosting/tests/helpers.py (+0/-15)
lib/lp/testing/__init__.py (+1/-19)
utilities/make-dummy-hosted-branches (+13/-2)
Reviewer Review Type Date Requested Status
Ioana Lasc (community) Approve
Review via email: mp+393822@code.launchpad.net

Commit message

Move a few bzr helpers closer to their sole call sites

To post a comment you must log in.
Revision history for this message
Ioana Lasc (ilasc) :
review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1diff --git a/lib/lp/code/scripts/tests/test_reclaim_branch_space.py b/lib/lp/code/scripts/tests/test_reclaim_branch_space.py
2index b9e18d7..091b804 100644
3--- a/lib/lp/code/scripts/tests/test_reclaim_branch_space.py
4+++ b/lib/lp/code/scripts/tests/test_reclaim_branch_space.py
5@@ -7,12 +7,14 @@ import datetime
6 import os
7 import shutil
8
9+from breezy.transport import get_transport
10 import transaction
11
12 from lp.code.model.branchjob import (
13 BranchJob,
14 BranchJobType,
15 )
16+from lp.codehosting.vfs import branch_id_to_path
17 from lp.services.config import config
18 from lp.services.database.interfaces import IStore
19 from lp.services.scripts.tests import run_script
20@@ -24,6 +26,20 @@ class TestReclaimBranchSpaceScript(TestCaseWithFactory):
21
22 layer = ZopelessAppServerLayer
23
24+ @staticmethod
25+ def getBranchPath(branch, base):
26+ """Return the path of the branch in the mirrored area.
27+
28+ This always uses the configured mirrored area, ignoring whatever
29+ server might be providing lp-mirrored: urls.
30+ """
31+ # XXX gary 2009-5-28 bug 381325
32+ # This is a work-around for some failures on PQM, arguably caused by
33+ # relying on test set-up that is happening in the Makefile rather than
34+ # the actual test set-up.
35+ get_transport(base).create_prefix()
36+ return os.path.join(base, branch_id_to_path(branch.id))
37+
38 def test_reclaimbranchspace_script(self):
39 # When the reclaimbranchspace script is run, it removes from the file
40 # system any branches that were deleted from the database more than a
41diff --git a/lib/lp/codehosting/tests/helpers.py b/lib/lp/codehosting/tests/helpers.py
42index 143dbbd..295acaa 100644
43--- a/lib/lp/codehosting/tests/helpers.py
44+++ b/lib/lp/codehosting/tests/helpers.py
45@@ -11,7 +11,6 @@ __all__ = [
46 'create_branch_with_one_revision',
47 'force_stacked_on_url',
48 'LoomTestMixin',
49- 'make_bazaar_branch_and_tree',
50 'TestResultWrapper',
51 ]
52
53@@ -25,9 +24,6 @@ from breezy.tests import (
54 )
55 from testtools.twistedsupport import AsynchronousDeferredRunTest
56
57-from lp.code.enums import BranchType
58-from lp.codehosting.vfs import branch_id_to_path
59-from lp.services.config import config
60 from lp.testing import TestCase
61
62
63@@ -88,17 +84,6 @@ class LoomTestMixin:
64 return loom_tree
65
66
67-def make_bazaar_branch_and_tree(db_branch):
68- """Make a dummy Bazaar branch and working tree from a database Branch."""
69- assert db_branch.branch_type == BranchType.HOSTED, (
70- "Can only create branches for HOSTED branches: %r"
71- % db_branch)
72- branch_dir = os.path.join(
73- config.codehosting.mirrored_branches_root,
74- branch_id_to_path(db_branch.id))
75- return create_branch_with_one_revision(branch_dir)
76-
77-
78 def create_branch_with_one_revision(branch_dir, format=None):
79 """Create a dummy Bazaar branch at the given directory."""
80 # XXX cjwatson 2019-06-13: This still uses bzrlib until such time as the
81diff --git a/lib/lp/testing/__init__.py b/lib/lp/testing/__init__.py
82index 2b4882b..8fb58eb 100644
83--- a/lib/lp/testing/__init__.py
84+++ b/lib/lp/testing/__init__.py
85@@ -85,7 +85,6 @@ from breezy.controldir import (
86 ControlDir,
87 format_registry,
88 )
89-from breezy.transport import get_transport
90 import fixtures
91 from lazr.restful.testing.tales import test_tales
92 from lazr.restful.testing.webservice import FakeRequest
93@@ -126,10 +125,7 @@ from zope.security.proxy import (
94
95 from lp.app.interfaces.launchpad import ILaunchpadCelebrities
96 from lp.app.interfaces.security import IAuthorization
97-from lp.codehosting.vfs import (
98- branch_id_to_path,
99- get_rw_server,
100- )
101+from lp.codehosting.vfs import get_rw_server
102 from lp.registry.interfaces.packaging import IPackagingUtil
103 from lp.services import features
104 from lp.services.config import config
105@@ -933,20 +929,6 @@ class TestCaseWithFactory(TestCase):
106 naked_branch.last_scanned_id = bzr_branch.last_revision()
107 return bzr_branch
108
109- @staticmethod
110- def getBranchPath(branch, base):
111- """Return the path of the branch in the mirrored area.
112-
113- This always uses the configured mirrored area, ignoring whatever
114- server might be providing lp-mirrored: urls.
115- """
116- # XXX gary 2009-5-28 bug 381325
117- # This is a work-around for some failures on PQM, arguably caused by
118- # relying on test set-up that is happening in the Makefile rather than
119- # the actual test set-up.
120- get_transport(base).create_prefix()
121- return os.path.join(base, branch_id_to_path(branch.id))
122-
123 def useTempBzrHome(self):
124 self.useTempDir()
125 # Avoid leaking local user configuration into tests.
126diff --git a/utilities/make-dummy-hosted-branches b/utilities/make-dummy-hosted-branches
127index cd2c650..2b777a0 100755
128--- a/utilities/make-dummy-hosted-branches
129+++ b/utilities/make-dummy-hosted-branches
130@@ -25,16 +25,27 @@ import sys
131 import tempfile
132
133 import transaction
134-from zope.component import getUtility
135
136 from lp.code.enums import BranchType
137 from lp.code.model.branch import Branch
138-from lp.codehosting.tests.helpers import make_bazaar_branch_and_tree
139+from lp.codehosting.tests.helpers import create_branch_with_one_revision
140+from lp.codehosting.vfs import branch_id_to_path
141 from lp.services.config import config
142 from lp.services.database.sqlbase import sqlvalues
143 from lp.services.scripts import execute_zcml_for_scripts
144
145
146+def make_bazaar_branch_and_tree(db_branch):
147+ """Make a dummy Bazaar branch and working tree from a database Branch."""
148+ assert db_branch.branch_type == BranchType.HOSTED, (
149+ "Can only create branches for HOSTED branches: %r"
150+ % db_branch)
151+ branch_dir = os.path.join(
152+ config.codehosting.mirrored_branches_root,
153+ branch_id_to_path(db_branch.id))
154+ return create_branch_with_one_revision(branch_dir)
155+
156+
157 def main(argv):
158 os.environ['BZR_HOME'] = tempfile.mkdtemp()
159 if os.path.exists(config.codehosting.mirrored_branches_root):

Subscribers

People subscribed via source and target branches

to status/vote changes: