Skip to content

Commit

Permalink
Add baseline test to verify iterable hooks
Browse files Browse the repository at this point in the history
  • Loading branch information
Tyler Goodlet committed Nov 12, 2017
1 parent 5f54615 commit e6d7bd5
Showing 1 changed file with 57 additions and 0 deletions.
57 changes: 57 additions & 0 deletions testing/test_pluginmanager.py
Original file line number Diff line number Diff line change
Expand Up @@ -350,3 +350,60 @@ def m(self, __multicall__, x):
def test_add_hookspecs_nohooks(pm):
with pytest.raises(ValueError):
pm.add_hookspecs(10)


def test_iterable_hooks(pm):
class Hooks(object):
@hookspec
def he_method1(self, arg):
pass

pm.add_hookspecs(Hooks)

l = []

class Plugin1(object):
@hookimpl
def he_method1(self, arg):
l.append(1)
return 1

class Plugin2(object):
@hookimpl
def he_method1(self, arg):
l.append(2)
return 2

class Plugin3(object):
@hookimpl
def he_method1(self, arg):
l.append(3)
return 3

class Plugin4(object):
@hookimpl
def he_method1(self, arg):
l.append(4)
return 4

class PluginWrapper(object):
@hookimpl(hookwrapper=True)
def he_method1(self, arg):
assert not l
outcome = yield
res = outcome.get_result()
assert res
assert res == [1, 2, 3] == l

pm.register(Plugin1())
pm.register(Plugin2())
pm.register(Plugin3())
pm.register(Plugin4())
pm.register(PluginWrapper())

for result, i in zip(pm.ihook.he_method1(arg=None), reversed(range(1, 5))):
assert result == i
if result == 2: # stop before the final iteration
break

assert l == [4, 3, 2]

0 comments on commit e6d7bd5

Please sign in to comment.