~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

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

Merge bzr.dev.

Show diffs side-by-side

added added

removed removed

Lines of Context:
16
16
 
17
17
"""Tests that branch classes implement hook callouts correctly."""
18
18
 
 
19
from bzrlib.branch import Branch, ChangeBranchTipParams
19
20
from bzrlib.errors import HookFailed, TipChangeRejected
20
 
from bzrlib.branch import Branch, ChangeBranchTipParams
 
21
from bzrlib.remote import RemoteBranch
21
22
from bzrlib.revision import NULL_REVISION
22
23
from bzrlib.tests import TestCaseWithMemoryTransport
23
24
 
107
108
        return branch
108
109
 
109
110
 
 
111
class TestOpen(TestCaseWithMemoryTransport):
 
112
 
 
113
    def capture_hook(self, branch):
 
114
        self.hook_calls.append(branch)
 
115
 
 
116
    def install_hook(self):
 
117
        self.hook_calls = []
 
118
        Branch.hooks.install_named_hook('open', self.capture_hook, None)
 
119
 
 
120
    def test_create(self):
 
121
        self.install_hook()
 
122
        b = self.make_branch('.')
 
123
        self.assertEqual([b], self.hook_calls)
 
124
 
 
125
    def test_open(self):
 
126
        branch_url = self.make_branch('.').bzrdir.root_transport.base
 
127
        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))
 
139
        else:
 
140
            self.assertEqual([b], self.hook_calls)
 
141
 
 
142
 
110
143
class TestPreChangeBranchTip(ChangeBranchTipTestCase):
111
144
    """Tests for pre_change_branch_tip hook.
112
145