Skip to content

Commit

Permalink
Add an edge case test for firstresult hooks
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
Tyler Goodlet committed Aug 29, 2017
1 parent b289c9e commit 5ab312c
Showing 1 changed file with 35 additions and 0 deletions.
35 changes: 35 additions & 0 deletions testing/test_hookrelay.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,3 +92,38 @@ def hello(self, arg):
pm.register(Plugin3()) # None result is ignored
res = pm.hook.hello(arg=3)
assert res == 2


def test_firstresult_returns_none(pm):
"""If None results are returned by underlying implementations ensure
the multi-call loop returns a None value.
"""
class Api(object):
@hookspec(firstresult=True)
def hello(self, arg):
"api hook 1"

pm.add_hookspecs(Api)

class Plugin1(object):
@hookimpl
def hello(self, arg):
return None

pm.register(Plugin1())
res = pm.hook.hello(arg=3)
assert res == None


def test_firstresult_no_plugin(pm):
"""If no implementations/plugins have been registered for a firstresult
hook the multi-call loop should return a None value.
"""
class Api(object):
@hookspec(firstresult=True)
def hello(self, arg):
"api hook 1"

pm.add_hookspecs(Api)
res = pm.hook.hello(arg=3)
assert res == None

0 comments on commit 5ab312c

Please sign in to comment.