diff --git a/testing/test_hookrelay.py b/testing/test_hookrelay.py index 38c5e2ad..c713caa5 100644 --- a/testing/test_hookrelay.py +++ b/testing/test_hookrelay.py @@ -76,3 +76,32 @@ def hello(self, arg): pm.register(Plugin()) res = pm.hook.hello(arg=3) assert res == 4 + + +def test_defaults(pm): + """Verify that default keyword arguments can be declared on both specs + and impls. The default value look up precedence is up as follows: + - caller provided value + - hookspec default + - hookimpl default + """ + class Api: + @hookspec + def myhook(self, arg, kwarg="default"): + "A spec with a default" + + class Plugin: + @hookimpl + def myhook(self, arg, kwarg="my default"): + return kwarg + + pm.register(Plugin()) + + # with no spec registered + assert pm.hook.myhook(arg='yeah!')[0] == "my default" + assert pm.hook.myhook(arg='yeah!', kwarg='doggy')[0] == "doggy" + + # with spec registered + pm.add_hookspecs(Api) + assert pm.hook.myhook(arg='yeah!')[0] == "default" + assert pm.hook.myhook(arg='yeah!', kwarg='doggy')[0] == "doggy"