From e6d7bd5833a9fe9935ee65f29cc06ae069486095 Mon Sep 17 00:00:00 2001 From: Tyler Goodlet Date: Sun, 12 Nov 2017 18:19:35 -0500 Subject: [PATCH] Add baseline test to verify iterable hooks --- testing/test_pluginmanager.py | 57 +++++++++++++++++++++++++++++++++++ 1 file changed, 57 insertions(+) diff --git a/testing/test_pluginmanager.py b/testing/test_pluginmanager.py index 7e9701b3..a2da7b41 100644 --- a/testing/test_pluginmanager.py +++ b/testing/test_pluginmanager.py @@ -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]