From 5c6846f0a9632015e99661515d40f0f523350573 Mon Sep 17 00:00:00 2001 From: Tyler Goodlet Date: Wed, 30 Aug 2017 16:53:56 -0400 Subject: [PATCH] Test forcing a result in a wrapper --- testing/test_hookrelay.py | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/testing/test_hookrelay.py b/testing/test_hookrelay.py index 46ffadae..7d9b6f52 100644 --- a/testing/test_hookrelay.py +++ b/testing/test_hookrelay.py @@ -102,6 +102,41 @@ def hello(self, arg): assert res == 2 +def test_firstresult_force_result(pm): + """Verify forcing a result in a wrapper. + """ + class Api(object): + @hookspec(firstresult=True) + def hello(self, arg): + "api hook 1" + + pm.add_hookspecs(Api) + + class Plugin1(object): + @hookimpl + def hello(self, arg): + return arg + 1 + + class Plugin2(object): + @hookimpl(hookwrapper=True) + def hello(self, arg): + assert arg == 3 + outcome = yield + assert outcome.get_result() == 4 + outcome.force_result(0) + + class Plugin3(object): + @hookimpl + def hello(self, arg): + return None + + pm.register(Plugin1()) + pm.register(Plugin2()) # wrapper + pm.register(Plugin3()) # ignored since returns None + res = pm.hook.hello(arg=3) + assert res == 0 # this result is forced and not a list + + def test_firstresult_returns_none(pm): """If None results are returned by underlying implementations ensure the multi-call loop returns a None value.