def test_hook(self):
        hook = HookPoint("foo", "no docs", None, None)

        def callback():
            pass

        hook.hook(callback, "my callback")
        self.assertEqual([callback], list(hook))
Example #2
0
 def test_uninstall(self):
     hook = HookPoint("foo", "no docs", None, None)
     hook.hook_lazy(
         "bzrlib.tests.test_hooks", "TestHook.lazy_callback",
         "my callback")
     self.assertEqual([TestHook.lazy_callback], list(hook))
     hook.uninstall("my callback")
     self.assertEqual([], list(hook))
Example #3
0
 def test___repr(self):
     # The repr should list all the callbacks, with names.
     hook = HookPoint("foo", "no docs", None, None)
     def callback():
         pass
     hook.hook(callback, "my callback")
     callback_repr = repr(callback)
     self.assertEqual(
         '<HookPoint(foo), callbacks=[%s(my callback)]>' %
         callback_repr, repr(hook))
Example #4
0
 def test_docs(self):
     doc = ("Invoked after changing the tip of a branch object. Called with"
         " a bzrlib.branch.PostChangeBranchTipParams object")
     hook = HookPoint("post_tip_change", doc, (0, 15), None)
     self.assertEqual("post_tip_change\n"
         "~~~~~~~~~~~~~~~\n"
         "\n"
         "Introduced in: 0.15\n"
         "\n"
         "Invoked after changing the tip of a branch object. Called with a\n"
         "bzrlib.branch.PostChangeBranchTipParams object\n", hook.docs())
    def test___repr(self):
        # The repr should list all the callbacks, with names.
        hook = HookPoint("foo", "no docs", None, None)

        def callback():
            pass

        hook.hook(callback, "my callback")
        callback_repr = repr(callback)
        self.assertEqual(
            '<HookPoint(foo), callbacks=[%s(my callback)]>' % callback_repr,
            repr(hook))
 def test_docs(self):
     doc = ("Invoked after changing the tip of a branch object. Called with"
            " a bzrlib.branch.PostChangeBranchTipParams object")
     hook = HookPoint("post_tip_change", doc, (0, 15), None)
     self.assertEqual(
         "post_tip_change\n"
         "~~~~~~~~~~~~~~~\n"
         "\n"
         "Introduced in: 0.15\n"
         "\n"
         "Invoked after changing the tip of a branch object. Called with a\n"
         "bzrlib.branch.PostChangeBranchTipParams object\n", hook.docs())
 def test___init__(self):
     doc = ("Invoked after changing the tip of a branch object. Called with"
            "a bzrlib.branch.PostChangeBranchTipParams object")
     hook = HookPoint("post_tip_change", doc, (0, 15), None)
     self.assertEqual(doc, hook.__doc__)
     self.assertEqual("post_tip_change", hook.name)
     self.assertEqual((0, 15), hook.introduced)
     self.assertEqual(None, hook.deprecated)
     self.assertEqual([], list(hook))
 def test_uninstall(self):
     hook = HookPoint("foo", "no docs", None, None)
     hook.hook_lazy("bzrlib.tests.test_hooks", "TestHook.lazy_callback",
                    "my callback")
     self.assertEqual([TestHook.lazy_callback], list(hook))
     hook.uninstall("my callback")
     self.assertEqual([], list(hook))
 def test_uninstall_unknown(self):
     hook = HookPoint("foo", "no docs", None, None)
     self.assertRaises(KeyError, hook.uninstall, "my callback")
Example #10
0
 def test_install_named_hook_lazy(self):
     hooks = Hooks("bzrlib.tests.hooks", "some_hooks")
     hooks['set_rh'] = HookPoint("set_rh", "doc", (0, 15), None)
     hooks.install_named_hook_lazy('set_rh', 'bzrlib.tests.test_hooks',
                                   'TestHooks.set_rh', "demo")
     self.assertEqual(list(hooks['set_rh']), [TestHooks.set_rh])
Example #11
0
 def test_hook(self):
     hook = HookPoint("foo", "no docs", None, None)
     def callback():
         pass
     hook.hook(callback, "my callback")
     self.assertEqual([callback], list(hook))