/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

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

  • Committer: Martin Pool
  • Date: 2008-05-27 03:00:53 UTC
  • mfrom: (3452 +trunk)
  • mto: (3724.1.1 lock-hooks)
  • mto: This revision was merged to the branch mainline in revision 3730.
  • Revision ID: mbp@sourcefrog.net-20080527030053-0mct6dypek0ysjc3
merge trunk

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
 
36
37
 
37
38
    def test_set_rh_empty_history(self):
38
39
        branch = self.make_branch('source')
39
 
        Branch.hooks.install_hook('set_rh', self.capture_set_rh_hook)
 
40
        Branch.hooks.install_named_hook('set_rh', self.capture_set_rh_hook,
 
41
                                        None)
40
42
        branch.set_revision_history([])
41
43
        self.assertEqual(self.hook_calls,
42
44
            [('set_rh', branch, [], True)])
49
51
        tree.commit('empty commit', rev_id='foo')
50
52
        tree.unlock()
51
53
        branch = tree.branch
52
 
        Branch.hooks.install_hook('set_rh', self.capture_set_rh_hook)
 
54
        Branch.hooks.install_named_hook('set_rh', self.capture_set_rh_hook,
 
55
                                        None)
53
56
        # some branches require that their history be set to a revision in the
54
57
        # repository
55
58
        branch.set_revision_history(['f\xc2\xb5'])
58
61
 
59
62
    def test_set_rh_branch_is_locked(self):
60
63
        branch = self.make_branch('source')
61
 
        Branch.hooks.install_hook('set_rh', self.capture_set_rh_hook)
 
64
        Branch.hooks.install_named_hook('set_rh', self.capture_set_rh_hook,
 
65
                                        None)
62
66
        branch.set_revision_history([])
63
67
        self.assertEqual(self.hook_calls,
64
68
            [('set_rh', branch, [], True)])
65
69
 
66
70
    def test_set_rh_calls_all_hooks_no_errors(self):
67
71
        branch = self.make_branch('source')
68
 
        Branch.hooks.install_hook('set_rh', self.capture_set_rh_hook)
69
 
        Branch.hooks.install_hook('set_rh', self.capture_set_rh_hook)
 
72
        Branch.hooks.install_named_hook('set_rh', self.capture_set_rh_hook,
 
73
                                        None)
 
74
        Branch.hooks.install_named_hook('set_rh', self.capture_set_rh_hook,
 
75
                                        None)
70
76
        branch.set_revision_history([])
71
77
        self.assertEqual(self.hook_calls,
72
78
            [('set_rh', branch, [], True),
73
79
             ('set_rh', branch, [], True),
74
80
            ])
 
81
 
 
82
 
 
83
class TestPostChangeBranchTip(TestCaseWithMemoryTransport):
 
84
 
 
85
    def setUp(self):
 
86
        self.hook_calls = []
 
87
        TestCaseWithMemoryTransport.setUp(self)
 
88
 
 
89
    def capture_post_change_branch_tip_hook(self, params):
 
90
        """Capture post_change_branch_tip hook calls to self.hook_calls.
 
91
 
 
92
        The call is logged, as is some state of the branch.
 
93
        """
 
94
        self.hook_calls.append((params, params.branch.is_locked()))
 
95
        self.assertEquals(params.branch.last_revision_info(),
 
96
                          (params.new_revno, params.new_revid))
 
97
 
 
98
    def test_post_change_branch_tip_empty_history(self):
 
99
        branch = self.make_branch('source')
 
100
        Branch.hooks.install_named_hook(
 
101
            'post_change_branch_tip',
 
102
            self.capture_post_change_branch_tip_hook,
 
103
            None)
 
104
        branch.set_last_revision_info(0, NULL_REVISION)
 
105
        self.assertEqual(len(self.hook_calls), 1)
 
106
        self.assertEqual(self.hook_calls[0][0].branch, branch)
 
107
        self.assertEqual(self.hook_calls[0][0].old_revid, NULL_REVISION)
 
108
        self.assertEqual(self.hook_calls[0][0].old_revno, 0)
 
109
        self.assertEqual(self.hook_calls[0][0].new_revid, NULL_REVISION)
 
110
        self.assertEqual(self.hook_calls[0][0].new_revno, 0)
 
111
 
 
112
    def test_post_change_branch_tip_nonempty_history(self):
 
113
        tree = self.make_branch_and_memory_tree('source')
 
114
        tree.lock_write()
 
115
        tree.add('')
 
116
        tree.commit('another commit', rev_id='f\xc2\xb5')
 
117
        tree.commit('empty commit', rev_id='foo')
 
118
        tree.unlock()
 
119
        branch = tree.branch
 
120
        Branch.hooks.install_named_hook(
 
121
            'post_change_branch_tip',
 
122
            self.capture_post_change_branch_tip_hook,
 
123
            None)
 
124
        # some branches require that their history be set to a revision in the
 
125
        # repository
 
126
        branch.set_last_revision_info(1, 'f\xc2\xb5')
 
127
        self.assertEqual(len(self.hook_calls), 1)
 
128
        self.assertEqual(self.hook_calls[0][0].branch, branch)
 
129
        self.assertEqual(self.hook_calls[0][0].old_revid, 'foo')
 
130
        self.assertEqual(self.hook_calls[0][0].old_revno, 2)
 
131
        self.assertEqual(self.hook_calls[0][0].new_revid, 'f\xc2\xb5')
 
132
        self.assertEqual(self.hook_calls[0][0].new_revno, 1)
 
133
 
 
134
    def test_post_change_branch_tip_branch_is_locked(self):
 
135
        branch = self.make_branch('source')
 
136
        Branch.hooks.install_named_hook(
 
137
            'post_change_branch_tip',
 
138
            self.capture_post_change_branch_tip_hook,
 
139
            None)
 
140
        branch.set_last_revision_info(0, NULL_REVISION)
 
141
        self.assertEqual(len(self.hook_calls), 1)
 
142
        self.assertEqual(self.hook_calls[0][0].branch, branch)
 
143
        self.assertEqual(self.hook_calls[0][1], True)
 
144
 
 
145
    def test_post_change_branch_tip_calls_all_hooks_no_errors(self):
 
146
        branch = self.make_branch('source')
 
147
        Branch.hooks.install_named_hook(
 
148
            'post_change_branch_tip',
 
149
            self.capture_post_change_branch_tip_hook,
 
150
            None)
 
151
        Branch.hooks.install_named_hook(
 
152
            'post_change_branch_tip',
 
153
            self.capture_post_change_branch_tip_hook,
 
154
            None)
 
155
        branch.set_last_revision_info(0, NULL_REVISION)
 
156
        self.assertEqual(len(self.hook_calls), 2)
 
157
        self.assertEqual(self.hook_calls[0][0].branch, branch)
 
158
        self.assertEqual(self.hook_calls[1][0].branch, branch)