Skip to content

Commit cc22337

Browse files
author
Tyler Goodlet
committed
Test historic hook with no callback
Ensure that if a result callback (dubbed `proc` for the moment) provided to `PluginManager.call_historic()` is `None`, no error occurs. Relates to #110
1 parent 91b2193 commit cc22337

File tree

1 file changed

+28
-6
lines changed

1 file changed

+28
-6
lines changed

testing/test_pluginmanager.py

Lines changed: 28 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -183,24 +183,46 @@ def he_method1(self, arg):
183183
assert out == [1, 10, 120, 12]
184184

185185

186-
def test_with_result_memorized(pm):
186+
@pytest.mark.parametrize("result_callback", [True, False])
187+
def test_with_result_memorized(pm, result_callback):
188+
"""Verify that ``_HookCaller._maybe_apply_history()`
189+
correctly applies the ``result_callback`` function, when provided,
190+
to the result from calling each newly registered hook.
191+
"""
192+
out = []
193+
if result_callback:
194+
def callback(res):
195+
out.append(res)
196+
else:
197+
callback = None
198+
187199
class Hooks(object):
188200
@hookspec(historic=True)
189201
def he_method1(self, arg):
190202
pass
203+
191204
pm.add_hookspecs(Hooks)
192205

206+
class Plugin1(object):
207+
@hookimpl
208+
def he_method1(self, arg):
209+
return arg * 10
210+
211+
pm.register(Plugin1())
212+
193213
he_method1 = pm.hook.he_method1
194-
he_method1.call_historic(lambda res: out.append(res), dict(arg=1))
195-
out = []
214+
he_method1.call_historic(proc=callback, kwargs=dict(arg=1))
196215

197-
class Plugin(object):
216+
class Plugin2(object):
198217
@hookimpl
199218
def he_method1(self, arg):
200219
return arg * 10
201220

202-
pm.register(Plugin())
203-
assert out == [10]
221+
pm.register(Plugin2())
222+
if result_callback:
223+
assert out == [10, 10]
224+
else:
225+
assert out == []
204226

205227

206228
def test_with_callbacks_immediately_executed(pm):

0 commit comments

Comments
 (0)