Rev 6035: More refactoring. in http://bazaar.launchpad.net/~jameinel/bzr/2.5-verbosity-knob-812928
John Arbash Meinel
john at arbash-meinel.com
Fri Jul 22 11:54:46 UTC 2011
At http://bazaar.launchpad.net/~jameinel/bzr/2.5-verbosity-knob-812928
------------------------------------------------------------
revno: 6035
revision-id: john at arbash-meinel.com-20110722115425-biyy7aioy3zxrihe
parent: john at arbash-meinel.com-20110722105928-ucxdvw8vcidnh4iu
committer: John Arbash Meinel <john at arbash-meinel.com>
branch nick: 2.5-verbosity-knob-812928
timestamp: Fri 2011-07-22 13:54:25 +0200
message:
More refactoring.
Rewrite the tests to focus on extracting the content vs reporting the content,
and then rewrite to focus on the permutations that matter.
I think we actually have more tests now, because display tests still
need to test all the permutations, and now we add a couple more for
getting the data out of the branch.
Though the display tests do run faster...
-------------- next part --------------
=== modified file 'bzrlib/plugins/launchpad/lp_api_lite.py'
--- a/bzrlib/plugins/launchpad/lp_api_lite.py 2011-07-22 10:59:28 +0000
+++ b/bzrlib/plugins/launchpad/lp_api_lite.py 2011-07-22 11:54:25 +0000
@@ -205,13 +205,13 @@
the_branch.unlock()
-def _check_freshness(the_branch, latest_pub):
+def _get_newest_versions(the_branch, latest_pub):
"""Get information about how 'fresh' this packaging branch is.
:param the_branch: The Branch to check
:param latest_pub: The LatestPublication used to check most recent
published version.
- :return: (tags, latest_ver)
+ :return: (latest_ver, branch_latest_ver)
"""
t = time.time()
latest_ver = latest_pub.get_latest_version()
@@ -219,15 +219,20 @@
trace.mutter('LatestPublication.get_latest_version took: %.3fs'
% (t_latest_ver,))
if latest_ver is None:
- return None, {}
+ return None, None
t = time.time()
tags = the_branch.tags.get_tag_dict()
t_tag_dict = time.time() - t
trace.mutter('LatestPublication.get_tag_dict took: %.3fs' % (t_tag_dict,))
- return latest_ver, tags
-
-
-def _report_freshness(the_branch, tags, latest_ver, place, verbosity):
+ if latest_ver in tags:
+ # branch might have a newer tag, but we don't really care
+ return latest_ver, latest_ver
+ else:
+ best_tag = get_most_recent_tag(tags, the_branch)
+ return latest_ver, best_tag
+
+
+def _report_freshness(latest_ver, branch_latest_ver, place, verbosity):
"""Report if the branch is up-to-date."""
if latest_ver is None:
if verbosity == 'all':
@@ -235,7 +240,7 @@
elif verbosity == 'short':
trace.note('%s is MISSING a version' % (place,))
return
- if latest_ver in tags:
+ elif latest_ver == branch_latest_ver:
if verbosity == 'minimal':
return
elif verbosity == 'short':
@@ -245,17 +250,16 @@
'Packaging branch status: CURRENT'
% (place, latest_ver))
else:
- best_tag = get_most_recent_tag(tags, the_branch)
if verbosity in ('minimal', 'short'):
- if best_tag is None:
- best_tag = 'Branch'
+ if branch_latest_ver is None:
+ branch_latest_ver = 'Branch'
trace.warning('%s is OUT-OF-DATE, %s has %s'
- % (best_tag, place, latest_ver))
+ % (branch_latest_ver, place, latest_ver))
else:
trace.warning('Most recent %s version: %s\n'
'Packaging branch version: %s\n'
'Packaging branch status: OUT-OF-DATE'
- % (place, latest_ver, best_tag))
+ % (place, latest_ver, branch_latest_ver))
def report_freshness(the_branch, verbosity, latest_pub):
@@ -275,6 +279,6 @@
return
if verbosity is None:
verbosity = 'all'
- latest_ver, tags = _check_freshness(the_branch, latest_pub)
+ latest_ver, branch_ver = _get_newest_versions(the_branch, latest_pub)
place = latest_pub.place()
- _report_freshness(the_branch, tags, latest_ver, place, verbosity)
+ _report_freshness(latest_ver, branch_ver, place, verbosity)
=== modified file 'bzrlib/plugins/launchpad/test_lp_api_lite.py'
--- a/bzrlib/plugins/launchpad/test_lp_api_lite.py 2011-07-22 10:59:28 +0000
+++ b/bzrlib/plugins/launchpad/test_lp_api_lite.py 2011-07-22 11:54:25 +0000
@@ -433,68 +433,117 @@
lp_api_lite.report_freshness(self.branch, 'off', latest_pub)
self.assertFalse(latest_pub.called)
+ def test_verbosity_all_out_of_date_smoke(self):
+ self.branch.tags.set_tag('1.0-1ubuntu1', 'A')
+ self.assertFreshnessReports('all', '1.0-1ubuntu2',
+ ' WARNING Most recent Ubuntu Natty version: 1.0-1ubuntu2\n'
+ 'Packaging branch version: 1.0-1ubuntu1\n'
+ 'Packaging branch status: OUT-OF-DATE\n')
+
+class Test_GetNewestVersions(tests.TestCaseWithMemoryTransport):
+
+ def setUp(self):
+ super(Test_GetNewestVersions, self).setUp()
+ builder = self.make_branch_builder('tip')
+ builder.build_snapshot('A', [], [
+ ('add', ('', 'root-id', 'directory', None))])
+ self.branch = builder.get_branch()
+
+ def assertLatestVersions(self, latest_branch_version, pub_version):
+ if latest_branch_version is not None:
+ self.branch.tags.set_tag(latest_branch_version, 'A')
+ latest_pub = StubLatestPublication(pub_version)
+ self.assertEqual((pub_version, latest_branch_version),
+ lp_api_lite._get_newest_versions(self.branch, latest_pub))
+
+ def test_no_tags(self):
+ self.assertLatestVersions(None, '1.0-1ubuntu2')
+
+ def test_out_of_date(self):
+ self.assertLatestVersions('1.0-1ubuntu1', '1.0-1ubuntu2')
+
+ def test_up_to_date(self):
+ self.assertLatestVersions('1.0-1ubuntu2', '1.0-1ubuntu2')
+
+ def test_missing(self):
+ self.assertLatestVersions(None, None)
+
+
+class Test_ReportFreshness(tests.TestCase):
+
+ def assertReportedFreshness(self, verbosity, latest_ver, branch_latest_ver,
+ content, place='Ubuntu Natty'):
+ """Assert that lp_api_lite.report_freshness reports the given content.
+ """
+ orig_log_len = len(self.get_log())
+ lp_api_lite._report_freshness(latest_ver, branch_latest_ver, place,
+ verbosity)
+ new_content = self.get_log()[orig_log_len:]
+ # Strip out lines that have LatestPublication.get_* because those are
+ # timing related lines. While interesting to log for now, they aren't
+ # something we want to be testing
+ new_content = new_content.split('\n')
+ for i in range(2):
+ if (len(new_content) > 0
+ and 'LatestPublication.get_' in new_content[0]):
+ new_content = new_content[1:]
+ new_content = '\n'.join(new_content)
+ self.assertThat(new_content,
+ DocTestMatches(content,
+ doctest.ELLIPSIS | doctest.REPORT_UDIFF))
+
def test_verbosity_minimal_no_tags(self):
- self.assertFreshnessReports('minimal', '1.0-1ubuntu2',
+ self.assertReportedFreshness('minimal', '1.0-1ubuntu2', None,
' WARNING Branch is OUT-OF-DATE, Ubuntu Natty has 1.0-1ubuntu2\n')
def test_verbosity_minimal_out_of_date(self):
- self.branch.tags.set_tag('1.0-1ubuntu1', 'A')
- self.assertFreshnessReports('minimal', '1.0-1ubuntu2',
+ self.assertReportedFreshness('minimal', '1.0-1ubuntu2', '1.0-1ubuntu1',
' WARNING 1.0-1ubuntu1 is OUT-OF-DATE,'
' Ubuntu Natty has 1.0-1ubuntu2\n')
def test_verbosity_minimal_up_to_date(self):
- self.branch.tags.set_tag('1.0-1ubuntu2', 'A')
- self.assertFreshnessReports('minimal', '1.0-1ubuntu2',
+ self.assertReportedFreshness('minimal', '1.0-1ubuntu2', '1.0-1ubuntu2',
'')
def test_verbosity_minimal_missing(self):
- self.branch.tags.set_tag('1.0-1ubuntu2', 'A')
- self.assertFreshnessReports('minimal', None,
+ self.assertReportedFreshness('minimal', None, None,
'')
def test_verbosity_short_out_of_date(self):
- self.branch.tags.set_tag('1.0-1ubuntu1', 'A')
- self.assertFreshnessReports('short', '1.0-1ubuntu2',
+ self.assertReportedFreshness('short', '1.0-1ubuntu2', '1.0-1ubuntu1',
' WARNING 1.0-1ubuntu1 is OUT-OF-DATE,'
' Ubuntu Natty has 1.0-1ubuntu2\n')
def test_verbosity_short_up_to_date(self):
- self.branch.tags.set_tag('1.0-1ubuntu2', 'A')
- self.assertFreshnessReports('short', '1.0-1ubuntu2',
+ self.assertReportedFreshness('short', '1.0-1ubuntu2', '1.0-1ubuntu2',
' INFO 1.0-1ubuntu2 is CURRENT in Ubuntu Natty')
def test_verbosity_short_missing(self):
- self.branch.tags.set_tag('1.0-1ubuntu2', 'A')
- self.assertFreshnessReports('short', None,
+ self.assertReportedFreshness('short', None, None,
' INFO Ubuntu Natty is MISSING a version')
def test_verbosity_all_no_tags(self):
- self.assertFreshnessReports('all', '1.0-1ubuntu2',
+ self.assertReportedFreshness('all', '1.0-1ubuntu2', None,
' WARNING Most recent Ubuntu Natty version: 1.0-1ubuntu2\n'
'Packaging branch version: None\n'
'Packaging branch status: OUT-OF-DATE\n')
def test_verbosity_all_out_of_date(self):
- self.branch.tags.set_tag('1.0-1ubuntu1', 'A')
- self.assertFreshnessReports('all', '1.0-1ubuntu2',
+ self.assertReportedFreshness('all', '1.0-1ubuntu2', '1.0-1ubuntu1',
' WARNING Most recent Ubuntu Natty version: 1.0-1ubuntu2\n'
'Packaging branch version: 1.0-1ubuntu1\n'
'Packaging branch status: OUT-OF-DATE\n')
def test_verbosity_all_up_to_date(self):
- self.branch.tags.set_tag('1.0-1ubuntu2', 'A')
- self.assertFreshnessReports('all', '1.0-1ubuntu2',
+ self.assertReportedFreshness('all', '1.0-1ubuntu2', '1.0-1ubuntu2',
' INFO Most recent Ubuntu Natty version: 1.0-1ubuntu2\n'
'Packaging branch status: CURRENT\n')
def test_verbosity_all_missing(self):
- self.branch.tags.set_tag('1.0-1ubuntu2', 'A')
- self.assertFreshnessReports('all', None,
+ self.assertReportedFreshness('all', None, None,
' INFO Most recent Ubuntu Natty version: MISSING\n')
def test_verbosity_None_is_all(self):
- self.branch.tags.set_tag('1.0-1ubuntu2', 'A')
- self.assertFreshnessReports(None, '1.0-1ubuntu2',
+ self.assertReportedFreshness(None, '1.0-1ubuntu2', '1.0-1ubuntu2',
' INFO Most recent Ubuntu Natty version: 1.0-1ubuntu2\n'
'Packaging branch status: CURRENT\n')
More information about the bazaar-commits
mailing list