File tree Expand file tree Collapse file tree 1 file changed +28
-6
lines changed Expand file tree Collapse file tree 1 file changed +28
-6
lines changed Original file line number Diff line number Diff line change @@ -183,24 +183,46 @@ def he_method1(self, arg):
183
183
assert out == [1 , 10 , 120 , 12 ]
184
184
185
185
186
- def test_with_result_memorized (pm ):
186
+ @pytest .mark .parametrize ("result_callback" , [True , False ])
187
+ def test_with_result_memorized (pm , result_callback ):
188
+ """Verify that ``_HookCaller._maybe_apply_history()`
189
+ correctly applies the ``result_callback`` function, when provided,
190
+ to the result from calling each newly registered hook.
191
+ """
192
+ out = []
193
+ if result_callback :
194
+ def callback (res ):
195
+ out .append (res )
196
+ else :
197
+ callback = None
198
+
187
199
class Hooks (object ):
188
200
@hookspec (historic = True )
189
201
def he_method1 (self , arg ):
190
202
pass
203
+
191
204
pm .add_hookspecs (Hooks )
192
205
206
+ class Plugin1 (object ):
207
+ @hookimpl
208
+ def he_method1 (self , arg ):
209
+ return arg * 10
210
+
211
+ pm .register (Plugin1 ())
212
+
193
213
he_method1 = pm .hook .he_method1
194
- he_method1 .call_historic (lambda res : out .append (res ), dict (arg = 1 ))
195
- out = []
214
+ he_method1 .call_historic (proc = callback , kwargs = dict (arg = 1 ))
196
215
197
- class Plugin (object ):
216
+ class Plugin2 (object ):
198
217
@hookimpl
199
218
def he_method1 (self , arg ):
200
219
return arg * 10
201
220
202
- pm .register (Plugin ())
203
- assert out == [10 ]
221
+ pm .register (Plugin2 ())
222
+ if result_callback :
223
+ assert out == [10 , 10 ]
224
+ else :
225
+ assert out == []
204
226
205
227
206
228
def test_with_callbacks_immediately_executed (pm ):
You can’t perform that action at this time.
0 commit comments