def test_only_kwargs(self): pm = PluginManager("he") class Api: def hello(self, arg): "api hook 1" pm.addhooks(Api) pytest.raises(TypeError, lambda: pm.hook.hello(3))
def test_argmismatch(self): class Api: def hello(self, arg): "api hook 1" pm = PluginManager("he") pm.addhooks(Api) class Plugin: def hello(self, argwrong): pass with pytest.raises(PluginValidationError) as exc: pm.register(Plugin()) assert "argwrong" in str(exc.value)
def test_firstresult_definition(self): class Api: def hello(self, arg): "api hook 1" hello.firstresult = True pm = PluginManager("he") pm.addhooks(Api) class Plugin: def hello(self, arg): return arg + 1 pm.register(Plugin()) res = pm.hook.hello(arg=3) assert res == 4
def test_hapmypath(self): class Api: def hello(self, arg): "api hook 1" pm = PluginManager("he") pm.addhooks(Api) hook = pm.hook assert hasattr(hook, 'hello') assert repr(hook.hello).find("hello") != -1 class Plugin: def hello(self, arg): return arg + 1 plugin = Plugin() pm.register(plugin) l = hook.hello(arg=3) assert l == [4] assert not hasattr(hook, 'world') pm.unregister(plugin) assert hook.hello(arg=3) == []