Skip to content

Commit e6d7bd5

Browse files
author
Tyler Goodlet
committed
Add baseline test to verify iterable hooks
1 parent 5f54615 commit e6d7bd5

File tree

1 file changed

+57
-0
lines changed

1 file changed

+57
-0
lines changed

Diff for: testing/test_pluginmanager.py

+57
Original file line numberDiff line numberDiff line change
@@ -350,3 +350,60 @@ def m(self, __multicall__, x):
350350
def test_add_hookspecs_nohooks(pm):
351351
with pytest.raises(ValueError):
352352
pm.add_hookspecs(10)
353+
354+
355+
def test_iterable_hooks(pm):
356+
class Hooks(object):
357+
@hookspec
358+
def he_method1(self, arg):
359+
pass
360+
361+
pm.add_hookspecs(Hooks)
362+
363+
l = []
364+
365+
class Plugin1(object):
366+
@hookimpl
367+
def he_method1(self, arg):
368+
l.append(1)
369+
return 1
370+
371+
class Plugin2(object):
372+
@hookimpl
373+
def he_method1(self, arg):
374+
l.append(2)
375+
return 2
376+
377+
class Plugin3(object):
378+
@hookimpl
379+
def he_method1(self, arg):
380+
l.append(3)
381+
return 3
382+
383+
class Plugin4(object):
384+
@hookimpl
385+
def he_method1(self, arg):
386+
l.append(4)
387+
return 4
388+
389+
class PluginWrapper(object):
390+
@hookimpl(hookwrapper=True)
391+
def he_method1(self, arg):
392+
assert not l
393+
outcome = yield
394+
res = outcome.get_result()
395+
assert res
396+
assert res == [1, 2, 3] == l
397+
398+
pm.register(Plugin1())
399+
pm.register(Plugin2())
400+
pm.register(Plugin3())
401+
pm.register(Plugin4())
402+
pm.register(PluginWrapper())
403+
404+
for result, i in zip(pm.ihook.he_method1(arg=None), reversed(range(1, 5))):
405+
assert result == i
406+
if result == 2: # stop before the final iteration
407+
break
408+
409+
assert l == [4, 3, 2]

0 commit comments

Comments
 (0)