@@ -372,3 +372,60 @@ def example_hook():
372
372
assert getattr (pm .hook , 'example_hook' , None ) # conftest.example_hook should be collected
373
373
assert pm .parse_hookimpl_opts (conftest , 'example_blah' ) is None
374
374
assert pm .parse_hookimpl_opts (conftest , 'example_hook' ) == {}
375
+
376
+
377
+ def test_iterable_hooks (pm ):
378
+ class Hooks (object ):
379
+ @hookspec
380
+ def he_method1 (self , arg ):
381
+ pass
382
+
383
+ pm .add_hookspecs (Hooks )
384
+
385
+ l = []
386
+
387
+ class Plugin1 (object ):
388
+ @hookimpl
389
+ def he_method1 (self , arg ):
390
+ l .append (1 )
391
+ return 1
392
+
393
+ class Plugin2 (object ):
394
+ @hookimpl
395
+ def he_method1 (self , arg ):
396
+ l .append (2 )
397
+ return 2
398
+
399
+ class Plugin3 (object ):
400
+ @hookimpl
401
+ def he_method1 (self , arg ):
402
+ l .append (3 )
403
+ return 3
404
+
405
+ class Plugin4 (object ):
406
+ @hookimpl
407
+ def he_method1 (self , arg ):
408
+ l .append (4 )
409
+ return 4
410
+
411
+ class PluginWrapper (object ):
412
+ @hookimpl (hookwrapper = True )
413
+ def he_method1 (self , arg ):
414
+ assert not l
415
+ outcome = yield
416
+ res = outcome .get_result ()
417
+ assert res
418
+ assert res == [1 , 2 , 3 ] == l
419
+
420
+ pm .register (Plugin1 ())
421
+ pm .register (Plugin2 ())
422
+ pm .register (Plugin3 ())
423
+ pm .register (Plugin4 ())
424
+ pm .register (PluginWrapper ())
425
+
426
+ for result , i in zip (pm .ihook .he_method1 (arg = None ), reversed (range (1 , 5 ))):
427
+ assert result == i
428
+ if result == 2 : # stop before the final iteration
429
+ break
430
+
431
+ assert l == [4 , 3 , 2 ]
0 commit comments