Rev 6029: Pull out code into helper functions, which allows us to test it. in http://bazaar.launchpad.net/~jameinel/bzr/2.5-up-to-date-609187
John Arbash Meinel
john at arbash-meinel.com
Mon Jul 18 16:23:47 UTC 2011
At http://bazaar.launchpad.net/~jameinel/bzr/2.5-up-to-date-609187
------------------------------------------------------------
revno: 6029
revision-id: john at arbash-meinel.com-20110718162248-hulru3k592nqlgho
parent: john at arbash-meinel.com-20110718160536-b9irkw7kpze28035
committer: John Arbash Meinel <john at arbash-meinel.com>
branch nick: 2.5-up-to-date-609187
timestamp: Mon 2011-07-18 18:22:48 +0200
message:
Pull out code into helper functions, which allows us to test it.
-------------- next part --------------
=== modified file 'bzrlib/plugins/launchpad/__init__.py'
--- a/bzrlib/plugins/launchpad/__init__.py 2011-07-18 16:05:36 +0000
+++ b/bzrlib/plugins/launchpad/__init__.py 2011-07-18 16:22:48 +0000
@@ -467,23 +467,43 @@
_register_directory()
-
-package_branch = lazy_regex.lazy_compile(
+# This is kept in __init__ so that we don't load lp_api_lite unless the branch
+# actually matches. That way we can avoid importing extra dependencies like
+# json.
+_package_branch = lazy_regex.lazy_compile(
r'bazaar.launchpad.net.*?/'
r'(?P<user>~[^/]+/)?(?P<archive>ubuntu|debian)/(?P<series>[^/]+/)?'
r'(?P<project>[^/]+)(?P<branch>/[^/]+)?'
)
-def _check_is_up_to_date(the_branch):
- m = package_branch.search(the_branch.base)
+
+def _get_package_branch_info(url):
+ """Determine the packaging information for this URL.
+
+ :return: If this isn't a packaging branch, return None. If it is, return
+ (archive, series, project)
+ """
+ m = _package_branch.search(url)
if m is None:
return
- from bzrlib.plugins.launchpad import lp_api_lite
archive, series, project, user = m.group('archive', 'series',
'project', 'user')
if series is not None:
# series is optional, so the regex includes the extra '/', we don't
# want to send that on (it causes Internal Server Errors.)
series = series.strip('/')
+ if user is not None:
+ user = user.strip('~/')
+ if user != 'ubuntu-branches':
+ return None
+ return archive, series, project
+
+
+def _check_is_up_to_date(the_branch):
+ info = _get_package_branch_info(the_branch.base)
+ if info is None:
+ return
+ archive, series, project = info
+ from bzrlib.plugins.launchpad import lp_api_lite
t = time.time()
latest_pub = lp_api_lite.LatestPublication(archive, series, project)
latest_ver = latest_pub.get_latest_version()
=== modified file 'bzrlib/plugins/launchpad/lp_api_lite.py'
--- a/bzrlib/plugins/launchpad/lp_api_lite.py 2011-07-18 14:22:20 +0000
+++ b/bzrlib/plugins/launchpad/lp_api_lite.py 2011-07-18 16:22:48 +0000
@@ -36,7 +36,9 @@
import urllib
import urllib2
-from bzrlib import trace
+from bzrlib import (
+ trace,
+ )
class LatestPublication(object):
@@ -166,3 +168,5 @@
"""
lp = LatestPublication(archive, series, project)
return lp.get_latest_version()
+
+
=== modified file 'bzrlib/plugins/launchpad/test_lp_api_lite.py'
--- a/bzrlib/plugins/launchpad/test_lp_api_lite.py 2011-07-18 16:05:36 +0000
+++ b/bzrlib/plugins/launchpad/test_lp_api_lite.py 2011-07-18 16:22:48 +0000
@@ -266,22 +266,29 @@
class TestIsUpToDate(tests.TestCase):
def assertPackageBranchRe(self, url, user, archive, series, project):
- m = launchpad.package_branch.search(url)
+ m = launchpad._package_branch.search(url)
if m is None:
self.fail('package_branch regex did not match url: %s' % (url,))
self.assertEqual(
(user, archive, series, project),
m.group('user', 'archive', 'series', 'project'))
+ def assertNotPackageBranch(self, url):
+ self.assertIs(None, launchpad._get_package_branch_info(url))
+
+ def assertBranchInfo(self, url, archive, series, project):
+ self.assertEqual((archive, series, project),
+ launchpad._get_package_branch_info(url))
+
def test_package_branch_regex(self):
self.assertPackageBranchRe(
'http://bazaar.launchpad.net/+branch/ubuntu/foo',
None, 'ubuntu', None, 'foo')
self.assertPackageBranchRe(
- 'http://bazaar.launchpad.net/+branch/ubuntu/natty/foo',
+ 'bzr+ssh://bazaar.launchpad.net/+branch/ubuntu/natty/foo',
None, 'ubuntu', 'natty/', 'foo')
self.assertPackageBranchRe(
- 'http://bazaar.launchpad.net/+branch/debian/foo',
+ 'sftp://bazaar.launchpad.net/+branch/debian/foo',
None, 'debian', None, 'foo')
self.assertPackageBranchRe(
'http://bazaar.launchpad.net/+branch/debian/sid/foo',
@@ -290,3 +297,31 @@
'http://bazaar.launchpad.net/+branch'
'/~ubuntu-branches/ubuntu/natty/foo/natty',
'~ubuntu-branches/', 'ubuntu', 'natty/', 'foo')
+ self.assertPackageBranchRe(
+ 'http://bazaar.launchpad.net/+branch'
+ '/~user/ubuntu/natty/foo/test',
+ '~user/', 'ubuntu', 'natty/', 'foo')
+
+ def test_package_branch_doesnt_match(self):
+ self.assertNotPackageBranch('http://example.com/ubuntu/foo')
+ self.assertNotPackageBranch(
+ 'http://bazaar.launchpad.net/+branch/bzr')
+ self.assertNotPackageBranch(
+ 'http://bazaar.launchpad.net/+branch/~bzr-pqm/bzr/bzr.dev')
+ # Not a packaging branch because ~user isn't ~ubuntu-branches
+ self.assertNotPackageBranch(
+ 'http://bazaar.launchpad.net/+branch'
+ '/~user/ubuntu/natty/foo/natty')
+
+ def test__get_package_branch_info(self):
+ self.assertBranchInfo(
+ 'bzr+ssh://bazaar.launchpad.net/+branch/ubuntu/natty/foo',
+ 'ubuntu', 'natty', 'foo')
+ self.assertBranchInfo(
+ 'bzr+ssh://bazaar.launchpad.net/+branch'
+ '/~ubuntu-branches/ubuntu/natty/foo/natty',
+ 'ubuntu', 'natty', 'foo')
+ self.assertBranchInfo(
+ 'http://bazaar.launchpad.net/+branch'
+ '/~ubuntu-branches/debian/sid/foo/sid',
+ 'debian', 'sid', 'foo')
More information about the bazaar-commits
mailing list