Skip to content

Commit 429c5fc

Browse files
author
Tyler Goodlet
committed
Add a test demonstrating the opt in nature of args
Args are always opt in for hookimpls regardless of whether the spec or call defines more then the impl accepts. Relates to #170
1 parent 6587ed0 commit 429c5fc

File tree

2 files changed

+29
-0
lines changed

2 files changed

+29
-0
lines changed

changelog/172.trivial.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Add a test exemplifying the opt-in nature of spec defined args.

testing/test_invocations.py

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,34 @@ def hello(self, arg):
3939
assert comprehensible in str(exc.value)
4040

4141

42+
def test_opt_in_args(pm):
43+
"""Verfiy that two hookimpls with mutex args can serve
44+
under the same spec.
45+
"""
46+
47+
class Api(object):
48+
@hookspec
49+
def hello(self, arg1, arg2, common_arg):
50+
"api hook 1"
51+
52+
class Plugin1(object):
53+
@hookimpl
54+
def hello(self, arg1, common_arg):
55+
return arg1 + common_arg
56+
57+
class Plugin2(object):
58+
@hookimpl
59+
def hello(self, arg2, common_arg):
60+
return arg2 + common_arg
61+
62+
pm.add_hookspecs(Api)
63+
pm.register(Plugin1())
64+
pm.register(Plugin2())
65+
66+
results = pm.hook.hello(arg1=1, arg2=2, common_arg=0)
67+
assert results == [2, 1]
68+
69+
4270
def test_call_order(pm):
4371
class Api(object):
4472
@hookspec

0 commit comments

Comments
 (0)