/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/per_branch/test_hooks.py

  • Committer: Andrew Bennetts
  • Date: 2010-04-13 04:33:55 UTC
  • mfrom: (5147 +trunk)
  • mto: This revision was merged to the branch mainline in revision 5149.
  • Revision ID: andrew.bennetts@canonical.com-20100413043355-lg3id0uwtju0k3zs
MergeĀ lp:bzr.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2007 Canonical Ltd
 
1
# Copyright (C) 2007-2010 Canonical Ltd
2
2
#
3
3
# This program is free software; you can redistribute it and/or modify
4
4
# it under the terms of the GNU General Public License as published by
12
12
#
13
13
# You should have received a copy of the GNU General Public License
14
14
# along with this program; if not, write to the Free Software
15
 
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 
15
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
16
16
 
17
17
"""Tests that branch classes implement hook callouts correctly."""
18
18
 
19
 
from bzrlib.branch import Branch, ChangeBranchTipParams
20
 
from bzrlib.errors import HookFailed, TipChangeRejected
21
 
from bzrlib.remote import RemoteBranch
22
 
from bzrlib.revision import NULL_REVISION
23
 
from bzrlib.tests import TestCaseWithMemoryTransport
24
 
 
25
 
 
26
 
class TestSetRevisionHistoryHook(TestCaseWithMemoryTransport):
 
19
from bzrlib import (
 
20
    branch as _mod_branch,
 
21
    errors,
 
22
    remote,
 
23
    revision,
 
24
    tests,
 
25
    )
 
26
from bzrlib.tests import test_server
 
27
 
 
28
class ChangeBranchTipTestCase(tests.TestCaseWithMemoryTransport):
 
29
    """Base TestCase for testing pre/post_change_branch_tip hooks."""
 
30
 
 
31
    def install_logging_hook(self, prefix):
 
32
        """Add a hook that logs calls made to it.
 
33
 
 
34
        :returns: the list that the calls will be appended to.
 
35
        """
 
36
        hook_calls = []
 
37
        _mod_branch.Branch.hooks.install_named_hook(
 
38
            prefix + '_change_branch_tip', hook_calls.append, None)
 
39
        return hook_calls
 
40
 
 
41
    def make_branch_with_revision_ids(self, *revision_ids):
 
42
        """Makes a branch with the given commits."""
 
43
        tree = self.make_branch_and_memory_tree('source')
 
44
        tree.lock_write()
 
45
        tree.add('')
 
46
        for revision_id in revision_ids:
 
47
            tree.commit(u'Message of ' + revision_id.decode('utf8'),
 
48
                        rev_id=revision_id)
 
49
        tree.unlock()
 
50
        branch = tree.branch
 
51
        return branch
 
52
 
 
53
    def assertHookCalls(self, expected_params, branch, hook_calls=None,
 
54
        pre=False):
 
55
        if hook_calls is None:
 
56
            hook_calls = self.hook_calls
 
57
        if isinstance(branch, remote.RemoteBranch):
 
58
            # For a remote branch, both the server and the client will raise
 
59
            # this hook, and we see both in the test environment. The remote
 
60
            # instance comes in between the clients - the client doe pre, the
 
61
            # server does pre, the server does post, the client does post.
 
62
            if pre:
 
63
                offset = 0
 
64
            else:
 
65
                offset = 1
 
66
            self.assertEqual(expected_params, hook_calls[offset])
 
67
            self.assertEqual(2, len(hook_calls))
 
68
        else:
 
69
            self.assertEqual([expected_params], hook_calls)
 
70
 
 
71
 
 
72
class TestSetRevisionHistoryHook(ChangeBranchTipTestCase):
27
73
 
28
74
    def setUp(self):
29
75
        self.hook_calls = []
30
 
        TestCaseWithMemoryTransport.setUp(self)
 
76
        super(TestSetRevisionHistoryHook, self).setUp()
31
77
 
32
78
    def capture_set_rh_hook(self, branch, rev_history):
33
79
        """Capture post set-rh hook calls to self.hook_calls.
34
 
        
 
80
 
35
81
        The call is logged, as is some state of the branch.
36
82
        """
