1
# Copyright (C) 2007, 2009 Canonical Ltd
1
# Copyright (C) 2007-2010 Canonical Ltd
3
3
# This program is free software; you can redistribute it and/or modify
4
4
# it under the terms of the GNU General Public License as published by
24
28
known_hooks_key_to_object,
25
29
known_hooks_key_to_parent_and_attribute,
27
from bzrlib.errors import (
31
from bzrlib.symbol_versioning import (
31
from bzrlib.tests import TestCase
34
class TestHooks(TestCase):
36
class TestHooks(tests.TestCase):
36
38
def test_create_hook_first(self):
98
98
def test_install_named_hook_raises_unknown_hook(self):
100
self.assertRaises(UnknownHook, hooks.install_named_hook, 'silly',
100
self.assertRaises(errors.UnknownHook, hooks.install_named_hook, 'silly',
103
103
def test_install_named_hook_appends_known_hook(self):
113
113
self.assertEqual("demo", hooks.get_hook_name(None))
116
class TestHook(TestCase):
116
class TestHook(tests.TestCase):
118
118
def test___init__(self):
119
119
doc = ("Invoked after changing the tip of a branch object. Called with"
157
156
callback_repr, repr(hook))
160
class TestHookRegistry(TestCase):
159
class TestHookRegistry(tests.TestCase):
162
161
def test_items_are_reasonable_keys(self):
163
162
# All the items in the known_hooks registry need to map from
173
172
new_hooks = factory()
174
173
self.assertIsInstance(obj, Hooks)
175
174
self.assertEqual(type(obj), type(new_hooks))
175
self.assertEqual("No hook name", new_hooks.get_hook_name(None))
177
177
def test_known_hooks_key_to_object(self):
178
178
self.assertIs(branch.Branch.hooks,
179
179
known_hooks_key_to_object(('bzrlib.branch', 'Branch.hooks')))
181
def test_known_hooks_key_to_parent_and_attribute_deprecated(self):
182
self.assertEqual((branch.Branch, 'hooks'),
183
self.applyDeprecated(deprecated_in((2,3)),
184
known_hooks_key_to_parent_and_attribute,
185
('bzrlib.branch', 'Branch.hooks')))
186
self.assertEqual((branch, 'Branch'),
187
self.applyDeprecated(deprecated_in((2,3)),
188
known_hooks_key_to_parent_and_attribute,
189
('bzrlib.branch', 'Branch')))
181
191
def test_known_hooks_key_to_parent_and_attribute(self):
182
192
self.assertEqual((branch.Branch, 'hooks'),
183
known_hooks_key_to_parent_and_attribute(
193
known_hooks.key_to_parent_and_attribute(
184
194
('bzrlib.branch', 'Branch.hooks')))
185
195
self.assertEqual((branch, 'Branch'),
186
known_hooks_key_to_parent_and_attribute(
196
known_hooks.key_to_parent_and_attribute(
187
197
('bzrlib.branch', 'Branch')))