~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_hooks.py

  • Committer: Canonical.com Patch Queue Manager
  • Date: 2011-03-31 16:28:11 UTC
  • mfrom: (5622.3.15 more-lazy-hooks)
  • Revision ID: pqm@pqm.ubuntu.com-20110331162811-w1uw1lgpr5fiawp5
(jelmer) Support installing lazy hooks for all existing hook points,
 deprecate Hooks.create_hook. (Jelmer Vernooij)

Show diffs side-by-side

added added

removed removed

Lines of Context:
39
39
class TestHooks(tests.TestCase):
40
40
 
41
41
    def test_create_hook_first(self):
42
 
        hooks = Hooks()
 
42
        hooks = Hooks("bzrlib.tests.test_hooks", "some_hooks")
43
43
        doc = ("Invoked after changing the tip of a branch object. Called with"
44
44
            "a bzrlib.branch.PostChangeBranchTipParams object")
45
45
        hook = HookPoint("post_tip_change", doc, (0, 15), None)
46
 
        hooks.create_hook(hook)
 
46
        self.applyDeprecated(deprecated_in((2, 4)), hooks.create_hook, hook)
47
47
        self.assertEqual(hook, hooks['post_tip_change'])
48
48
 
49
49
    def test_create_hook_name_collision_errors(self):
50
 
        hooks = Hooks()
 
50
        hooks = Hooks("bzrlib.tests.test_hooks", "some_hooks")
51
51
        doc = ("Invoked after changing the tip of a branch object. Called with"
52
52
            "a bzrlib.branch.PostChangeBranchTipParams object")
53
53
        hook = HookPoint("post_tip_change", doc, (0, 15), None)
54
54
        hook2 = HookPoint("post_tip_change", None, None, None)
55
 
        hooks.create_hook(hook)
56
 
        self.assertRaises(errors.DuplicateKey, hooks.create_hook, hook2)
 
55
        self.applyDeprecated(deprecated_in((2, 4)), hooks.create_hook, hook)
 
56
        self.assertRaises(errors.DuplicateKey, self.applyDeprecated,
 
57
            deprecated_in((2, 4, 0)), hooks.create_hook, hook2)
57
58
        self.assertEqual(hook, hooks['post_tip_change'])
58
59
 
59
60
    def test_docs(self):
60
61
        """docs() should return something reasonable about the Hooks."""
61
62
        class MyHooks(Hooks):
62
63
            pass
63
 
        hooks = MyHooks()
 
64
        hooks = MyHooks("bzrlib.tests.test_hooks", "some_hooks")
64
65
        hooks['legacy'] = []
65
 
        hook1 = HookPoint('post_tip_change',
 
66
        hooks.add_hook('post_tip_change',
66
67
            "Invoked after the tip of a branch changes. Called with "
67
 
            "a ChangeBranchTipParams object.", (1, 4), None)
68
 
        hook2 = HookPoint('pre_tip_change',
 
68
            "a ChangeBranchTipParams object.", (1, 4))
 
69
        hooks.add_hook('pre_tip_change',
69
70
            "Invoked before the tip of a branch changes. Called with "
70
71
            "a ChangeBranchTipParams object. Hooks should raise "
71
72
            "TipChangeRejected to signal that a tip change is not permitted.",
72
73
            (1, 6), None)
73
 
        hooks.create_hook(hook1)
74
 
        hooks.create_hook(hook2)
75
74
        self.assertEqualDiff(
76
75
            "MyHooks\n"
77
76
            "-------\n"
99
98
            "signal that a tip change is not permitted.\n", hooks.docs())
100
99
 
101
100
    def test_install_named_hook_raises_unknown_hook(self):
102
 
        hooks = Hooks()
 
101
        hooks = Hooks("bzrlib.tests.test_hooks", "some_hooks")
103
102
        self.assertRaises(errors.UnknownHook, hooks.install_named_hook, 'silly',
104
103
                          None, "")
105
104
 
106
105
    def test_install_named_hook_appends_known_hook(self):
107
 
        hooks = Hooks()
 
106
        hooks = Hooks("bzrlib.tests.test_hooks", "some_hooks")
108
107
        hooks['set_rh'] = []
109
108
        hooks.install_named_hook('set_rh', None, "demo")
110
109
        self.assertEqual(hooks['set_rh'], [None])
111
110
 
112
111
    def test_install_named_hook_and_retrieve_name(self):
113
 
        hooks = Hooks()
 
112
        hooks = Hooks("bzrlib.tests.test_hooks", "somehooks")
114
113
        hooks['set_rh'] = []
115
114
        hooks.install_named_hook('set_rh', None, "demo")
116
115
        self.assertEqual("demo", hooks.get_hook_name(None))
134
133
    set_rh = lambda: None
135
134
 
136
135
    def test_install_named_hook_lazy(self):
137
 
        hooks = Hooks()
 
136
        hooks = Hooks("bzrlib.tests.hooks", "some_hooks")
138
137
        hooks['set_rh'] = HookPoint("set_rh", "doc", (0, 15), None)
139
138
        hooks.install_named_hook_lazy('set_rh', 'bzrlib.tests.test_hooks',
140
139
            'TestHooks.set_rh', "demo")
143
142
    def test_install_named_hook_lazy_old(self):
144
143
        # An exception is raised if a lazy hook is raised for
145
144
        # an old style hook point.
146
 
        hooks = Hooks()
 
145
        hooks = Hooks("bzrlib.tests.hooks", "some_hooks")
147
146
        hooks['set_rh'] = []
148
147
        self.assertRaises(errors.UnsupportedOperation,
149
148
            hooks.install_named_hook_lazy,