~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-02-18 18:13:45 UTC
  • mfrom: (5622.1.4 lazy-hooks-pt1)
  • Revision ID: pqm@pqm.ubuntu.com-20110218181345-on7vdomzesup6tos
(jelmer) Add some methods to allow lazy loading of hook callbacks. (Jelmer
 Vernooij)

Show diffs side-by-side

added added

removed removed

Lines of Context:
112
112
        hooks.install_named_hook('set_rh', None, "demo")
113
113
        self.assertEqual("demo", hooks.get_hook_name(None))
114
114
 
 
115
    set_rh = lambda: None
 
116
 
 
117
    def test_install_named_hook_lazy(self):
 
118
        hooks = Hooks()
 
119
        hooks['set_rh'] = HookPoint("set_rh", "doc", (0, 15), None)
 
120
        hooks.install_named_hook_lazy('set_rh', 'bzrlib.tests.test_hooks',
 
121
            'TestHooks.set_rh', "demo")
 
122
        self.assertEqual(list(hooks['set_rh']), [TestHooks.set_rh])
 
123
 
 
124
    def test_install_named_hook_lazy_old(self):
 
125
        # An exception is raised if a lazy hook is raised for
 
126
        # an old style hook point.
 
127
        hooks = Hooks()
 
128
        hooks['set_rh'] = []
 
129
        self.assertRaises(errors.UnsupportedOperation,
 
130
            hooks.install_named_hook_lazy,
 
131
            'set_rh', 'bzrlib.tests.test_hooks', 'TestHooks.set_rh',
 
132
            "demo")
 
133
 
115
134
 
116
135
class TestHook(tests.TestCase):
117
136
 
144
163
        hook.hook(callback, "my callback")
145
164
        self.assertEqual([callback], list(hook))
146
165
 
 
166
    def lazy_callback():
 
167
        pass
 
168
 
 
169
    def test_lazy_hook(self):
 
170
        hook = HookPoint("foo", "no docs", None, None)
 
171
        hook.hook_lazy(
 
172
            "bzrlib.tests.test_hooks", "TestHook.lazy_callback",
 
173
            "my callback")
 
174
        self.assertEqual([TestHook.lazy_callback], list(hook))
 
175
 
147
176
    def test___repr(self):
148
177
        # The repr should list all the callbacks, with names.
149
178
        hook = HookPoint("foo", "no docs", None, None)