~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

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

  • Committer: Andrew Bennetts
  • Date: 2010-10-08 08:15:14 UTC
  • mto: This revision was merged to the branch mainline in revision 5498.
  • Revision ID: andrew.bennetts@canonical.com-20101008081514-dviqzrdfwyzsqbz2
Split NEWS into per-release doc/en/release-notes/bzr-*.txt

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2007-2012, 2016 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
23
23
    revision,
24
24
    tests,
25
25
    )
26
 
from bzrlib.symbol_versioning import deprecated_in
27
26
from bzrlib.tests import test_server
28
27
 
29
28
class ChangeBranchTipTestCase(tests.TestCaseWithMemoryTransport):
70
69
            self.assertEqual([expected_params], hook_calls)
71
70
 
72
71
 
 
72
class TestSetRevisionHistoryHook(ChangeBranchTipTestCase):
 
73
 
 
74
    def setUp(self):
 
75
        self.hook_calls = []
 
76
        super(TestSetRevisionHistoryHook, self).setUp()
 
77
 
 
78
    def capture_set_rh_hook(self, branch, rev_history):
 
79
        """Capture post set-rh hook calls to self.hook_calls.
 
80
 
 
81
        The call is logged, as is some state of the branch.
 
82
        """
 
83
        self.hook_calls.append(
 
84
            ('set_rh', branch, rev_history, branch.is_locked()))
 
85
 
 
86
    def test_set_rh_empty_history(self):
 
87
        branch = self.make_branch('source')
 
88
        _mod_branch.Branch.hooks.install_named_hook(
 
89
            'set_rh', self.capture_set_rh_hook, None)
 
90
        branch.set_revision_history([])
 
91
        expected_params = ('set_rh', branch, [], True)
 
92
        self.assertHookCalls(expected_params, branch)
 
93
 
 
94
    def test_set_rh_nonempty_history(self):
 
95
        tree = self.make_branch_and_memory_tree('source')
 
96
        tree.lock_write()
 
97
        tree.add('')
 
98
        tree.commit('another commit', rev_id='f\xc2\xb5')
 
99
        tree.commit('empty commit', rev_id='foo')
 
100
        tree.unlock()
 
101
        branch = tree.branch
 
102
        _mod_branch.Branch.hooks.install_named_hook(
 
103
            'set_rh', self.capture_set_rh_hook, None)
 
104
        # some branches require that their history be set to a revision in the
 
105
        # repository
 
106
        branch.set_revision_history(['f\xc2\xb5'])
 
107
        expected_params =('set_rh', branch, ['f\xc2\xb5'], True)
 
108
        self.assertHookCalls(expected_params, branch)
 
109
 
 
110
    def test_set_rh_branch_is_locked(self):
 
111
        branch = self.make_branch('source')
 
112
        _mod_branch.Branch.hooks.install_named_hook(
 
113
            'set_rh', self.capture_set_rh_hook, None)
 
114
        branch.set_revision_history([])
 
115
        expected_params = ('set_rh', branch, [], True)
 
116
        self.assertHookCalls(expected_params, branch)
 
117
 
 
118
    def test_set_rh_calls_all_hooks_no_errors(self):
 
119
        branch = self.make_branch('source')
 
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)
 
124
        branch.set_revision_history([])
 
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
 
73
138
class TestOpen(tests.TestCaseWithMemoryTransport):
74
139
 
75
140
    def capture_hook(self, branch):
138
203
        """
139
204
        branch = self.make_branch_with_revision_ids('revid-one')
140
205
        def assertBranchAtRevision1(params):
141
 
            self.assertEqual(
 
206
            self.assertEquals(
142
207
                (1, 'revid-one'), params.branch.last_revision_info())
143
208
        _mod_branch.Branch.hooks.install_named_hook(
144
209
            'pre_change_branch_tip', assertBranchAtRevision1, None)
235
300
        """
236
301
        branch = self.make_branch_with_revision_ids('revid-one')
237
302
        def assertBranchAtRevision1(params):
238
 
            self.assertEqual(
 
303
            self.assertEquals(
239
304
                (0, revision.NULL_REVISION), params.branch.last_revision_info())
240
305
        _mod_branch.Branch.hooks.install_named_hook(
241
306
            'post_change_branch_tip', assertBranchAtRevision1, None)
294
359
    """
295
360
 
296
361
    def setUp(self):
297
 
        super(TestAllMethodsThatChangeTipWillRunHooks, self).setUp()
 
362
        ChangeBranchTipTestCase.setUp(self)
298
363
        self.installPreAndPostHooks()
299
364
 
300
365
    def installPreAndPostHooks(self):
319
384
        self.assertEqual(length, len(self.pre_hook_calls))
320
385
        self.assertEqual(length, len(self.post_hook_calls))
321
386
 
 
387
    def test_set_revision_history(self):
 
388
        branch = self.make_branch('')
 
389
        branch.set_revision_history([])
 
390
        self.assertPreAndPostHooksWereInvoked(branch, True)
 
391
 
322
392
    def test_set_last_revision_info(self):
323
393
        branch = self.make_branch('')
324
394
        branch.set_last_revision_info(0, revision.NULL_REVISION)