~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/branch_implementations/test_hooks.py

  • Committer: Aaron Bentley
  • Date: 2008-04-24 04:58:42 UTC
  • mfrom: (3377 +trunk)
  • mto: This revision was merged to the branch mainline in revision 3380.
  • Revision ID: aaron@aaronbentley.com-20080424045842-0cajl9v6s4u52kaw
Merge bzr.dev

Show diffs side-by-side

added added

removed removed

Lines of Context:
17
17
"""Tests that branch classes implement hook callouts correctly."""
18
18
 
19
19
from bzrlib.branch import Branch
 
20
from bzrlib.revision import NULL_REVISION
20
21
from bzrlib.tests import TestCaseWithMemoryTransport
21
22
 
22
23
 
72
73
            [('set_rh', branch, [], True),
73
74
             ('set_rh', branch, [], True),
74
75
            ])
 
76
 
 
77
 
 
78
class TestPostChangeBranchTip(TestCaseWithMemoryTransport):
 
79
 
 
80
    def setUp(self):
 
81
        self.hook_calls = []
 
82
        TestCaseWithMemoryTransport.setUp(self)
 
83
 
 
84
    def capture_post_change_branch_tip_hook(self, params):
 
85
        """Capture post_change_branch_tip hook calls to self.hook_calls.
 
86
 
 
87
        The call is logged, as is some state of the branch.
 
88
        """
 
89
        self.hook_calls.append((params, params.branch.is_locked()))
 
90
        self.assertEquals(params.branch.last_revision_info(),
 
91
                          (params.new_revno, params.new_revid))
 
92
 
 
93
    def test_post_change_branch_tip_empty_history(self):
 
94
        branch = self.make_branch('source')
 
95
        Branch.hooks.install_hook('post_change_branch_tip',
 
96
                                  self.capture_post_change_branch_tip_hook)
 
97
        branch.set_last_revision_info(0, NULL_REVISION)
 
98
        self.assertEqual(len(self.hook_calls), 1)
 
99
        self.assertEqual(self.hook_calls[0][0].branch, branch)
 
100
        self.assertEqual(self.hook_calls[0][0].old_revid, NULL_REVISION)
 
101
        self.assertEqual(self.hook_calls[0][0].old_revno, 0)
 
102
        self.assertEqual(self.hook_calls[0][0].new_revid, NULL_REVISION)
 
103
        self.assertEqual(self.hook_calls[0][0].new_revno, 0)
 
104
 
 
105
    def test_post_change_branch_tip_nonempty_history(self):
 
106
        tree = self.make_branch_and_memory_tree('source')
 
107
        tree.lock_write()
 
108
        tree.add('')
 
109
        tree.commit('another commit', rev_id='f\xc2\xb5')
 
110
        tree.commit('empty commit', rev_id='foo')
 
111
        tree.unlock()
 
112
        branch = tree.branch
 
113
        Branch.hooks.install_hook('post_change_branch_tip',
 
114
                                  self.capture_post_change_branch_tip_hook)
 
115
        # some branches require that their history be set to a revision in the
 
116
        # repository
 
117
        branch.set_last_revision_info(1, 'f\xc2\xb5')
 
118
        self.assertEqual(len(self.hook_calls), 1)
 
119
        self.assertEqual(self.hook_calls[0][0].branch, branch)
 
120
        self.assertEqual(self.hook_calls[0][0].old_revid, 'foo')
 
121
        self.assertEqual(self.hook_calls[0][0].old_revno, 2)
 
122
        self.assertEqual(self.hook_calls[0][0].new_revid, 'f\xc2\xb5')
 
123
        self.assertEqual(self.hook_calls[0][0].new_revno, 1)
 
124
 
 
125
    def test_post_change_branch_tip_branch_is_locked(self):
 
126
        branch = self.make_branch('source')
 
127
        Branch.hooks.install_hook('post_change_branch_tip',
 
128
                                  self.capture_post_change_branch_tip_hook)
 
129
        branch.set_last_revision_info(0, NULL_REVISION)
 
130
        self.assertEqual(len(self.hook_calls), 1)
 
131
        self.assertEqual(self.hook_calls[0][0].branch, branch)
 
132
        self.assertEqual(self.hook_calls[0][1], True)
 
133
 
 
134
    def test_post_change_branch_tip_calls_all_hooks_no_errors(self):
 
135
        branch = self.make_branch('source')
 
136
        Branch.hooks.install_hook('post_change_branch_tip',
 
137
                                  self.capture_post_change_branch_tip_hook)
 
138
        Branch.hooks.install_hook('post_change_branch_tip',
 
139
                                  self.capture_post_change_branch_tip_hook)
 
140
        branch.set_last_revision_info(0, NULL_REVISION)
 
141
        self.assertEqual(len(self.hook_calls), 2)
 
142
        self.assertEqual(self.hook_calls[0][0].branch, branch)
 
143
        self.assertEqual(self.hook_calls[1][0].branch, branch)