Rev 3: Update to more modern bzrlib calls. in http://people.ubuntu.com/~robertc/baz2.0/plugins/branchfeed/trunk
Robert Collins
robertc at robertcollins.net
Thu Jul 10 09:48:07 BST 2008
At http://people.ubuntu.com/~robertc/baz2.0/plugins/branchfeed/trunk
------------------------------------------------------------
revno: 3
revision-id: robertc at robertcollins.net-20080710084806-sr0rp311up6yjhe3
parent: robertc at robertcollins.net-20080710082919-1z43by0r0jjovh2g
committer: Robert Collins <robertc at robertcollins.net>
branch nick: trunk
timestamp: Thu 2008-07-10 18:48:06 +1000
message:
Update to more modern bzrlib calls.
modified:
branch_feed.py branch_feed.py-20070121145705-sx0o8hd51l0r67r1-4
tests/test_hook.py test_hook.py-20070129172729-withaw4ffooledsr-1
=== modified file 'branch_feed.py'
--- a/branch_feed.py 2007-01-29 17:50:01 +0000
+++ b/branch_feed.py 2008-07-10 08:48:06 +0000
@@ -29,7 +29,16 @@
def install_hooks():
"""Install the BranchFeed hooks into bzrlib."""
- Branch.hooks['set_rh'].append(set_rh_hook)
+ if 'post_change_branch_tip' in Branch.hooks:
+ Branch.hooks.install_named_hook('post_change_branch_tip',
+ post_change_hook, 'Creating atom feed')
+ else:
+ Branch.hooks['set_rh'].append(set_rh_hook)
+
+
+def post_change_hook(change):
+ """Update a branch's atom feed from the post_change_branch_tip hook."""
+ BranchFeed(change.branch).update()
def set_rh_hook(branch, rev_history):
=== modified file 'tests/test_hook.py'
--- a/tests/test_hook.py 2008-07-10 08:29:19 +0000
+++ b/tests/test_hook.py 2008-07-10 08:48:06 +0000
@@ -19,7 +19,7 @@
"""Tests for the hook installation."""
-from bzrlib.branch import Branch
+from bzrlib.branch import Branch, ChangeBranchTipParams
from bzrlib.tests import TestCaseWithMemoryTransport
from bzrlib.plugins.branchfeed import branch_feed
@@ -29,13 +29,30 @@
def test_set_rh_installed(self):
"""The _preserved hooks should have set_rh in them."""
- self.assertTrue(branch_feed.set_rh_hook in
- self._preserved_hooks[Branch]['set_rh'])
+ # If the bzrlib version supports post_change_branch_tip then
+ # we should not set the set_rh hook.
+ if 'post_change_branch_tip' in Branch.hooks:
+ self.assertFalse(branch_feed.set_rh_hook in
+ self._preserved_hooks[Branch]['set_rh'])
+ self.assertTrue(branch_feed.post_change_hook in
+ self._preserved_hooks[Branch]['post_change_branch_tip'])
+ else:
+ self.assertTrue(branch_feed.set_rh_hook in
+ self._preserved_hooks[Branch]['set_rh'])
+ self.assertFalse(branch_feed.post_change_hook in
+ self._preserved_hooks[Branch]['post_change_branch_tip'])
def test_install_hooks(self):
"""branch_feed.set_rh_hook should be in Branch.hooks['set_rh']."""
branch_feed.install_hooks()
- self.assertTrue(branch_feed.set_rh_hook in Branch.hooks['set_rh'])
+ if 'post_change_branch_tip' in Branch.hooks:
+ self.assertTrue(branch_feed.post_change_hook in
+ Branch.hooks['post_change_branch_tip'])
+ self.assertFalse(branch_feed.set_rh_hook in Branch.hooks['set_rh'])
+ else:
+ self.assertFalse(branch_feed.post_change_hook in
+ Branch.hooks['post_change_branch_tip'])
+ self.assertTrue(branch_feed.set_rh_hook in Branch.hooks['set_rh'])
def test_set_rh_hook(self):
"""The set_rh_hook should create a BranchFeed and call update."""
@@ -57,3 +74,25 @@
finally:
branch_feed.BranchFeed = original_class
self.assertEqual([('init', 'branch'), ('update', )], calls)
+
+ def test_post_change_hook(self):
+ """The post_change_hook should create a BranchFeed and call update."""
+ # change the BranchFeed object in the branch_feed module to test
+ # the api use.
+ calls = []
+ class SampleFeed(object):
+
+ def __init__(self, branch):
+ calls.append(('init', branch))
+
+ def update(self):
+ calls.append(('update', ))
+
+ original_class = branch_feed.BranchFeed
+ try:
+ branch_feed.BranchFeed = SampleFeed
+ change = ChangeBranchTipParams('branch', None, None, None, None)
+ branch_feed.post_change_hook(change)
+ finally:
+ branch_feed.BranchFeed = original_class
+ self.assertEqual([('init', 'branch'), ('update', )], calls)
More information about the bazaar-commits
mailing list