Skip to content

Commit 5ab312c

Browse files
author
Tyler Goodlet
committed
Add an edge case test for firstresult hooks
When calling a firstresult hook, if no implementation returns a non-None value a bug is exposed in the new `_MultiCall` which assumes there will be a least one result.
1 parent b289c9e commit 5ab312c

File tree

1 file changed

+35
-0
lines changed

1 file changed

+35
-0
lines changed

testing/test_hookrelay.py

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,3 +92,38 @@ def hello(self, arg):
9292
pm.register(Plugin3()) # None result is ignored
9393
res = pm.hook.hello(arg=3)
9494
assert res == 2
95+
96+
97+
def test_firstresult_returns_none(pm):
98+
"""If None results are returned by underlying implementations ensure
99+
the multi-call loop returns a None value.
100+
"""
101+
class Api(object):
102+
@hookspec(firstresult=True)
103+
def hello(self, arg):
104+
"api hook 1"
105+
106+
pm.add_hookspecs(Api)
107+
108+
class Plugin1(object):
109+
@hookimpl
110+
def hello(self, arg):
111+
return None
112+
113+
pm.register(Plugin1())
114+
res = pm.hook.hello(arg=3)
115+
assert res == None
116+
117+
118+
def test_firstresult_no_plugin(pm):
119+
"""If no implementations/plugins have been registered for a firstresult
120+
hook the multi-call loop should return a None value.
121+
"""
122+
class Api(object):
123+
@hookspec(firstresult=True)
124+
def hello(self, arg):
125+
"api hook 1"
126+
127+
pm.add_hookspecs(Api)
128+
res = pm.hook.hello(arg=3)
129+
assert res == None

0 commit comments

Comments
 (0)