17
17
"""Tests for the core Hooks logic."""
19
from bzrlib import errors
19
from bzrlib import branch, errors
20
20
from bzrlib.hooks import (
24
known_hooks_key_to_object,
25
known_hooks_key_to_parent_and_attribute,
24
27
from bzrlib.errors import (
180
183
self.assertEqual(
181
184
'<HookPoint(foo), callbacks=[%s(my callback)]>' %
182
185
callback_repr, repr(hook))
188
class TestHookRegistry(TestCase):
190
def test_items_are_reasonable_keys(self):
191
# All the items in the known_hooks registry need to map from
192
# (module_name, member_name) tuples to the callable used to get an
193
# empty Hooks of for that attribute. This is used to support the test
194
# suite which needs to generate empty hooks (and HookPoints) to ensure
195
# isolation and prevent tests failing spuriously.
196
for key, factory in known_hooks.items():
197
self.assertTrue(callable(factory),
198
"The factory(%r) for %r is not callable" % (factory, key))
199
obj = known_hooks_key_to_object(key)
200
self.assertIsInstance(obj, Hooks)
201
new_hooks = factory()
202
self.assertIsInstance(obj, Hooks)
203
self.assertEqual(type(obj), type(new_hooks))
205
def test_known_hooks_key_to_object(self):
206
self.assertIs(branch.Branch.hooks,
207
known_hooks_key_to_object(('bzrlib.branch', 'Branch.hooks')))
209
def test_known_hooks_key_to_parent_and_attribute(self):
210
self.assertEqual((branch.Branch, 'hooks'),
211
known_hooks_key_to_parent_and_attribute(
212
('bzrlib.branch', 'Branch.hooks')))
213
self.assertEqual((branch, 'Branch'),
214
known_hooks_key_to_parent_and_attribute(
215
('bzrlib.branch', 'Branch')))