Skip to content

Commit

Permalink
Test forcing a result in a wrapper
Browse files Browse the repository at this point in the history
  • Loading branch information
Tyler Goodlet committed Aug 30, 2017
1 parent 9c7246f commit 5c6846f
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 @@ -102,6 +102,41 @@ def hello(self, arg):
assert res == 2


def test_firstresult_force_result(pm):
"""Verify forcing a result in a wrapper.
"""
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 arg + 1

class Plugin2(object):
@hookimpl(hookwrapper=True)
def hello(self, arg):
assert arg == 3
outcome = yield
assert outcome.get_result() == 4
outcome.force_result(0)

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

pm.register(Plugin1())
pm.register(Plugin2()) # wrapper
pm.register(Plugin3()) # ignored since returns None
res = pm.hook.hello(arg=3)
assert res == 0 # this result is forced and not a list


def test_firstresult_returns_none(pm):
"""If None results are returned by underlying implementations ensure
the multi-call loop returns a None value.
Expand Down

0 comments on commit 5c6846f

Please sign in to comment.