Skip to content

Commit 5c6846f

Browse files
author
Tyler Goodlet
committed
Test forcing a result in a wrapper
1 parent 9c7246f commit 5c6846f

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
@@ -102,6 +102,41 @@ def hello(self, arg):
102102
assert res == 2
103103

104104

105+
def test_firstresult_force_result(pm):
106+
"""Verify forcing a result in a wrapper.
107+
"""
108+
class Api(object):
109+
@hookspec(firstresult=True)
110+
def hello(self, arg):
111+
"api hook 1"
112+
113+
pm.add_hookspecs(Api)
114+
115+
class Plugin1(object):
116+
@hookimpl
117+
def hello(self, arg):
118+
return arg + 1
119+
120+
class Plugin2(object):
121+
@hookimpl(hookwrapper=True)
122+
def hello(self, arg):
123+
assert arg == 3
124+
outcome = yield
125+
assert outcome.get_result() == 4
126+
outcome.force_result(0)
127+
128+
class Plugin3(object):
129+
@hookimpl
130+
def hello(self, arg):
131+
return None
132+
133+
pm.register(Plugin1())
134+
pm.register(Plugin2()) # wrapper
135+
pm.register(Plugin3()) # ignored since returns None
136+
res = pm.hook.hello(arg=3)
137+
assert res == 0 # this result is forced and not a list
138+
139+
105140
def test_firstresult_returns_none(pm):
106141
"""If None results are returned by underlying implementations ensure
107142
the multi-call loop returns a None value.

0 commit comments

Comments
 (0)