/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_branch.py

  • Committer: Marco Pantaleoni
  • Date: 2010-03-24 14:35:25 UTC
  • mto: This revision was merged to the branch mainline in revision 5174.
  • Revision ID: panta@elasticworld.org-20100324143525-00sej430c23d3gto
Added the new hooks 'post_branch', 'post_switch' and 'post_repo_init',
called respectively whenever a new branch is created, when a checkout is
switched to a different branch and when a repository is initialized
(created).

Show diffs side-by-side

added added

removed removed

Lines of Context:
455
455
            _mod_branch.BranchReferenceFormat().get_reference(checkout.bzrdir))
456
456
 
457
457
 
458
 
class TestHooks(tests.TestCase):
 
458
class TestHooks(tests.TestCaseWithTransport):
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" in hooks,
 
473
                        "post_branch not in %s" % hooks)
 
474
        self.assertTrue("post_switch" in hooks,
 
475
                        "post_switch not in %s" % hooks)
472
476
 
473
477
    def test_installed_hooks_are_BranchHooks(self):
474
478
        """The installed hooks object should be a BranchHooks."""
476
480
        self.assertIsInstance(self._preserved_hooks[_mod_branch.Branch][1],
477
481
                              _mod_branch.BranchHooks)
478
482
 
 
483
    def test_post_branch_hook(self):
 
484
        calls = []
 
485
        _mod_branch.Branch.hooks.install_named_hook('post_branch', lambda params, c=calls: c.append(params), None)
 
486
        self.assertLength(0, calls)
 
487
        branch = self.make_branch('a')
 
488
        self.assertLength(1, calls)
 
489
        params = calls[0]
 
490
        self.assertIsInstance(params, _mod_branch.BranchHookParams)
 
491
        self.assertTrue(hasattr(params, 'bzrdir'))
 
492
        self.assertTrue(hasattr(params, 'branch'))
 
493
 
 
494
    def test_post_switch_hook(self):
 
495
        from bzrlib import switch
 
496
        calls = []
 
497
        _mod_branch.Branch.hooks.install_named_hook('post_switch', lambda params, c=calls: c.append(params), None)
 
498
        tree = self.make_branch_and_tree('branch-1')
 
499
        self.build_tree(['branch-1/file-1'])
 
500
        tree.add('file-1')
 
501
        tree.commit('rev1')
 
502
        to_branch = tree.bzrdir.sprout('branch-2').open_branch()
 
503
        self.build_tree(['branch-1/file-2'])
 
504
        tree.add('file-2')
 
505
        tree.remove('file-1')
 
506
        tree.commit('rev2')
 
507
        checkout = tree.branch.create_checkout('checkout')
 
508
        self.assertLength(0, calls)
 
509
        switch.switch(checkout.bzrdir, to_branch)
 
510
        self.assertLength(1, calls)
 
511
        params = calls[0]
 
512
        self.assertIsInstance(params, _mod_branch.SwitchHookParams)
 
513
        self.assertTrue(hasattr(params, 'to_branch'))
 
514
        self.assertTrue(hasattr(params, 'revision_id'))
479
515
 
480
516
class TestPullResult(tests.TestCase):
481
517