/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar
2297.1.2 by Martin Pool
Cleanup imports
1
# Copyright (C) 2005, 2006, 2007 Canonical Ltd
1553.5.71 by Martin Pool
Change branch format 5 to use LockDirs, not transport locks
2
#
1534.4.3 by Robert Collins
Implement BranchTestProviderAdapter, so tests now run across all branch formats.
3
# This program is free software; you can redistribute it and/or modify
4
# it under the terms of the GNU General Public License as published by
5
# the Free Software Foundation; either version 2 of the License, or
6
# (at your option) any later version.
1553.5.71 by Martin Pool
Change branch format 5 to use LockDirs, not transport locks
7
#
1534.4.3 by Robert Collins
Implement BranchTestProviderAdapter, so tests now run across all branch formats.
8
# This program is distributed in the hope that it will be useful,
9
# but WITHOUT ANY WARRANTY; without even the implied warranty of
10
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11
# GNU General Public License for more details.
1553.5.71 by Martin Pool
Change branch format 5 to use LockDirs, not transport locks
12
#
1534.4.3 by Robert Collins
Implement BranchTestProviderAdapter, so tests now run across all branch formats.
13
# You should have received a copy of the GNU General Public License
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
16
17
"""Tests for the Branch facility that are not interface  tests.
18
1534.4.39 by Robert Collins
Basic BzrDir support.
19
For interface tests see tests/branch_implementations/*.py.
1534.4.3 by Robert Collins
Implement BranchTestProviderAdapter, so tests now run across all branch formats.
20
21
For concrete class tests see this file, and for meta-branch tests
22
also see this file.
23
"""
24
1534.4.7 by Robert Collins
Move downlevel check up to the Branch.open logic, removing it from the Branch constructor and deprecating relax_version_check to the same.
25
from StringIO import StringIO
1534.4.3 by Robert Collins
Implement BranchTestProviderAdapter, so tests now run across all branch formats.
26
2230.3.3 by Aaron Bentley
Add more config testing
27
from bzrlib import (
28
    branch as _mod_branch,
2230.3.44 by Aaron Bentley
Change asserts to specific errors for left-hand history violations
29
    bzrdir,
1551.15.35 by Aaron Bentley
Warn when setting config values that will be masked (#122286)
30
    config,
2230.3.44 by Aaron Bentley
Change asserts to specific errors for left-hand history violations
31
    errors,
1551.15.35 by Aaron Bentley
Warn when setting config values that will be masked (#122286)
32
    trace,
2230.3.3 by Aaron Bentley
Add more config testing
33
    urlutils,
34
    )
2297.1.2 by Martin Pool
Cleanup imports
35
from bzrlib.branch import (
36
    Branch,
37
    BranchHooks,
38
    BranchFormat,
39
    BranchReferenceFormat,
40
    BzrBranch5,
41
    BzrBranchFormat5,
2297.1.3 by Martin Pool
PullResult can pretend to be an int for api compatibility with old .pull()
42
    PullResult,
2297.1.2 by Martin Pool
Cleanup imports
43
    )
1553.5.71 by Martin Pool
Change branch format 5 to use LockDirs, not transport locks
44
from bzrlib.bzrdir import (BzrDirMetaFormat1, BzrDirMeta1, 
45
                           BzrDir, BzrDirFormat)
1534.4.7 by Robert Collins
Move downlevel check up to the Branch.open logic, removing it from the Branch constructor and deprecating relax_version_check to the same.
46
from bzrlib.errors import (NotBranchError,
47
                           UnknownFormatError,
2245.1.3 by Robert Collins
Add install_hook to the BranchHooks class as the official means for installing a hook.
48
                           UnknownHook,
1534.4.7 by Robert Collins
Move downlevel check up to the Branch.open logic, removing it from the Branch constructor and deprecating relax_version_check to the same.
49
                           UnsupportedFormatError,
50
                           )
51
1534.4.44 by Robert Collins
Make a new BzrDir format that uses a versioned branch format in a branch/ subdirectory.
52
from bzrlib.tests import TestCase, TestCaseWithTransport
1534.4.4 by Robert Collins
Make BzrBranchFormat.find_format take a transport not a url for efficiency.
53
from bzrlib.transport import get_transport
1534.4.3 by Robert Collins
Implement BranchTestProviderAdapter, so tests now run across all branch formats.
54
1534.4.44 by Robert Collins
Make a new BzrDir format that uses a versioned branch format in a branch/ subdirectory.
55
class TestDefaultFormat(TestCase):
56
57
    def test_get_set_default_format(self):
2297.1.2 by Martin Pool
Cleanup imports
58
        old_format = BranchFormat.get_default_format()
1534.4.44 by Robert Collins
Make a new BzrDir format that uses a versioned branch format in a branch/ subdirectory.
59
        # default is 5
2297.1.2 by Martin Pool
Cleanup imports
60
        self.assertTrue(isinstance(old_format, BzrBranchFormat5))
61
        BranchFormat.set_default_format(SampleBranchFormat())
1534.4.44 by Robert Collins
Make a new BzrDir format that uses a versioned branch format in a branch/ subdirectory.
62
        try:
63
            # the default branch format is used by the meta dir format
64
            # which is not the default bzrdir format at this point
1685.1.42 by John Arbash Meinel
A couple more fixes to make sure memory:/// works correctly.
65
            dir = BzrDirMetaFormat1().initialize('memory:///')
1534.4.44 by Robert Collins
Make a new BzrDir format that uses a versioned branch format in a branch/ subdirectory.
66
            result = dir.create_branch()
67
            self.assertEqual(result, 'A branch')
68
        finally:
2297.1.2 by Martin Pool
Cleanup imports
69
            BranchFormat.set_default_format(old_format)
70
        self.assertEqual(old_format, BranchFormat.get_default_format())
1508.1.25 by Robert Collins
Update per review comments.
71
72
1553.5.71 by Martin Pool
Change branch format 5 to use LockDirs, not transport locks
73
class TestBranchFormat5(TestCaseWithTransport):
74
    """Tests specific to branch format 5"""
75
76
    def test_branch_format_5_uses_lockdir(self):
77
        url = self.get_url()
1553.5.72 by Martin Pool
Clean up test for Branch5 lockdirs
78
        bzrdir = BzrDirMetaFormat1().initialize(url)
79
        bzrdir.create_repository()
80
        branch = bzrdir.create_branch()
81
        t = self.get_transport()
82
        self.log("branch instance is %r" % branch)
83
        self.assert_(isinstance(branch, BzrBranch5))
84
        self.assertIsDirectory('.', t)
85
        self.assertIsDirectory('.bzr/branch', t)
86
        self.assertIsDirectory('.bzr/branch/lock', t)
1553.5.73 by Martin Pool
Additional test that Branch5 uses lockdir properly
87
        branch.lock_write()
1658.1.5 by Martin Pool
Release more locks taken during test suite
88
        try:
89
            self.assertIsDirectory('.bzr/branch/lock/held', t)
90
        finally:
91
            branch.unlock()
1553.5.71 by Martin Pool
Change branch format 5 to use LockDirs, not transport locks
92
2230.3.3 by Aaron Bentley
Add more config testing
93
    def test_set_push_location(self):
94
        from bzrlib.config import (locations_config_filename,
95
                                   ensure_config_dir_exists)
96
        ensure_config_dir_exists()
97
        fn = locations_config_filename()
98
        branch = self.make_branch('.', format='knit')
99
        branch.set_push_location('foo')
100
        local_path = urlutils.local_path_from_url(branch.base[:-1])
101
        self.assertFileEqual("[%s]\n"
102
                             "push_location = foo\n"
103
                             "push_location:policy = norecurse" % local_path,
104
                             fn)
105
2230.3.12 by Aaron Bentley
Clean up trailing whitespace
106
    # TODO RBC 20051029 test getting a push location from a branch in a
2230.3.3 by Aaron Bentley
Add more config testing
107
    # recursive section - that is, it appends the branch name.
108
1553.5.71 by Martin Pool
Change branch format 5 to use LockDirs, not transport locks
109
2297.1.2 by Martin Pool
Cleanup imports
110
class SampleBranchFormat(BranchFormat):
1534.4.44 by Robert Collins
Make a new BzrDir format that uses a versioned branch format in a branch/ subdirectory.
111
    """A sample format
112
113
    this format is initializable, unsupported to aid in testing the 
114
    open and open_downlevel routines.
115
    """
116
117
    def get_format_string(self):
118
        """See BzrBranchFormat.get_format_string()."""
119
        return "Sample branch format."
120
121
    def initialize(self, a_bzrdir):
122
        """Format 4 branches cannot be created."""
123
        t = a_bzrdir.get_branch_transport(self)
1955.3.9 by John Arbash Meinel
Find more occurrances of put() and replace with put_file or put_bytes
124
        t.put_bytes('format', self.get_format_string())
1534.4.44 by Robert Collins
Make a new BzrDir format that uses a versioned branch format in a branch/ subdirectory.
125
        return 'A branch'
126
127
    def is_supported(self):
128
        return False
129
130
    def open(self, transport, _found=False):
131
        return "opened branch."
132
133
134
class TestBzrBranchFormat(TestCaseWithTransport):
135
    """Tests for the BzrBranchFormat facility."""
136
137
    def test_find_format(self):
138
        # is the right format object found for a branch?
139
        # create a branch with a few known format objects.
140
        # this is not quite the same as 
141
        self.build_tree(["foo/", "bar/"])
142
        def check_format(format, url):
143
            dir = format._matchingbzrdir.initialize(url)
1534.4.47 by Robert Collins
Split out repository into .bzr/repository
144
            dir.create_repository()
1534.4.44 by Robert Collins
Make a new BzrDir format that uses a versioned branch format in a branch/ subdirectory.
145
            format.initialize(dir)
2297.1.2 by Martin Pool
Cleanup imports
146
            found_format = BranchFormat.find_format(dir)
1534.4.44 by Robert Collins
Make a new BzrDir format that uses a versioned branch format in a branch/ subdirectory.
147
            self.failUnless(isinstance(found_format, format.__class__))
2297.1.2 by Martin Pool
Cleanup imports
148
        check_format(BzrBranchFormat5(), "bar")
1534.4.44 by Robert Collins
Make a new BzrDir format that uses a versioned branch format in a branch/ subdirectory.
149
        
150
    def test_find_format_not_branch(self):
151
        dir = bzrdir.BzrDirMetaFormat1().initialize(self.get_url())
152
        self.assertRaises(NotBranchError,
2297.1.2 by Martin Pool
Cleanup imports
153
                          BranchFormat.find_format,
1534.4.44 by Robert Collins
Make a new BzrDir format that uses a versioned branch format in a branch/ subdirectory.
154
                          dir)
155
156
    def test_find_format_unknown_format(self):
157
        dir = bzrdir.BzrDirMetaFormat1().initialize(self.get_url())
158
        SampleBranchFormat().initialize(dir)
159
        self.assertRaises(UnknownFormatError,
2297.1.2 by Martin Pool
Cleanup imports
160
                          BranchFormat.find_format,
1534.4.44 by Robert Collins
Make a new BzrDir format that uses a versioned branch format in a branch/ subdirectory.
161
                          dir)
162
163
    def test_register_unregister_format(self):
164
        format = SampleBranchFormat()
165
        # make a control dir
166
        dir = bzrdir.BzrDirMetaFormat1().initialize(self.get_url())
167
        # make a branch
168
        format.initialize(dir)
169
        # register a format for it.
2297.1.2 by Martin Pool
Cleanup imports
170
        BranchFormat.register_format(format)
1534.4.44 by Robert Collins
Make a new BzrDir format that uses a versioned branch format in a branch/ subdirectory.
171
        # which branch.Open will refuse (not supported)
2297.1.2 by Martin Pool
Cleanup imports
172
        self.assertRaises(UnsupportedFormatError, Branch.open, self.get_url())
2230.3.22 by Aaron Bentley
Make test suite use format registry default, not BzrDir default
173
        self.make_branch_and_tree('foo')
1534.4.44 by Robert Collins
Make a new BzrDir format that uses a versioned branch format in a branch/ subdirectory.
174
        # but open_downlevel will work
1534.4.50 by Robert Collins
Got the bzrdir api straightened out, plenty of refactoring to use it pending, but the api is up and running.
175
        self.assertEqual(format.open(dir), bzrdir.BzrDir.open(self.get_url()).open_branch(unsupported=True))
1534.4.44 by Robert Collins
Make a new BzrDir format that uses a versioned branch format in a branch/ subdirectory.
176
        # unregister the format
2297.1.2 by Martin Pool
Cleanup imports
177
        BranchFormat.unregister_format(format)
2230.3.22 by Aaron Bentley
Make test suite use format registry default, not BzrDir default
178
        self.make_branch_and_tree('bar')
1534.4.50 by Robert Collins
Got the bzrdir api straightened out, plenty of refactoring to use it pending, but the api is up and running.
179
180
2230.3.1 by Aaron Bentley
Get branch6 creation working
181
class TestBranch6(TestCaseWithTransport):
182
183
    def test_creation(self):
184
        format = BzrDirMetaFormat1()
2230.3.55 by Aaron Bentley
Updates from review
185
        format.set_branch_format(_mod_branch.BzrBranchFormat6())
2230.3.1 by Aaron Bentley
Get branch6 creation working
186
        branch = self.make_branch('a', format=format)
187
        self.assertIsInstance(branch, _mod_branch.BzrBranch6)
1551.13.1 by Aaron Bentley
Introduce dirstate-tags format
188
        branch = self.make_branch('b', format='dirstate-tags')
2230.3.1 by Aaron Bentley
Get branch6 creation working
189
        self.assertIsInstance(branch, _mod_branch.BzrBranch6)
190
        branch = _mod_branch.Branch.open('a')
191
        self.assertIsInstance(branch, _mod_branch.BzrBranch6)
192
193
    def test_layout(self):
1551.13.1 by Aaron Bentley
Introduce dirstate-tags format
194
        branch = self.make_branch('a', format='dirstate-tags')
2230.3.1 by Aaron Bentley
Get branch6 creation working
195
        self.failUnlessExists('a/.bzr/branch/last-revision')
196
        self.failIfExists('a/.bzr/branch/revision-history')
197
2230.3.3 by Aaron Bentley
Add more config testing
198
    def test_config(self):
199
        """Ensure that all configuration data is stored in the branch"""
1551.13.1 by Aaron Bentley
Introduce dirstate-tags format
200
        branch = self.make_branch('a', format='dirstate-tags')
2230.3.3 by Aaron Bentley
Add more config testing
201
        branch.set_parent('http://bazaar-vcs.org')
202
        self.failIfExists('a/.bzr/branch/parent')
203
        self.assertEqual('http://bazaar-vcs.org', branch.get_parent())
204
        branch.set_push_location('sftp://bazaar-vcs.org')
205
        config = branch.get_config()._get_branch_data_config()
2230.3.12 by Aaron Bentley
Clean up trailing whitespace
206
        self.assertEqual('sftp://bazaar-vcs.org',
2230.3.3 by Aaron Bentley
Add more config testing
207
                         config.get_user_option('push_location'))
208
        branch.set_bound_location('ftp://bazaar-vcs.org')
209
        self.failIfExists('a/.bzr/branch/bound')
210
        self.assertEqual('ftp://bazaar-vcs.org', branch.get_bound_location())
211
2230.3.44 by Aaron Bentley
Change asserts to specific errors for left-hand history violations
212
    def test_set_revision_history(self):
213
        tree = self.make_branch_and_memory_tree('.',
1551.13.1 by Aaron Bentley
Introduce dirstate-tags format
214
            format='dirstate-tags')
2230.3.44 by Aaron Bentley
Change asserts to specific errors for left-hand history violations
215
        tree.lock_write()
216
        try:
217
            tree.add('.')
218
            tree.commit('foo', rev_id='foo')
219
            tree.commit('bar', rev_id='bar')
220
            tree.branch.set_revision_history(['foo', 'bar'])
221
            tree.branch.set_revision_history(['foo'])
222
            self.assertRaises(errors.NotLefthandHistory,
223
                              tree.branch.set_revision_history, ['bar'])
224
        finally:
225
            tree.unlock()
226
227
    def test_append_revision(self):
228
        tree = self.make_branch_and_tree('branch1',
1551.13.1 by Aaron Bentley
Introduce dirstate-tags format
229
            format='dirstate-tags')
2230.3.44 by Aaron Bentley
Change asserts to specific errors for left-hand history violations
230
        tree.lock_write()
231
        try:
232
            tree.commit('foo', rev_id='foo')
233
            tree.commit('bar', rev_id='bar')
234
            tree.commit('baz', rev_id='baz')
235
            tree.set_last_revision('bar')
2230.3.51 by Aaron Bentley
Store revno for Branch6, set_last_revision -> set_last_revision_info
236
            tree.branch.set_last_revision_info(2, 'bar')
2230.3.44 by Aaron Bentley
Change asserts to specific errors for left-hand history violations
237
            tree.commit('qux', rev_id='qux')
238
            tree.add_parent_tree_id('baz')
239
            tree.commit('qux', rev_id='quxx')
2230.3.51 by Aaron Bentley
Store revno for Branch6, set_last_revision -> set_last_revision_info
240
            tree.branch.set_last_revision_info(0, 'null:')
2230.3.44 by Aaron Bentley
Change asserts to specific errors for left-hand history violations
241
            self.assertRaises(errors.NotLeftParentDescendant,
242
                              tree.branch.append_revision, 'bar')
243
            tree.branch.append_revision('foo')
244
            self.assertRaises(errors.NotLeftParentDescendant,
245
                              tree.branch.append_revision, 'baz')
246
            tree.branch.append_revision('bar')
247
            tree.branch.append_revision('baz')
248
            self.assertRaises(errors.NotLeftParentDescendant,
249
                              tree.branch.append_revision, 'quxx')
250
        finally:
251
            tree.unlock()
2230.3.51 by Aaron Bentley
Store revno for Branch6, set_last_revision -> set_last_revision_info
252
2100.3.26 by Aaron Bentley
checkout type is maintained for subtrees
253
    def do_checkout_test(self, lightweight=False):
2255.2.194 by Robert Collins
[BROKEN] Many updates to stop using experimental formats in tests.
254
        tree = self.make_branch_and_tree('source', format='dirstate-with-subtree')
255
        subtree = self.make_branch_and_tree('source/subtree',
256
            format='dirstate-with-subtree')
2100.3.25 by Aaron Bentley
add subsubtree to test
257
        subsubtree = self.make_branch_and_tree('source/subtree/subsubtree',
2255.2.194 by Robert Collins
[BROKEN] Many updates to stop using experimental formats in tests.
258
            format='dirstate-with-subtree')
2100.3.25 by Aaron Bentley
add subsubtree to test
259
        self.build_tree(['source/subtree/file',
260
                         'source/subtree/subsubtree/file'])
261
        subsubtree.add('file')
2100.3.21 by Aaron Bentley
Work on checking out by-reference trees
262
        subtree.add('file')
2100.3.25 by Aaron Bentley
add subsubtree to test
263
        subtree.add_reference(subsubtree)
2100.3.21 by Aaron Bentley
Work on checking out by-reference trees
264
        tree.add_reference(subtree)
265
        tree.commit('a revision')
2100.3.23 by Aaron Bentley
Nested checkouts kinda work
266
        subtree.commit('a subtree file')
2100.3.25 by Aaron Bentley
add subsubtree to test
267
        subsubtree.commit('a subsubtree file')
2100.3.26 by Aaron Bentley
checkout type is maintained for subtrees
268
        tree.branch.create_checkout('target', lightweight=lightweight)
2100.3.21 by Aaron Bentley
Work on checking out by-reference trees
269
        self.failUnlessExists('target')
270
        self.failUnlessExists('target/subtree')
271
        self.failUnlessExists('target/subtree/file')
2100.3.25 by Aaron Bentley
add subsubtree to test
272
        self.failUnlessExists('target/subtree/subsubtree/file')
2100.3.31 by Aaron Bentley
Merged bzr.dev (17 tests failing)
273
        subbranch = _mod_branch.Branch.open('target/subtree/subsubtree')
2100.3.26 by Aaron Bentley
checkout type is maintained for subtrees
274
        if lightweight:
275
            self.assertEndsWith(subbranch.base, 'source/subtree/subsubtree/')
276
        else:
277
            self.assertEndsWith(subbranch.base, 'target/subtree/subsubtree/')
278
279
280
    def test_checkout_with_references(self):
281
        self.do_checkout_test()
282
283
    def test_light_checkout_with_references(self):
284
        self.do_checkout_test(lightweight=True)
2230.3.51 by Aaron Bentley
Store revno for Branch6, set_last_revision -> set_last_revision_info
285
1551.15.35 by Aaron Bentley
Warn when setting config values that will be masked (#122286)
286
    def test_set_push(self):
287
        branch = self.make_branch('source', format='dirstate-tags')
288
        branch.get_config().set_user_option('push_location', 'old',
289
            store=config.STORE_LOCATION)
290
        warnings = []
291
        def warning(*args):
292
            warnings.append(args[0] % args[1:])
293
        _warning = trace.warning
294
        trace.warning = warning
295
        try:
296
            branch.set_push_location('new')
297
        finally:
298
            trace.warning = _warning
299
        self.assertEqual(warnings[0], 'Value "new" is masked by "old" from '
300
                         'locations.conf')
301
1534.4.50 by Robert Collins
Got the bzrdir api straightened out, plenty of refactoring to use it pending, but the api is up and running.
302
class TestBranchReference(TestCaseWithTransport):
303
    """Tests for the branch reference facility."""
304
305
    def test_create_open_reference(self):
306
        bzrdirformat = bzrdir.BzrDirMetaFormat1()
307
        t = get_transport(self.get_url('.'))
308
        t.mkdir('repo')
309
        dir = bzrdirformat.initialize(self.get_url('repo'))
310
        dir.create_repository()
311
        target_branch = dir.create_branch()
312
        t.mkdir('branch')
313
        branch_dir = bzrdirformat.initialize(self.get_url('branch'))
2297.1.2 by Martin Pool
Cleanup imports
314
        made_branch = BranchReferenceFormat().initialize(branch_dir, target_branch)
1534.4.50 by Robert Collins
Got the bzrdir api straightened out, plenty of refactoring to use it pending, but the api is up and running.
315
        self.assertEqual(made_branch.base, target_branch.base)
316
        opened_branch = branch_dir.open_branch()
317
        self.assertEqual(opened_branch.base, target_branch.base)
2018.6.1 by Robert Collins
Implement a BzrDir.open_branch smart server method for opening a branch without VFS.
318
319
    def test_get_reference(self):
320
        """For a BranchReference, get_reference should reutrn the location."""
321
        branch = self.make_branch('target')
322
        checkout = branch.create_checkout('checkout', lightweight=True)
323
        reference_url = branch.bzrdir.root_transport.abspath('') + '/'
324
        # if the api for create_checkout changes to return different checkout types
325
        # then this file read will fail.
326
        self.assertFileEqual(reference_url, 'checkout/.bzr/branch/location')
327
        self.assertEqual(reference_url,
2018.5.97 by Andrew Bennetts
Fix more tests.
328
            _mod_branch.BranchReferenceFormat().get_reference(checkout.bzrdir))
2018.5.45 by Andrew Bennetts
Merge from bzr.dev
329
2245.1.1 by Robert Collins
New Branch hooks facility, with one initial hook 'set_rh' which triggers
330
331
class TestHooks(TestCase):
332
2245.1.2 by Robert Collins
Remove the static DefaultHooks method from Branch, replacing it with a derived dict BranchHooks object, which is easier to use and provides a place to put the policy-checking add method discussed on list.
333
    def test_constructor(self):
334
        """Check that creating a BranchHooks instance has the right defaults."""
2297.1.2 by Martin Pool
Cleanup imports
335
        hooks = BranchHooks()
2245.1.2 by Robert Collins
Remove the static DefaultHooks method from Branch, replacing it with a derived dict BranchHooks object, which is easier to use and provides a place to put the policy-checking add method discussed on list.
336
        self.assertTrue("set_rh" in hooks, "set_rh not in %s" % hooks)
2246.1.3 by Robert Collins
New branch hooks: post_push, post_pull, post_commit, post_uncommit. These
337
        self.assertTrue("post_push" in hooks, "post_push not in %s" % hooks)
338
        self.assertTrue("post_commit" in hooks, "post_commit not in %s" % hooks)
339
        self.assertTrue("post_pull" in hooks, "post_pull not in %s" % hooks)
340
        self.assertTrue("post_uncommit" in hooks, "post_uncommit not in %s" % hooks)
2245.1.1 by Robert Collins
New Branch hooks facility, with one initial hook 'set_rh' which triggers
341
2245.1.2 by Robert Collins
Remove the static DefaultHooks method from Branch, replacing it with a derived dict BranchHooks object, which is easier to use and provides a place to put the policy-checking add method discussed on list.
342
    def test_installed_hooks_are_BranchHooks(self):
343
        """The installed hooks object should be a BranchHooks."""
344
        # the installed hooks are saved in self._preserved_hooks.
2376.3.5 by Robert Collins
Fix Branch hook tests for the new eans of preserving hooks by the test suite.
345
        self.assertIsInstance(self._preserved_hooks[_mod_branch.Branch], BranchHooks)
2245.1.3 by Robert Collins
Add install_hook to the BranchHooks class as the official means for installing a hook.
346
2297.1.3 by Martin Pool
PullResult can pretend to be an int for api compatibility with old .pull()
347
348
class TestPullResult(TestCase):
349
350
    def test_pull_result_to_int(self):
351
        # to support old code, the pull result can be used as an int
352
        r = PullResult()
353
        r.old_revno = 10
354
        r.new_revno = 20
355
        # this usage of results is not recommended for new code (because it
356
        # doesn't describe very well what happened), but for api stability
357
        # it's still supported
358
        a = "%d revisions pulled" % r
359
        self.assertEqual(a, "10 revisions pulled")