~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_branch.py

  • Committer: Canonical.com Patch Queue Manager
  • Date: 2007-06-28 05:18:30 UTC
  • mfrom: (2557.1.1 trivial)
  • Revision ID: pqm@pqm.ubuntu.com-20070628051830-re1rvfieof32tnux
[BUG 119330] Fix tempfile permissions error in smart server tar bundling (under windows) (Martin_)

Show diffs side-by-side

added added

removed removed

Lines of Context:
27
27
from bzrlib import (
28
28
    branch as _mod_branch,
29
29
    bzrdir,
30
 
    config,
31
30
    errors,
32
 
    trace,
33
31
    urlutils,
34
32
    )
35
33
from bzrlib.branch import (
39
37
    BranchReferenceFormat,
40
38
    BzrBranch5,
41
39
    BzrBranchFormat5,
42
 
    BzrBranchFormat6,
43
40
    PullResult,
44
41
    )
45
42
from bzrlib.bzrdir import (BzrDirMetaFormat1, BzrDirMeta1, 
55
52
 
56
53
class TestDefaultFormat(TestCase):
57
54
 
58
 
    def test_default_format(self):
59
 
        # update this if you change the default branch format
60
 
        self.assertIsInstance(BranchFormat.get_default_format(),
61
 
                BzrBranchFormat6)
62
 
 
63
 
    def test_default_format_is_same_as_bzrdir_default(self):
64
 
        # XXX: it might be nice if there was only one place the default was
65
 
        # set, but at the moment that's not true -- mbp 20070814 -- 
66
 
        # https://bugs.launchpad.net/bzr/+bug/132376
67
 
        self.assertEqual(BranchFormat.get_default_format(),
68
 
                BzrDirFormat.get_default_format().get_branch_format())
69
 
 
70
55
    def test_get_set_default_format(self):
71
 
        # set the format and then set it back again
72
56
        old_format = BranchFormat.get_default_format()
 
57
        # default is 5
 
58
        self.assertTrue(isinstance(old_format, BzrBranchFormat5))
73
59
        BranchFormat.set_default_format(SampleBranchFormat())
74
60
        try:
75
61
            # the default branch format is used by the meta dir format
107
93
                                   ensure_config_dir_exists)
108
94
        ensure_config_dir_exists()
109
95
        fn = locations_config_filename()
110
 
        # write correct newlines to locations.conf
111
 
        # by default ConfigObj uses native line-endings for new files
112
 
        # but uses already existing line-endings if file is not empty
113
 
        f = open(fn, 'wb')
114
 
        try:
115
 
            f.write('# comment\n')
116
 
        finally:
117
 
            f.close()
118
 
 
119
96
        branch = self.make_branch('.', format='knit')
120
97
        branch.set_push_location('foo')
121
98
        local_path = urlutils.local_path_from_url(branch.base[:-1])
122
 
        self.assertFileEqual("# comment\n"
123
 
                             "[%s]\n"
 
99
        self.assertFileEqual("[%s]\n"
124
100
                             "push_location = foo\n"
125
101
                             "push_location:policy = norecurse" % local_path,
126
102
                             fn)
246
222
        finally:
247
223
            tree.unlock()
248
224
 
 
225
    def test_append_revision(self):
 
226
        tree = self.make_branch_and_tree('branch1',
 
227
            format='dirstate-tags')
 
228
        tree.lock_write()
 
229
        try:
 
230
            tree.commit('foo', rev_id='foo')
 
231
            tree.commit('bar', rev_id='bar')
 
232
            tree.commit('baz', rev_id='baz')
 
233
            tree.set_last_revision('bar')
 
234
            tree.branch.set_last_revision_info(2, 'bar')
 
235
            tree.commit('qux', rev_id='qux')
 
236
            tree.add_parent_tree_id('baz')
 
237
            tree.commit('qux', rev_id='quxx')
 
238
            tree.branch.set_last_revision_info(0, 'null:')
 
239
            self.assertRaises(errors.NotLeftParentDescendant,
 
240
                              tree.branch.append_revision, 'bar')
 
241
            tree.branch.append_revision('foo')
 
242
            self.assertRaises(errors.NotLeftParentDescendant,
 
243
                              tree.branch.append_revision, 'baz')
 
244
            tree.branch.append_revision('bar')
 
245
            tree.branch.append_revision('baz')
 
246
            self.assertRaises(errors.NotLeftParentDescendant,
 
247
                              tree.branch.append_revision, 'quxx')
 
248
        finally:
 
249
            tree.unlock()
 
250
 
249
251
    def do_checkout_test(self, lightweight=False):
250
252
        tree = self.make_branch_and_tree('source', format='dirstate-with-subtree')
251
253
        subtree = self.make_branch_and_tree('source/subtree',
272
274
        else:
273
275
            self.assertEndsWith(subbranch.base, 'target/subtree/subsubtree/')
274
276
 
 
277
 
275
278
    def test_checkout_with_references(self):
276
279
        self.do_checkout_test()
277
280
 
278
281
    def test_light_checkout_with_references(self):
279
282
        self.do_checkout_test(lightweight=True)
280
283
 
281
 
    def test_set_push(self):
282
 
        branch = self.make_branch('source', format='dirstate-tags')
283
 
        branch.get_config().set_user_option('push_location', 'old',
284
 
            store=config.STORE_LOCATION)
285
 
        warnings = []
286
 
        def warning(*args):
287
 
            warnings.append(args[0] % args[1:])
288
 
        _warning = trace.warning
289
 
        trace.warning = warning
290
 
        try:
291
 
            branch.set_push_location('new')
292
 
        finally:
293
 
            trace.warning = _warning
294
 
        self.assertEqual(warnings[0], 'Value "new" is masked by "old" from '
295
 
                         'locations.conf')
296
 
 
297
284
class TestBranchReference(TestCaseWithTransport):
298
285
    """Tests for the branch reference facility."""
299
286
 
331
318
        self.assertTrue("set_rh" in hooks, "set_rh not in %s" % hooks)
332
319
        self.assertTrue("post_push" in hooks, "post_push not in %s" % hooks)
333
320
        self.assertTrue("post_commit" in hooks, "post_commit not in %s" % hooks)
334
 
        self.assertTrue("pre_commit" in hooks, "pre_commit not in %s" % hooks)
335
321
        self.assertTrue("post_pull" in hooks, "post_pull not in %s" % hooks)
336
322
        self.assertTrue("post_uncommit" in hooks, "post_uncommit not in %s" % hooks)
337
323
 
340
326
        # the installed hooks are saved in self._preserved_hooks.
341
327
        self.assertIsInstance(self._preserved_hooks[_mod_branch.Branch], BranchHooks)
342
328
 
 
329
    def test_install_hook_raises_unknown_hook(self):
 
330
        """install_hook should raise UnknownHook if a hook is unknown."""
 
331
        hooks = BranchHooks()
 
332
        self.assertRaises(UnknownHook, hooks.install_hook, 'silly', None)
 
333
 
 
334
    def test_install_hook_appends_known_hook(self):
 
335
        """install_hook should append the callable for known hooks."""
 
336
        hooks = BranchHooks()
 
337
        hooks.install_hook('set_rh', None)
 
338
        self.assertEqual(hooks['set_rh'], [None])
 
339
 
343
340
 
344
341
class TestPullResult(TestCase):
345
342