30
32
class TestHooks(TestCase):
34
def test_create_hook_first(self):
36
doc = ("Invoked after changing the tip of a branch object. Called with"
37
"a bzrlib.branch.PostChangeBranchTipParams object")
38
hook = Hook("post_tip_change", doc, (0, 15), None)
39
hooks.create_hook(hook)
40
self.assertEqual(hook, hooks['post_tip_change'])
42
def test_create_hook_name_collision_errors(self):
44
doc = ("Invoked after changing the tip of a branch object. Called with"
45
"a bzrlib.branch.PostChangeBranchTipParams object")
46
hook = Hook("post_tip_change", doc, (0, 15), None)
47
hook2 = Hook("post_tip_change", None, None, None)
48
hooks.create_hook(hook)
49
self.assertRaises(errors.DuplicateKey, hooks.create_hook, hook2)
50
self.assertEqual(hook, hooks['post_tip_change'])
53
"""docs() should return something reasonable about the Hooks."""
56
hook1 = Hook('post_tip_change',
57
"Invoked after the tip of a branch changes. Called with "
58
"a ChangeBranchTipParams object.", (1, 4), None)
59
hook2 = Hook('pre_tip_change',
60
"Invoked before the tip of a branch changes. Called with "
61
"a ChangeBranchTipParams object. Hooks should raise "
62
"TipChangeRejected to signal that a tip change is not permitted.",
64
hooks.create_hook(hook1)
65
hooks.create_hook(hook2)
70
"An old-style hook. For documentation see the __init__ method of 'Hooks'\n"
75
"Introduced in: 1.4\n"
76
"Deprecated in: Not deprecated\n"
78
"Invoked after the tip of a branch changes. Called with a\n"
79
"ChangeBranchTipParams object.\n"
84
"Introduced in: 1.6\n"
85
"Deprecated in: Not deprecated\n"
87
"Invoked before the tip of a branch changes. Called with a\n"
88
"ChangeBranchTipParams object. Hooks should raise TipChangeRejected to\n"
89
"signal that a tip change is not permitted.\n", hooks.docs())
32
91
def test_install_hook_raises_unknown_hook(self):
33
92
"""install_hook should raise UnknownHook if a hook is unknown."""
72
131
hooks['set_rh'] = []
73
132
self.applyDeprecated(one_five, hooks.install_hook, 'set_rh', None)
74
133
self.assertEqual("No hook name", hooks.get_hook_name(None))
136
class TestHook(TestCase):
138
def test___init__(self):
139
doc = ("Invoked after changing the tip of a branch object. Called with"
140
"a bzrlib.branch.PostChangeBranchTipParams object")
141
hook = Hook("post_tip_change", doc, (0, 15), None)
142
self.assertEqual(doc, hook.__doc__)
143
self.assertEqual("post_tip_change", hook.name)
144
self.assertEqual((0, 15), hook.introduced)
145
self.assertEqual(None, hook.deprecated)
146
self.assertEqual([], list(hook))
149
doc = ("Invoked after changing the tip of a branch object. Called with"
150
" a bzrlib.branch.PostChangeBranchTipParams object")
151
hook = Hook("post_tip_change", doc, (0, 15), None)
152
self.assertEqual("post_tip_change\n"
155
"Introduced in: 0.15\n"
156
"Deprecated in: Not deprecated\n"
158
"Invoked after changing the tip of a branch object. Called with a\n"
159
"bzrlib.branch.PostChangeBranchTipParams object\n", hook.docs())
162
hook = Hook("foo", "no docs", None, None)
165
hook.hook(callback, "my callback")
166
self.assertEqual([callback], list(hook))
168
def test___repr(self):
169
# The repr should list all the callbacks, with names.
170
hook = Hook("foo", "no docs", None, None)
173
hook.hook(callback, "my callback")
174
callback_repr = repr(callback)
176
'<bzrlib.hooks.Hook(foo), callbacks=[%s(my callback)]>' %
177
callback_repr, repr(hook))