~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-04-22 17:08:27 UTC
  • mfrom: (5107.3.8 new_branch_and_repo_hooks)
  • Revision ID: pqm@pqm.ubuntu.com-20100422170827-h0bb41yq5nkosu6t
(vila) Add 'post_repo_init', 'post_branch_init' and 'post_switch' hooks. (Marco Pantaleoni)

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_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)
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_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'))
479
517
 
480
518
class TestPullResult(tests.TestCase):
481
519