File tree Expand file tree Collapse file tree 1 file changed +26
-1
lines changed
Expand file tree Collapse file tree 1 file changed +26
-1
lines changed Original file line number Diff line number Diff line change @@ -562,7 +562,32 @@ def g():
562562 with testset ("MultishotIterator: adapting @multishot to Python's generator API" ):
563563 # basic use
564564 test [[x for x in MultishotIterator (g ())] == [1 , 2 , 3 ]]
565- # TODO: advanced example, exercise all features
565+
566+ # Re-using `g` from above:
567+ mig = MultishotIterator (g ())
568+ test [next (mig ) == 1 ]
569+ k = mig .k # stash the current continuation tracked by the `MultishotIterator`
570+ test [next (mig ) == 2 ]
571+ test [next (mig ) == 3 ]
572+ mig .k = k # multi-shot: rewind to the point we stashed
573+ test [next (mig ) == 2 ]
574+ test [next (mig ) == 3 ]
575+
576+ # Re-using `f` from above:
577+ mif = MultishotIterator (f ())
578+ test [next (mif ) is None ]
579+ k = mif .k
580+ test [next (mif ) == 42 ]
581+ test [next (mif ) is None ]
582+ test [mif .send (23 ) == 42 ]
583+ test_raises [StopIteration , mif .send (17 )]
584+ mif .k = k # rewind
585+ test [next (mif ) == 42 ]
586+ test [next (mif ) is None ]
587+ test [mif .send (23 ) == 42 ]
588+ test_raises [StopIteration , mif .send (17 )]
589+
590+ # TODO: advanced examples, exercise all features
566591
567592if __name__ == '__main__' : # pragma: no cover
568593 with session (__file__ ):
You can’t perform that action at this time.
0 commit comments