Beispiel #1
0
    def test_register(self):
        class BadHook:
            """"""

        class GoodHook(HookBase):
            """"""

        hook = Hook()
        self.assertRaises(AssertionError, hook.register, BadHook)
        self.assertRaises(AssertionError, hook.register, GoodHook("req"))

        hook.register(GoodHook)
        self.assertListEqual(hook._registry, [GoodHook, ])
Beispiel #2
0
    def test_call(self):
        hook = Hook()

        with mock.patch.object(HookProxy, '__init__') as mock_init:
            mock_init.return_value = None
            proxy = hook("foo", extra="bar")
            mock_init.assert_called_once_with(hook._registry, "foo", extra="bar")
            self.assertIsInstance(proxy, HookProxy)
Beispiel #3
0
    def test_unregister(self):
        class GoodHook(HookBase):
            """"""

        hook = Hook()
        hook.register(GoodHook)
        self.assertListEqual(hook._registry, [GoodHook, ])
        hook.unregister(GoodHook)
        self.assertListEqual(hook._registry, [])

        # calling unregister again should do nothing
        hook.unregister(GoodHook)
        self.assertListEqual(hook._registry, [])