~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: 2010-02-11 04:02:41 UTC
  • mfrom: (5017.2.2 tariff)
  • Revision ID: pqm@pqm.ubuntu.com-20100211040241-w6n021dz0uus341n
(mbp) add import-tariff tests

Show diffs side-by-side

added added

removed removed

Lines of Context:
123
123
        """See BzrBranchFormat.get_format_string()."""
124
124
        return "Sample branch format."
125
125
 
126
 
    def initialize(self, a_bzrdir, name=None):
 
126
    def initialize(self, a_bzrdir):
127
127
        """Format 4 branches cannot be created."""
128
 
        t = a_bzrdir.get_branch_transport(self, name=name)
 
128
        t = a_bzrdir.get_branch_transport(self)
129
129
        t.put_bytes('format', self.get_format_string())
130
130
        return 'A branch'
131
131
 
132
132
    def is_supported(self):
133
133
        return False
134
134
 
135
 
    def open(self, transport, name=None, _found=False, ignore_fallbacks=False):
 
135
    def open(self, transport, _found=False, ignore_fallbacks=False):
136
136
        return "opened branch."
137
137
 
138
138
 
438
438
        t.mkdir('branch')
439
439
        branch_dir = bzrdirformat.initialize(self.get_url('branch'))
440
440
        made_branch = _mod_branch.BranchReferenceFormat().initialize(
441
 
            branch_dir, target_branch=target_branch)
 
441
            branch_dir, target_branch)
442
442
        self.assertEqual(made_branch.base, target_branch.base)
443
443
        opened_branch = branch_dir.open_branch()
444
444
        self.assertEqual(opened_branch.base, target_branch.base)
455
455
            _mod_branch.BranchReferenceFormat().get_reference(checkout.bzrdir))
456
456
 
457
457
 
458
 
class TestHooks(tests.TestCaseWithTransport):
 
458
class TestHooks(tests.TestCase):
459
459
 
460
460
    def test_constructor(self):
461
461
        """Check that creating a BranchHooks instance has the right defaults."""
469
469
                        "post_uncommit not in %s" % hooks)
470
470
        self.assertTrue("post_change_branch_tip" in hooks,
471
471
                        "post_change_branch_tip not in %s" % hooks)
472
 
        self.assertTrue("post_branch_init" in hooks,
473
 
                        "post_branch_init not in %s" % hooks)
474
 
        self.assertTrue("post_switch" in hooks,
475
 
                        "post_switch not in %s" % hooks)
476
472
 
477
473
    def test_installed_hooks_are_BranchHooks(self):
478
474
        """The installed hooks object should be a BranchHooks."""
480
476
        self.assertIsInstance(self._preserved_hooks[_mod_branch.Branch][1],
481
477
                              _mod_branch.BranchHooks)
482
478
 
483
 
    def test_post_branch_init_hook(self):
484
 
        calls = []
485
 
        _mod_branch.Branch.hooks.install_named_hook('post_branch_init',
486
 
            calls.append, None)
487
 
        self.assertLength(0, calls)
488
 
        branch = self.make_branch('a')
489
 
        self.assertLength(1, calls)
490
 
        params = calls[0]
491
 
        self.assertIsInstance(params, _mod_branch.BranchInitHookParams)
492
 
        self.assertTrue(hasattr(params, 'bzrdir'))
493
 
        self.assertTrue(hasattr(params, 'branch'))
494
 
 
495
 
    def test_post_switch_hook(self):
496
 
        from bzrlib import switch
497
 
        calls = []
498
 
        _mod_branch.Branch.hooks.install_named_hook('post_switch',
499
 
            calls.append, None)
500
 
        tree = self.make_branch_and_tree('branch-1')
501
 
        self.build_tree(['branch-1/file-1'])
502
 
        tree.add('file-1')
503
 
        tree.commit('rev1')
504
 
        to_branch = tree.bzrdir.sprout('branch-2').open_branch()
505
 
        self.build_tree(['branch-1/file-2'])
506
 
        tree.add('file-2')
507
 
        tree.remove('file-1')
508
 
        tree.commit('rev2')
509
 
        checkout = tree.branch.create_checkout('checkout')
510
 
        self.assertLength(0, calls)
511
 
        switch.switch(checkout.bzrdir, to_branch)
512
 
        self.assertLength(1, calls)
513
 
        params = calls[0]
514
 
        self.assertIsInstance(params, _mod_branch.SwitchHookParams)
515
 
        self.assertTrue(hasattr(params, 'to_branch'))
516
 
        self.assertTrue(hasattr(params, 'revision_id'))
517
 
 
518
 
 
519
 
class TestBranchOptions(tests.TestCaseWithTransport):
520
 
 
521
 
    def setUp(self):
522
 
        super(TestBranchOptions, self).setUp()
523
 
        self.branch = self.make_branch('.')
524
 
        self.config = self.branch.get_config()
525
 
 
526
 
    def check_append_revisions_only(self, expected_value, value=None):
527
 
        """Set append_revisions_only in config and check its interpretation."""
528
 
        if value is not None:
529
 
            self.config.set_user_option('append_revisions_only', value)
530
 
        self.assertEqual(expected_value,
531
 
                         self.branch._get_append_revisions_only())
532
 
 
533
 
    def test_valid_append_revisions_only(self):
534
 
        self.assertEquals(None,
535
 
                          self.config.get_user_option('append_revisions_only'))
536
 
        self.check_append_revisions_only(None)
537
 
        self.check_append_revisions_only(False, 'False')
538
 
        self.check_append_revisions_only(True, 'True')
539
 
        # The following values will cause compatibility problems on projects
540
 
        # using older bzr versions (<2.2) but are accepted
541
 
        self.check_append_revisions_only(False, 'false')
542
 
        self.check_append_revisions_only(True, 'true')
543
 
 
544
 
    def test_invalid_append_revisions_only(self):
545
 
        """Ensure warning is noted on invalid settings"""
546
 
        self.warnings = []
547
 
        def warning(*args):
548
 
            self.warnings.append(args[0] % args[1:])
549
 
        self.overrideAttr(trace, 'warning', warning)
550
 
        self.check_append_revisions_only(None, 'not-a-bool')
551
 
        self.assertLength(1, self.warnings)
552
 
        self.assertEqual(
553
 
            'Value "not-a-bool" is not a boolean for "append_revisions_only"',
554
 
            self.warnings[0])
555
 
 
556
479
 
557
480
class TestPullResult(tests.TestCase):
558
481