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
diff --git a/lib/lp/code/scripts/tests/test_reclaim_branch_space.py b/lib/lp/code/scripts/tests/test_reclaim_branch_space.py
index b9e18d7..091b804 100644
--- a/lib/lp/code/scripts/tests/test_reclaim_branch_space.py
+++ b/lib/lp/code/scripts/tests/test_reclaim_branch_space.py
@@ -7,12 +7,14 @@ import datetime
7import os7import os
8import shutil8import shutil
99
10from breezy.transport import get_transport
10import transaction11import transaction
1112
12from lp.code.model.branchjob import (13from lp.code.model.branchjob import (
13 BranchJob,14 BranchJob,
14 BranchJobType,15 BranchJobType,
15 )16 )
17from lp.codehosting.vfs import branch_id_to_path
16from lp.services.config import config18from lp.services.config import config
17from lp.services.database.interfaces import IStore19from lp.services.database.interfaces import IStore
18from lp.services.scripts.tests import run_script20from lp.services.scripts.tests import run_script
@@ -24,6 +26,20 @@ class TestReclaimBranchSpaceScript(TestCaseWithFactory):
2426
25 layer = ZopelessAppServerLayer27 layer = ZopelessAppServerLayer
2628
29 @staticmethod
30 def getBranchPath(branch, base):
31 """Return the path of the branch in the mirrored area.
32
33 This always uses the configured mirrored area, ignoring whatever
34 server might be providing lp-mirrored: urls.
35 """
36 # XXX gary 2009-5-28 bug 381325
37 # This is a work-around for some failures on PQM, arguably caused by
38 # relying on test set-up that is happening in the Makefile rather than
39 # the actual test set-up.
40 get_transport(base).create_prefix()
41 return os.path.join(base, branch_id_to_path(branch.id))
42
27 def test_reclaimbranchspace_script(self):43 def test_reclaimbranchspace_script(self):
28 # When the reclaimbranchspace script is run, it removes from the file44 # When the reclaimbranchspace script is run, it removes from the file
29 # system any branches that were deleted from the database more than a45 # system any branches that were deleted from the database more than a
diff --git a/lib/lp/codehosting/tests/helpers.py b/lib/lp/codehosting/tests/helpers.py
index 143dbbd..295acaa 100644
--- a/lib/lp/codehosting/tests/helpers.py
+++ b/lib/lp/codehosting/tests/helpers.py
@@ -11,7 +11,6 @@ __all__ = [
11 'create_branch_with_one_revision',11 'create_branch_with_one_revision',
12 'force_stacked_on_url',12 'force_stacked_on_url',
13 'LoomTestMixin',13 'LoomTestMixin',
14 'make_bazaar_branch_and_tree',
15 'TestResultWrapper',14 'TestResultWrapper',
16 ]15 ]
1716
@@ -25,9 +24,6 @@ from breezy.tests import (
25 )24 )
26from testtools.twistedsupport import AsynchronousDeferredRunTest25from testtools.twistedsupport import AsynchronousDeferredRunTest
2726
28from lp.code.enums import BranchType
29from lp.codehosting.vfs import branch_id_to_path
30from lp.services.config import config
31from lp.testing import TestCase27from lp.testing import TestCase
3228
3329
@@ -88,17 +84,6 @@ class LoomTestMixin:
88 return loom_tree84 return loom_tree
8985
9086
91def make_bazaar_branch_and_tree(db_branch):
92 """Make a dummy Bazaar branch and working tree from a database Branch."""
93 assert db_branch.branch_type == BranchType.HOSTED, (
94 "Can only create branches for HOSTED branches: %r"
95 % db_branch)
96 branch_dir = os.path.join(
97 config.codehosting.mirrored_branches_root,
98 branch_id_to_path(db_branch.id))
99 return create_branch_with_one_revision(branch_dir)
100
101
102def create_branch_with_one_revision(branch_dir, format=None):87def create_branch_with_one_revision(branch_dir, format=None):
103 """Create a dummy Bazaar branch at the given directory."""88 """Create a dummy Bazaar branch at the given directory."""
104 # XXX cjwatson 2019-06-13: This still uses bzrlib until such time as the89 # XXX cjwatson 2019-06-13: This still uses bzrlib until such time as the
diff --git a/lib/lp/testing/__init__.py b/lib/lp/testing/__init__.py
index 2b4882b..8fb58eb 100644
--- a/lib/lp/testing/__init__.py
+++ b/lib/lp/testing/__init__.py
@@ -85,7 +85,6 @@ from breezy.controldir import (
85 ControlDir,85 ControlDir,
86 format_registry,86 format_registry,
87 )87 )
88from breezy.transport import get_transport
89import fixtures88import fixtures
90from lazr.restful.testing.tales import test_tales89from lazr.restful.testing.tales import test_tales
91from lazr.restful.testing.webservice import FakeRequest90from lazr.restful.testing.webservice import FakeRequest
@@ -126,10 +125,7 @@ from zope.security.proxy import (
126125
127from lp.app.interfaces.launchpad import ILaunchpadCelebrities126from lp.app.interfaces.launchpad import ILaunchpadCelebrities
128from lp.app.interfaces.security import IAuthorization127from lp.app.interfaces.security import IAuthorization
129from lp.codehosting.vfs import (128from lp.codehosting.vfs import get_rw_server
130 branch_id_to_path,
131 get_rw_server,
132 )
133from lp.registry.interfaces.packaging import IPackagingUtil129from lp.registry.interfaces.packaging import IPackagingUtil
134from lp.services import features130from lp.services import features
135from lp.services.config import config131from lp.services.config import config
@@ -933,20 +929,6 @@ class TestCaseWithFactory(TestCase):
933 naked_branch.last_scanned_id = bzr_branch.last_revision()929 naked_branch.last_scanned_id = bzr_branch.last_revision()
934 return bzr_branch930 return bzr_branch
935931
936 @staticmethod
937 def getBranchPath(branch, base):
938 """Return the path of the branch in the mirrored area.
939
940 This always uses the configured mirrored area, ignoring whatever
941 server might be providing lp-mirrored: urls.
942 """
943 # XXX gary 2009-5-28 bug 381325
944 # This is a work-around for some failures on PQM, arguably caused by
945 # relying on test set-up that is happening in the Makefile rather than
946 # the actual test set-up.
947 get_transport(base).create_prefix()
948 return os.path.join(base, branch_id_to_path(branch.id))
949
950 def useTempBzrHome(self):932 def useTempBzrHome(self):
951 self.useTempDir()933 self.useTempDir()
952 # Avoid leaking local user configuration into tests.934 # Avoid leaking local user configuration into tests.
diff --git a/utilities/make-dummy-hosted-branches b/utilities/make-dummy-hosted-branches
index cd2c650..2b777a0 100755
--- a/utilities/make-dummy-hosted-branches
+++ b/utilities/make-dummy-hosted-branches
@@ -25,16 +25,27 @@ import sys
25import tempfile25import tempfile
2626
27import transaction27import transaction
28from zope.component import getUtility
2928
30from lp.code.enums import BranchType29from lp.code.enums import BranchType
31from lp.code.model.branch import Branch30from lp.code.model.branch import Branch
32from lp.codehosting.tests.helpers import make_bazaar_branch_and_tree31from lp.codehosting.tests.helpers import create_branch_with_one_revision
32from lp.codehosting.vfs import branch_id_to_path
33from lp.services.config import config33from lp.services.config import config
34from lp.services.database.sqlbase import sqlvalues34from lp.services.database.sqlbase import sqlvalues
35from lp.services.scripts import execute_zcml_for_scripts35from lp.services.scripts import execute_zcml_for_scripts
3636
3737
38def make_bazaar_branch_and_tree(db_branch):
39 """Make a dummy Bazaar branch and working tree from a database Branch."""
40 assert db_branch.branch_type == BranchType.HOSTED, (
41 "Can only create branches for HOSTED branches: %r"
42 % db_branch)
43 branch_dir = os.path.join(
44 config.codehosting.mirrored_branches_root,
45 branch_id_to_path(db_branch.id))
46 return create_branch_with_one_revision(branch_dir)
47
48
38def main(argv):49def main(argv):
39 os.environ['BZR_HOME'] = tempfile.mkdtemp()50 os.environ['BZR_HOME'] = tempfile.mkdtemp()
40 if os.path.exists(config.codehosting.mirrored_branches_root):51 if os.path.exists(config.codehosting.mirrored_branches_root):

Subscribers

People subscribed via source and target branches

to status/vote changes: