~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

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

  • Committer: Tarmac
  • Author(s): Vincent Ladeuil
  • Date: 2017-01-30 14:42:05 UTC
  • mfrom: (6620.1.1 trunk)
  • Revision ID: tarmac-20170130144205-r8fh2xpmiuxyozpv
Merge  2.7 into trunk including fix for bug #1657238 [r=vila]

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
70
70
            self.assertEqual([expected_params], hook_calls)
71
71
 
72
72
 
73
 
class TestSetRevisionHistoryHook(ChangeBranchTipTestCase):
74
 
 
75
 
    def setUp(self):
76
 
        self.hook_calls = []
77
 
        super(TestSetRevisionHistoryHook, self).setUp()
78
 
 
79
 
    def capture_set_rh_hook(self, branch, rev_history):
80
 
        """Capture post set-rh hook calls to self.hook_calls.
81
 
 
82
 
        The call is logged, as is some state of the branch.
83
 
        """
84
 
        self.hook_calls.append(
85
 
            ('set_rh', branch, rev_history, branch.is_locked()))
86
 
 
87
 
    def test_set_rh_empty_history(self):
88
 
        branch = self.make_branch('source')
89
 
        _mod_branch.Branch.hooks.install_named_hook(
90
 
            'set_rh', self.capture_set_rh_hook, None)
91
 
        self.applyDeprecated(deprecated_in((2, 4, 0)),
92
 
            branch.set_revision_history, [])
93
 
        expected_params = ('set_rh', branch, [], True)
94
 
        self.assertHookCalls(expected_params, branch)
95
 
 
96
 
    def test_set_rh_nonempty_history(self):
97
 
        tree = self.make_branch_and_memory_tree('source')
98
 
        tree.lock_write()
99
 
        tree.add('')
100
 
        tree.commit('another commit', rev_id='f\xc2\xb5')
101
 
        tree.commit('empty commit', rev_id='foo')
102
 
        tree.unlock()
103
 
        branch = tree.branch
104
 
        _mod_branch.Branch.hooks.install_named_hook(
105
 
            'set_rh', self.capture_set_rh_hook, None)
106
 
        # some branches require that their history be set to a revision in the
107
 
        # repository
108
 
        self.applyDeprecated(deprecated_in((2, 4, 0)),
109
 
            branch.set_revision_history, ['f\xc2\xb5'])
110
 
        expected_params =('set_rh', branch, ['f\xc2\xb5'], True)
111
 
        self.assertHookCalls(expected_params, branch)
112
 
 
113
 
    def test_set_rh_branch_is_locked(self):
114
 
        branch = self.make_branch('source')
115
 
        _mod_branch.Branch.hooks.install_named_hook(
116
 
            'set_rh', self.capture_set_rh_hook, None)
117
 
        self.applyDeprecated(deprecated_in((2, 4, 0)),
118
 
            branch.set_revision_history, [])
119
 
        expected_params = ('set_rh', branch, [], True)
120
 
        self.assertHookCalls(expected_params, branch)
121
 
 
122
 
    def test_set_rh_calls_all_hooks_no_errors(self):
123
 
        branch = self.make_branch('source')
124
 
        _mod_branch.Branch.hooks.install_named_hook(
125
 
            'set_rh', self.capture_set_rh_hook, None)
126
 
        _mod_branch.Branch.hooks.install_named_hook(
127
 
            'set_rh', self.capture_set_rh_hook, None)
128
 
        self.applyDeprecated(deprecated_in((2, 4, 0)),
129
 
            branch.set_revision_history, [])
130
 
        expected_calls = [('set_rh', branch, [], True),
131
 
            ('set_rh', branch, [], True),
132
 
            ]
133
 
        if isinstance(branch, remote.RemoteBranch):
134
 
            # For a remote branch, both the server and the client will raise
135
 
            # set_rh, and the server will do so first because that is where
136
 
            # the change takes place.
137
 
            self.assertEqual(expected_calls, self.hook_calls[2:])
138
 
            self.assertEqual(4, len(self.hook_calls))
139
 
        else:
140
 
            self.assertEqual(expected_calls, self.hook_calls)
141
 
 
142
 
 
143
73
class TestOpen(tests.TestCaseWithMemoryTransport):
144
74
 
145
75
    def capture_hook(self, branch):
208
138
        """
209
139
        branch = self.make_branch_with_revision_ids('revid-one')
210
140
        def assertBranchAtRevision1(params):
211
 
            self.assertEquals(
 
141
            self.assertEqual(
212
142
                (1, 'revid-one'), params.branch.last_revision_info())
213
143
        _mod_branch.Branch.hooks.install_named_hook(
214
144
            'pre_change_branch_tip', assertBranchAtRevision1, None)
305
235
        """
306
236
        branch = self.make_branch_with_revision_ids('revid-one')
307
237
        def assertBranchAtRevision1(params):
308
 
            self.assertEquals(
 
238
            self.assertEqual(
309
239
                (0, revision.NULL_REVISION), params.branch.last_revision_info())
310
240
        _mod_branch.Branch.hooks.install_named_hook(
311
241
            'post_change_branch_tip', assertBranchAtRevision1, None)
364
294
    """
365
295
 
366
296
    def setUp(self):
367
 
        ChangeBranchTipTestCase.setUp(self)
 
297
        super(TestAllMethodsThatChangeTipWillRunHooks, self).setUp()
368
298
        self.installPreAndPostHooks()
369
299
 
370
300
    def installPreAndPostHooks(self):
389
319
        self.assertEqual(length, len(self.pre_hook_calls))
390
320
        self.assertEqual(length, len(self.post_hook_calls))
391
321
 
392
 
    def test_set_revision_history(self):
393
 
        branch = self.make_branch('')
394
 
        self.applyDeprecated(deprecated_in((2, 4, 0)),
395
 
            branch.set_revision_history, [])
396
 
        self.assertPreAndPostHooksWereInvoked(branch, True)
397
 
 
398
322
    def test_set_last_revision_info(self):
399
323
        branch = self.make_branch('')
400
324
        branch.set_last_revision_info(0, revision.NULL_REVISION)