37
83
        self.hook_calls.append(
39
85
 
40
86
    def test_set_rh_empty_history(self):
41
87
        branch = self.make_branch('source')
42
 
        Branch.hooks.install_named_hook('set_rh', self.capture_set_rh_hook,
43
 
                                        None)
 
88
        _mod_branch.Branch.hooks.install_named_hook(
 
89
            'set_rh', self.capture_set_rh_hook, None)
44
90
        branch.set_revision_history([])
45
 
        self.assertEqual(self.hook_calls,
46
 
            [('set_rh', branch, [], True)])
 
91
        expected_params = ('set_rh', branch, [], True)
 
92
        self.assertHookCalls(expected_params, branch)
47
93
 
48
94
    def test_set_rh_nonempty_history(self):
49
95
        tree = self.make_branch_and_memory_tree('source')
53
99
        tree.commit('empty commit', rev_id='foo')
54
100
        tree.unlock()
55
101
        branch = tree.branch
56
 
        Branch.hooks.install_named_hook('set_rh', self.capture_set_rh_hook,
57
 
                                        None)
 
102
        _mod_branch.Branch.hooks.install_named_hook(
 
103
            'set_rh', self.capture_set_rh_hook, None)
58
104
        # some branches require that their history be set to a revision in the
59
105
        # repository
60
106
        branch.set_revision_history(['f\xc2\xb5'])
61
 
        self.assertEqual(self.hook_calls,
62
 
            [('set_rh', branch, ['f\xc2\xb5'], True)])
 
107
        expected_params =('set_rh', branch, ['f\xc2\xb5'], True)
 
108
        self.assertHookCalls(expected_params, branch)
63
109
 
64
110
    def test_set_rh_branch_is_locked(self):
65
111
        branch = self.make_branch('source')
66
 
        Branch.hooks.install_named_hook('set_rh', self.capture_set_rh_hook,
67
 
                                        None)
 
112
        _mod_branch.Branch.hooks.install_named_hook(
 
113
            'set_rh', self.capture_set_rh_hook, None)
68
114
        branch.set_revision_history([])
69
 
        self.assertEqual(self.hook_calls,
70
 
            [('set_rh', branch, [], True)])
 
115
        expected_params = ('set_rh', branch, [], True)
 
116
        self.assertHookCalls(expected_params, branch)
71
117
 
72
118
    def test_set_rh_calls_all_hooks_no_errors(self):
73
119
        branch = self.make_branch('source')
74
 
        Branch.hooks.install_named_hook('set_rh', self.capture_set_rh_hook,
75
 
                                        None)
76
 
        Branch.hooks.install_named_hook('set_rh', self.capture_set_rh_hook,
77
 
                                        None)
 
120
        _mod_branch.Branch.hooks.install_named_hook(
 
121
            'set_rh', self.capture_set_rh_hook, None)
 
122
        _mod_branch.Branch.hooks.install_named_hook(
 
123
            'set_rh', self.capture_set_rh_hook, None)
78
124
        branch.set_revision_history([])
79
 
        self.assertEqual(self.hook_calls,
80
 
            [('set_rh', branch, [], True),
81
 
             ('set_rh', branch, [], True),
82
 
            ])
83
 
 
84
 
 
85
 
class ChangeBranchTipTestCase(TestCaseWithMemoryTransport):
86
 
    """Base TestCase for testing pre/post_change_branch_tip hooks."""
87
 
 
88
 
    def install_logging_hook(self, prefix):
89
 
        """Add a hook that logs calls made to it.
90
 
        
91
 
        :returns: the list that the calls will be appended to.
92
 
        """
93
 
        hook_calls = []
94
 
        Branch.hooks.install_named_hook(
95
 
            prefix + '_change_branch_tip', hook_calls.append, None)
96
 
        return hook_calls
97
 
 
98
 
    def make_branch_with_revision_ids(self, *revision_ids):
99
 
        """Makes a branch with the given commits."""
100
 
        tree = self.make_branch_and_memory_tree('source')
101
 
        tree.lock_write()
102
 
        tree.add('')
103
 
        for revision_id in revision_ids:
104
 
            tree.commit(u'Message of ' + revision_id.decode('utf8'),
105
 
                        rev_id=revision_id)
106
 
        tree.unlock()
107
 
        branch = tree.branch
108
 
        return branch
109
 
 
110
 
 
111
 
class TestOpen(TestCaseWithMemoryTransport):
 
125
        expected_calls = [('set_rh', branch, [], True),
 
126
            ('set_rh', branch, [], True),
 
127
            ]
 
128
        if isinstance(branch, remote.RemoteBranch):
 
129
            # For a remote branch, both the server and the client will raise
 
130
            # set_rh, and the server will do so first because that is where
 
131
            # the change takes place.
 
132
            self.assertEqual(expected_calls, self.hook_calls[2:])
 
133
            self.assertEqual(4, len(self.hook_calls))
 
134
        else:
 
135
            self.assertEqual(expected_calls, self.hook_calls)
 
136
 
 
137
 
 
138
class TestOpen(tests.TestCaseWithMemoryTransport):
112
139
 
113
140
    def capture_hook(self, branch):
114
141
        self.hook_calls.append(branch)
115
142
 
116
143
    def install_hook(self):
117
144
        self.hook_calls = []
118
 
        Branch.hooks.install_named_hook('open', self.capture_hook, None)
 
145
        _mod_branch.Branch.hooks.install_named_hook(
 
146
            'open', self.capture_hook, None)
119
147
 
120
148
    def test_create(self):
121
149
        self.install_hook()
122
150
        b = self.make_branch('.')
123
 
        self.assertEqual([b], self.hook_calls)
 
151
        if isinstance(b, remote.RemoteBranch):
 
152
            # RemoteBranch creation:
 
153
            if (self.transport_readonly_server
 
154
                == test_server.ReadonlySmartTCPServer_for_testing_v2_only):
 
155
                # Older servers:
 
156
                self.assertEqual(3, len(self.hook_calls))
 
157
                # creates the branch via the VFS (for older servers)
 
158
                self.assertEqual(b._real_branch, self.hook_calls[0])
 
159
                # creates a RemoteBranch object
 
160
                self.assertEqual(b, self.hook_calls[1])
 
161
                # get_stacked_on_url RPC
 
162
                self.assertRealBranch(self.hook_calls[2])
 
163
            else:
 
164
                self.assertEqual(2, len(self.hook_calls))
 
165
                # create_branch RPC
 
166
                self.assertRealBranch(self.hook_calls[0])
 
167
                # create RemoteBranch locally
 
168
                self.assertEqual(b, self.hook_calls[1])
 
169
        else:
 
170
            self.assertEqual([b], self.hook_calls)
124
171
 
125
172
    def test_open(self):
126
173
        branch_url = self.make_branch('.').bzrdir.root_transport.base
127
174
        self.install_hook()
128
 
        b = Branch.open(branch_url)
129
 
        if isinstance(b, RemoteBranch):
130
 
            # RemoteBranch open always opens the backing branch to get stacking
131
 
            # details. As that is done remotely we can't see the branch object
132
 
            # nor even compare base url's etc. So we just assert that the first
133
 
            # branch returned is the RemoteBranch, and that the second is a
134
 
            # Branch but not a RemoteBranch.
135
 
            self.assertEqual(2, len(self.hook_calls))
136
 
            self.assertEqual(b, self.hook_calls[0])
137
 
            self.assertIsInstance(self.hook_calls[1], Branch)
138
 
            self.assertFalse(isinstance(self.hook_calls[1], RemoteBranch))
 
175
        b = _mod_branch.Branch.open(branch_url)
 
176
        if isinstance(b, remote.RemoteBranch):
 
177
            self.assertEqual(3, len(self.hook_calls))
 
178
            # open_branchV2 RPC
 
179
            self.assertRealBranch(self.hook_calls[0])
 
180
            # create RemoteBranch locally
 
181
            self.assertEqual(b, self.hook_calls[1])
 
182
            # get_stacked_on_url RPC
 
183
            self.assertRealBranch(self.hook_calls[2])
139
184
        else:
140
185
            self.assertEqual([b], self.hook_calls)
141
186
 
 
187
    def assertRealBranch(self, b):
 
188
        # Branches opened on the server don't have comparable URLs, so we just
 
189
        # assert that it is not a RemoteBranch.
 
190
        self.assertIsInstance(b, _mod_branch.Branch)
 
191
        self.assertFalse(isinstance(b, remote.RemoteBranch))
 
192
 
142
193
 
143
194
class TestPreChangeBranchTip(ChangeBranchTipTestCase):
144
195
    """Tests for pre_change_branch_tip hook.
145
 
    
 
196
 
146
197
    Most of these tests are very similar to the tests in
147
198
    TestPostChangeBranchTip.
148
199
    """
154
205
        def assertBranchAtRevision1(params):
155
206
            self.assertEquals(
156
207
                (1, 'revid-one'), params.branch.last_revision_info())
157
 
        Branch.hooks.install_named_hook(
 
208
        _mod_branch.Branch.hooks.install_named_hook(
158
209
            'pre_change_branch_tip', assertBranchAtRevision1, None)
159
 
        branch.set_last_revision_info(0, NULL_REVISION)
 
210
        branch.set_last_revision_info(0, revision.NULL_REVISION)
160
211
 
161
212
    def test_hook_failure_prevents_change(self):
162
 
        """If a hook raises an exception, the change does not take effect.
163
 
        
164
 
        Also, a HookFailed exception will be raised.
165
 
        """
 
213
        """If a hook raises an exception, the change does not take effect."""
166
214
        branch = self.make_branch_with_revision_ids(
167
215
            'one-\xc2\xb5', 'two-\xc2\xb5')
168
216
        class PearShapedError(Exception):
169
217
            pass
170
218
        def hook_that_raises(params):
171
219
            raise PearShapedError()
172
 
        Branch.hooks.install_named_hook(
 
220
        _mod_branch.Branch.hooks.install_named_hook(
173
221
            'pre_change_branch_tip', hook_that_raises, None)
174
222
        hook_failed_exc = self.assertRaises(
175
 
            HookFailed, branch.set_last_revision_info, 0, NULL_REVISION)
176
 
        self.assertIsInstance(hook_failed_exc.exc_value, PearShapedError)
 
223
            PearShapedError,
 
224
            branch.set_last_revision_info, 0, revision.NULL_REVISION)
177
225
        # The revision info is unchanged.
178
226
        self.assertEqual((2, 'two-\xc2\xb5'), branch.last_revision_info())
179
 
        
 
227
 
180
228
    def test_empty_history(self):
181
229
        branch = self.make_branch('source')
182
230
        hook_calls = self.install_logging_hook('pre')
183
 
        branch.set_last_revision_info(0, NULL_REVISION)
184
 
        expected_params = ChangeBranchTipParams(
185
 
            branch, 0, 0, NULL_REVISION, NULL_REVISION)
186
 
        self.assertEqual([expected_params], hook_calls)
 
231
        branch.set_last_revision_info(0, revision.NULL_REVISION)
 
232
        expected_params = _mod_branch.ChangeBranchTipParams(
 
233
            branch, 0, 0, revision.NULL_REVISION, revision.NULL_REVISION)
 
234
        self.assertHookCalls(expected_params, branch, hook_calls, pre=True)
187
235
 
188
236
    def test_nonempty_history(self):
189
237
        # some branches require that their history be set to a revision in the
193
241
            'one-\xc2\xb5', 'two-\xc2\xb5')
194
242
        hook_calls = self.install_logging_hook('pre')
195
243
        branch.set_last_revision_info(1, 'one-\xc2\xb5')
196
 
        expected_params = ChangeBranchTipParams(
 
244
        expected_params = _mod_branch.ChangeBranchTipParams(
197
245
            branch, 2, 1, 'two-\xc2\xb5', 'one-\xc2\xb5')
198
 
        self.assertEqual([expected_params], hook_calls)
 
246
        self.assertHookCalls(expected_params, branch, hook_calls, pre=True)
199
247
 
200
248
    def test_branch_is_locked(self):
201
249
        branch = self.make_branch('source')
202
250
        def assertBranchIsLocked(params):
203
251
            self.assertTrue(params.branch.is_locked())
204
 
        Branch.hooks.install_named_hook(
 
252
        _mod_branch.Branch.hooks.install_named_hook(
205
253
            'pre_change_branch_tip', assertBranchIsLocked, None)
206
 
        branch.set_last_revision_info(0, NULL_REVISION)
 
254
        branch.set_last_revision_info(0, revision.NULL_REVISION)
207
255
 
208
256
    def test_calls_all_hooks_no_errors(self):
209
257
        """If multiple hooks are registered, all are called (if none raise
213
261
        hook_calls_1 = self.install_logging_hook('pre')
214
262
        hook_calls_2 = self.install_logging_hook('pre')
215
263
        self.assertIsNot(hook_calls_1, hook_calls_2)
216
 
        branch.set_last_revision_info(0, NULL_REVISION)
 
264
        branch.set_last_revision_info(0, revision.NULL_REVISION)
217
265
        # Both hooks are called.
218
 
        self.assertEqual(len(hook_calls_1), 1)
219
 
        self.assertEqual(len(hook_calls_2), 1)
 
266
        if isinstance(branch, remote.RemoteBranch):
 
267
            count = 2
 
268
        else:
 
269
            count = 1
 
270
        self.assertEqual(len(hook_calls_1), count)
 
271
        self.assertEqual(len(hook_calls_2), count)
220
272
 
221
273
    def test_explicit_reject_by_hook(self):
222
274
        """If a hook raises TipChangeRejected, the change does not take effect.
223
 
        
 
275
 
224
276
        TipChangeRejected exceptions are propagated, not wrapped in HookFailed.
225
277
        """
226
278
        branch = self.make_branch_with_revision_ids(
227
279
            'one-\xc2\xb5', 'two-\xc2\xb5')
228
280
        def hook_that_rejects(params):
229
 
            raise TipChangeRejected('rejection message')
230
 
        Branch.hooks.install_named_hook(
 
281
            raise errors.TipChangeRejected('rejection message')
 
282
        _mod_branch.Branch.hooks.install_named_hook(
231
283
            'pre_change_branch_tip', hook_that_rejects, None)
232
284
        self.assertRaises(
233
 
            TipChangeRejected, branch.set_last_revision_info, 0, NULL_REVISION)
 
285
            errors.TipChangeRejected,
 
286
            branch.set_last_revision_info, 0, revision.NULL_REVISION)
234
287
        # The revision info is unchanged.
235
288
        self.assertEqual((2, 'two-\xc2\xb5'), branch.last_revision_info())
236
 
        
 
289
 
237
290
 
238
291
class TestPostChangeBranchTip(ChangeBranchTipTestCase):
239
292
    """Tests for post_change_branch_tip hook.
248
301
        branch = self.make_branch_with_revision_ids('revid-one')
249
302
        def assertBranchAtRevision1(params):
250
303
            self.assertEquals(
251
 
                (0, NULL_REVISION), params.branch.last_revision_info())
252
 
        Branch.hooks.install_named_hook(
 
304
                (0, revision.NULL_REVISION), params.branch.last_revision_info())
 
305
        _mod_branch.Branch.hooks.install_named_hook(
253
306
            'post_change_branch_tip', assertBranchAtRevision1, None)
254
 
        branch.set_last_revision_info(0, NULL_REVISION)
 
307
        branch.set_last_revision_info(0, revision.NULL_REVISION)
255
308
 
256
309
    def test_empty_history(self):
257
310
        branch = self.make_branch('source')
258
311
        hook_calls = self.install_logging_hook('post')
259
 
        branch.set_last_revision_info(0, NULL_REVISION)
260
 
        expected_params = ChangeBranchTipParams(
261
 
            branch, 0, 0, NULL_REVISION, NULL_REVISION)
262
 
        self.assertEqual([expected_params], hook_calls)
 
312
        branch.set_last_revision_info(0, revision.NULL_REVISION)
 
313
        expected_params = _mod_branch.ChangeBranchTipParams(
 
314
            branch, 0, 0, revision.NULL_REVISION, revision.NULL_REVISION)
 
315
        self.assertHookCalls(expected_params, branch, hook_calls)
263
316
 
264
317
    def test_nonempty_history(self):
265
318
        # some branches require that their history be set to a revision in the
269
322
            'one-\xc2\xb5', 'two-\xc2\xb5')
270
323
        hook_calls = self.install_logging_hook('post')
271
324
        branch.set_last_revision_info(1, 'one-\xc2\xb5')
272
 
        expected_params = ChangeBranchTipParams(
 
325
        expected_params = _mod_branch.ChangeBranchTipParams(
273
326
            branch, 2, 1, 'two-\xc2\xb5', 'one-\xc2\xb5')
274
 
        self.assertEqual([expected_params], hook_calls)
 
327
        self.assertHookCalls(expected_params, branch, hook_calls)
275
328
 
276
329
    def test_branch_is_locked(self):
277
330
        """The branch passed to the hook is locked."""
278
331
        branch = self.make_branch('source')
279
332
        def assertBranchIsLocked(params):
280
333
            self.assertTrue(params.branch.is_locked())
281
 
        Branch.hooks.install_named_hook(
 
334
        _mod_branch.Branch.hooks.install_named_hook(
282
335
            'post_change_branch_tip', assertBranchIsLocked, None)
283
 
        branch.set_last_revision_info(0, NULL_REVISION)
 
336
        branch.set_last_revision_info(0, revision.NULL_REVISION)
284
337
 
285
338
    def test_calls_all_hooks_no_errors(self):
286
339
        """If multiple hooks are registered, all are called (if none raise
290
343
        hook_calls_1 = self.install_logging_hook('post')
291
344
        hook_calls_2 = self.install_logging_hook('post')
292
345
        self.assertIsNot(hook_calls_1, hook_calls_2)
293
 
        branch.set_last_revision_info(0, NULL_REVISION)
 
346
        branch.set_last_revision_info(0, revision.NULL_REVISION)
294
347
        # Both hooks are called.
295
 
        self.assertEqual(len(hook_calls_1), 1)
296
 
        self.assertEqual(len(hook_calls_2), 1)
 
348
        if isinstance(branch, remote.RemoteBranch):
 
349
            count = 2
 
350
        else:
 
351
            count = 1
 
352
        self.assertEqual(len(hook_calls_1), count)
 
353
        self.assertEqual(len(hook_calls_2), count)
297
354
 
298
355
 
299
356
class TestAllMethodsThatChangeTipWillRunHooks(ChangeBranchTipTestCase):
304
361
    def setUp(self):
305
362
        ChangeBranchTipTestCase.setUp(self)
306
363
        self.installPreAndPostHooks()
307
 
        
 
364
 
308
365
    def installPreAndPostHooks(self):
309
366
        self.pre_hook_calls = self.install_logging_hook('pre')
310
367
        self.post_hook_calls = self.install_logging_hook('post')
312
369
    def resetHookCalls(self):
313
370
        del self.pre_hook_calls[:], self.post_hook_calls[:]
314
371
 
315
 
    def assertPreAndPostHooksWereInvoked(self):
316
 
        # Check for len == 1, because the hooks should only be be invoked once
317
 
        # by an operation.
318
 
        self.assertEqual(1, len(self.pre_hook_calls))
319
 
        self.assertEqual(1, len(self.post_hook_calls))
 
372
    def assertPreAndPostHooksWereInvoked(self, branch, smart_enabled):
 
373
        """assert that both pre and post hooks were called
 
374
 
 
375
        :param smart_enabled: The method invoked is one that should be
 
376
            smart server ready.
 
377
        """
 
378
        # Check for the number of invocations expected. One invocation is
 
379
        # local, one is remote (if the branch is remote).
 
380
        if smart_enabled and isinstance(branch, remote.RemoteBranch):
 
381
            length = 2
 
382
        else:
 
383
            length = 1
 
384
        self.assertEqual(length, len(self.pre_hook_calls))
 
385
        self.assertEqual(length, len(self.post_hook_calls))
320
386
 
321
387
    def test_set_revision_history(self):
322
388
        branch = self.make_branch('')
323
389
        branch.set_revision_history([])
324
 
        self.assertPreAndPostHooksWereInvoked()
 
390
        self.assertPreAndPostHooksWereInvoked(branch, True)
325
391
 
326
392
    def test_set_last_revision_info(self):
327
393
        branch = self.make_branch('')
328
 
        branch.set_last_revision_info(0, NULL_REVISION)
329
 
        self.assertPreAndPostHooksWereInvoked()
 
394
        branch.set_last_revision_info(0, revision.NULL_REVISION)
 
395
        self.assertPreAndPostHooksWereInvoked(branch, True)
330
396
 
331
397
    def test_generate_revision_history(self):
332
398
        branch = self.make_branch('')
333
 
        branch.generate_revision_history(NULL_REVISION)
334
 
        self.assertPreAndPostHooksWereInvoked()
 
399
        branch.generate_revision_history(revision.NULL_REVISION)
 
400
        # NB: for HPSS protocols < v3, the server does not invoke branch tip
 
401
        # change events on generate_revision_history, as the change is done
 
402
        # directly by the client over the VFS.
 
403
        self.assertPreAndPostHooksWereInvoked(branch, True)
335
404
 
336
405
    def test_pull(self):
337
406
        source_branch = self.make_branch_with_revision_ids('rev-1', 'rev-2')
338
407
        self.resetHookCalls()
339
408
        destination_branch = self.make_branch('destination')
340
409
        destination_branch.pull(source_branch)
341
 
        self.assertPreAndPostHooksWereInvoked()
 
410
        self.assertPreAndPostHooksWereInvoked(destination_branch, False)
342
411
 
343
412
    def test_push(self):
344
413
        source_branch = self.make_branch_with_revision_ids('rev-1', 'rev-2')
345
414
        self.resetHookCalls()
346
415
        destination_branch = self.make_branch('destination')
347
416
        source_branch.push(destination_branch)
348
 
        self.assertPreAndPostHooksWereInvoked()
349
 
 
350
 
        
 
417
        self.assertPreAndPostHooksWereInvoked(destination_branch, True)