File tree Expand file tree Collapse file tree 1 file changed +35
-0
lines changed Expand file tree Collapse file tree 1 file changed +35
-0
lines changed Original file line number Diff line number Diff line change @@ -102,6 +102,41 @@ def hello(self, arg):
102
102
assert res == 2
103
103
104
104
105
+ def test_firstresult_force_result (pm ):
106
+ """Verify forcing a result in a wrapper.
107
+ """
108
+ class Api (object ):
109
+ @hookspec (firstresult = True )
110
+ def hello (self , arg ):
111
+ "api hook 1"
112
+
113
+ pm .add_hookspecs (Api )
114
+
115
+ class Plugin1 (object ):
116
+ @hookimpl
117
+ def hello (self , arg ):
118
+ return arg + 1
119
+
120
+ class Plugin2 (object ):
121
+ @hookimpl (hookwrapper = True )
122
+ def hello (self , arg ):
123
+ assert arg == 3
124
+ outcome = yield
125
+ assert outcome .get_result () == 4
126
+ outcome .force_result (0 )
127
+
128
+ class Plugin3 (object ):
129
+ @hookimpl
130
+ def hello (self , arg ):
131
+ return None
132
+
133
+ pm .register (Plugin1 ())
134
+ pm .register (Plugin2 ()) # wrapper
135
+ pm .register (Plugin3 ()) # ignored since returns None
136
+ res = pm .hook .hello (arg = 3 )
137
+ assert res == 0 # this result is forced and not a list
138
+
139
+
105
140
def test_firstresult_returns_none (pm ):
106
141
"""If None results are returned by underlying implementations ensure
107
142
the multi-call loop returns a None value.
You can’t perform that action at this time.
0 commit comments