~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

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

  • Committer: Patch Queue Manager
  • Date: 2016-02-01 19:56:05 UTC
  • mfrom: (6615.1.1 trunk)
  • Revision ID: pqm@pqm.ubuntu.com-20160201195605-o7rl92wf6uyum3fk
(vila) Open trunk again as 2.8b1 (Vincent Ladeuil)

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2007-2010 Canonical Ltd
 
1
# Copyright (C) 2007-2012, 2016 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
26
27
from bzrlib.tests import test_server
27
28
 
28
29
class ChangeBranchTipTestCase(tests.TestCaseWithMemoryTransport):
69
70
            self.assertEqual([expected_params], hook_calls)
70
71
 
71
72
 
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
 
 
138
73
class TestOpen(tests.TestCaseWithMemoryTransport):
139
74
 
140
75
    def capture_hook(self, branch):
203
138
        """
204
139
        branch = self.make_branch_with_revision_ids('revid-one')
205
140
        def assertBranchAtRevision1(params):
206
 
            self.assertEquals(
 
141
            self.assertEqual(
207
142
                (1, 'revid-one'), params.branch.last_revision_info())
208
143
        _mod_branch.Branch.hooks.install_named_hook(
209
144
            'pre_change_branch_tip', assertBranchAtRevision1, None)
300
235
        """
301
236
        branch = self.make_branch_with_revision_ids('revid-one')
302
237
        def assertBranchAtRevision1(params):
303
 
            self.assertEquals(
 
238
            self.assertEqual(
304
239
                (0, revision.NULL_REVISION), params.branch.last_revision_info())
305
240
        _mod_branch.Branch.hooks.install_named_hook(
306
241
            'post_change_branch_tip', assertBranchAtRevision1, None)
359
294
    """
360
295
 
361
296
    def setUp(self):
362
 
        ChangeBranchTipTestCase.setUp(self)
 
297
        super(TestAllMethodsThatChangeTipWillRunHooks, self).setUp()
363
298
        self.installPreAndPostHooks()
364
299
 
365
300
    def installPreAndPostHooks(self):
384
319
        self.assertEqual(length, len(self.pre_hook_calls))
385
320
        self.assertEqual(length, len(self.post_hook_calls))
386
321
 
387
 
    def test_set_revision_history(self):
388
 
        branch = self.make_branch('')
389
 
        branch.set_revision_history([])
390
 
        self.assertPreAndPostHooksWereInvoked(branch, True)
391
 
 
392
322
    def test_set_last_revision_info(self):
393
323
        branch = self.make_branch('')
394
324
        branch.set_last_revision_info(0, revision.NULL_REVISION)