~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_branch.py

  • Committer: Patch Queue Manager
  • Date: 2012-03-04 18:21:04 UTC
  • mfrom: (6468.4.3 509275-lp-fixes)
  • Revision ID: pqm@pqm.ubuntu.com-20120304182104-8y1tdavoblrrhflc
(jelmer) Add --link-bug option to 'bzr lp-propose'. (Ross Lagerwall)

Show diffs side-by-side

added added

removed removed

Lines of Context:
28
28
    branch as _mod_branch,
29
29
    bzrdir,
30
30
    config,
31
 
    controldir,
32
31
    errors,
33
32
    symbol_versioning,
34
33
    tests,
228
227
        branch = _mod_branch.Branch.open('.')
229
228
        self.assertEquals(branch._format.features, {})
230
229
 
 
230
    def test_register_unregister_format(self):
 
231
        # Test the deprecated format registration functions
 
232
        format = SampleBranchFormat()
 
233
        # make a control dir
 
234
        dir = bzrdir.BzrDirMetaFormat1().initialize(self.get_url())
 
235
        # make a branch
 
236
        format.initialize(dir)
 
237
        # register a format for it.
 
238
        self.applyDeprecated(symbol_versioning.deprecated_in((2, 4, 0)),
 
239
            _mod_branch.BranchFormat.register_format, format)
 
240
        # which branch.Open will refuse (not supported)
 
241
        self.assertRaises(errors.UnsupportedFormatError,
 
242
                          _mod_branch.Branch.open, self.get_url())
 
243
        self.make_branch_and_tree('foo')
 
244
        # but open_downlevel will work
 
245
        self.assertEqual(
 
246
            format.open(dir),
 
247
            bzrdir.BzrDir.open(self.get_url()).open_branch(unsupported=True))
 
248
        # unregister the format
 
249
        self.applyDeprecated(symbol_versioning.deprecated_in((2, 4, 0)),
 
250
            _mod_branch.BranchFormat.unregister_format, format)
 
251
        self.make_branch_and_tree('bar')
 
252
 
231
253
 
232
254
class TestBranchFormatRegistry(tests.TestCase):
233
255
 
340
362
        self.assertPathDoesNotExist('a/.bzr/branch/bound')
341
363
        self.assertEqual('ftp://example.com', branch.get_bound_location())
342
364
 
 
365
    def test_set_revision_history(self):
 
366
        builder = self.make_branch_builder('.', format=self.get_format_name())
 
367
        builder.build_snapshot('foo', None,
 
368
            [('add', ('', None, 'directory', None))],
 
369
            message='foo')
 
370
        builder.build_snapshot('bar', None, [], message='bar')
 
371
        branch = builder.get_branch()
 
372
        branch.lock_write()
 
373
        self.addCleanup(branch.unlock)
 
374
        self.applyDeprecated(symbol_versioning.deprecated_in((2, 4, 0)),
 
375
            branch.set_revision_history, ['foo', 'bar'])
 
376
        self.applyDeprecated(symbol_versioning.deprecated_in((2, 4, 0)),
 
377
                branch.set_revision_history, ['foo'])
 
378
        self.assertRaises(errors.NotLefthandHistory,
 
379
            self.applyDeprecated, symbol_versioning.deprecated_in((2, 4, 0)),
 
380
            branch.set_revision_history, ['bar'])
 
381
 
343
382
    def do_checkout_test(self, lightweight=False):
344
383
        tree = self.make_branch_and_tree('source',
345
384
            format=self.get_format_name_subtree())
449
488
 
450
489
    def make_branch(self, location, format=None):
451
490
        if format is None:
452
 
            format = controldir.format_registry.make_bzrdir('1.9')
 
491
            format = bzrdir.format_registry.make_bzrdir('1.9')
453
492
            format.set_branch_format(_mod_branch.BzrBranchFormat8())
454
493
        return tests.TestCaseWithTransport.make_branch(
455
494
            self, location, format=format)
552
591
    def test_constructor(self):
553
592
        """Check that creating a BranchHooks instance has the right defaults."""
554
593
        hooks = _mod_branch.BranchHooks()
 
594
        self.assertTrue("set_rh" in hooks, "set_rh not in %s" % hooks)
555
595
        self.assertTrue("post_push" in hooks, "post_push not in %s" % hooks)
556
596
        self.assertTrue("post_commit" in hooks, "post_commit not in %s" % hooks)
557
597
        self.assertTrue("pre_commit" in hooks, "pre_commit not in %s" % hooks)
653
693
            'Value "not-a-bool" is not valid for "append_revisions_only"',
654
694
            self.warnings[0])
655
695
 
656
 
    def test_use_fresh_values(self):
657
 
        copy = _mod_branch.Branch.open(self.branch.base)
658
 
        copy.lock_write()
659
 
        try:
660
 
            copy.get_config_stack().set('foo', 'bar')
661
 
        finally:
662
 
            copy.unlock()
663
 
        self.assertFalse(self.branch.is_locked())
664
 
        result = self.branch.get_config_stack().get('foo')
665
 
        # Bug: https://bugs.launchpad.net/bzr/+bug/948339
666
 
        self.expectFailure('Unlocked branches cache their configs',
667
 
            self.assertEqual, 'bar', result)
668
 
 
669
 
    def test_set_from_config_get_from_config_stack(self):
670
 
        self.branch.lock_write()
671
 
        self.addCleanup(self.branch.unlock)
672
 
        self.branch.get_config().set_user_option('foo', 'bar')
673
 
        result = self.branch.get_config_stack().get('foo')
674
 
        # https://bugs.launchpad.net/bzr/+bug/948344
675
 
        self.expectFailure('BranchStack uses cache after set_user_option',
676
 
                           self.assertEqual, 'bar', result)
677
 
 
678
 
    def test_set_from_config_stack_get_from_config(self):
679
 
        self.branch.lock_write()
680
 
        self.addCleanup(self.branch.unlock)
681
 
        self.branch.get_config_stack().set('foo', 'bar')
682
 
        self.assertEqual('bar',
683
 
                         self.branch.get_config().get_user_option('foo'))
684
 
 
685
 
    def test_set_delays_write(self):
686
 
        self.branch.lock_write()
687
 
        self.addCleanup(self.branch.unlock)
688
 
        self.branch.get_config_stack().set('foo', 'bar')
689
 
        copy = _mod_branch.Branch.open(self.branch.base)
690
 
        result = copy.get_config_stack().get('foo')
691
 
        # Bug: https://bugs.launchpad.net/bzr/+bug/948339
692
 
        self.expectFailure("Config writes are not cached.", self.assertIs,
693
 
                           None, result)
694
 
 
695
696
 
696
697
class TestPullResult(tests.TestCase):
697
698
 
 
699
    def test_pull_result_to_int(self):
 
700
        # to support old code, the pull result can be used as an int
 
701
        r = _mod_branch.PullResult()
 
702
        r.old_revno = 10
 
703
        r.new_revno = 20
 
704
        # this usage of results is not recommended for new code (because it
 
705
        # doesn't describe very well what happened), but for api stability
 
706
        # it's still supported
 
707
        self.assertEqual(self.applyDeprecated(
 
708
            symbol_versioning.deprecated_in((2, 3, 0)),
 
709
            r.__int__),
 
710
            10)
 
711
 
698
712
    def test_report_changed(self):
699
713
        r = _mod_branch.PullResult()
700
714
        r.old_revid = "old-revid"