@@ -611,55 +611,59 @@ def done():
611611 assert result .status == _Status .ITERATION_FINISHED
612612
613613
614- def test_terate_in_subprocess_initializer_failure ():
615- def src_fn () -> Iterable [int ]:
616- return SourceIterable (10 )
614+ def _src1 () -> Iterable [int ]:
615+ return SourceIterable (10 )
617616
618- def fail () -> None :
619- raise ValueError ("Failed!" )
620617
618+ def _init1 () -> None :
619+ raise ValueError ("Failed!" )
620+
621+
622+ def test_iterate_in_subprocess_initializer_failure ():
621623 with pytest .raises (RuntimeError , match = r"Initializer failed" ):
622- iterate_in_subprocess (src_fn , buffer_size = 1 , timeout = 3 , initializer = fail )
624+ iterate_in_subprocess (_src1 , buffer_size = 1 , timeout = 3 , initializer = _init1 )
623625
624626
625- def test_iterate_in_subprocess_iterator_initialize_failure () :
626- def src_fn () -> Iterator [ int ] :
627+ def _src2 () -> Iterator [ int ] :
628+ if True :
627629 raise ValueError ("Failed!" )
628- return SourceIterable (10 )
630+ return SourceIterable (10 )
631+
629632
633+ def test_iterate_in_subprocess_iterator_initialize_failure ():
630634 with pytest .raises (RuntimeError , match = r"Failed to create the iterable" ):
631- iterate_in_subprocess (src_fn , buffer_size = 1 , timeout = 3 )
635+ iterate_in_subprocess (_src2 , buffer_size = 1 , timeout = 3 )
632636
633637
634- def test_iterate_in_subprocess_generator_fail () :
638+ def _src3 () -> Iterable [ int ] :
635639 class SourceIterableFails (SourceIterable ):
636640 def __iter__ (self ) -> Iterator [int ]:
637641 raise ValueError ("Failed!" )
638642 yield from range (self .n )
639643
640- def src_fn () -> Iterable [ int ]:
641- return SourceIterableFails ( 10 )
644+ return SourceIterableFails ( 10 )
645+
642646
643- ite = iter (iterate_in_subprocess (src_fn , buffer_size = 1 , timeout = 3 ))
647+ def test_iterate_in_subprocess_generator_fail ():
648+ ite = iter (iterate_in_subprocess (_src3 , buffer_size = 1 , timeout = 3 ))
644649
645650 with pytest .raises (RuntimeError , match = r"Failed to fetch the next item" ):
646651 next (ite )
647652
648653
649- def test_iterate_in_subprocess_fail_after_n ():
650- N = 10
651-
654+ def _src4 () -> Iterable [int ]:
652655 class SourceIterableFails (SourceIterable ):
653656 def __iter__ (self ) -> Iterator [int ]:
654657 for v in range (self .n ):
655658 yield v
656659 if v == 2 :
657660 raise ValueError ("Failed!" )
658661
659- def src_fn () -> Iterable [ int ]:
660- return SourceIterableFails ( N )
662+ return SourceIterableFails ( 10 )
663+
661664
662- ite = iter (iterate_in_subprocess (src_fn , buffer_size = 1 , timeout = 3 ))
665+ def test_iterate_in_subprocess_fail_after_n ():
666+ ite = iter (iterate_in_subprocess (_src4 , buffer_size = 1 , timeout = 3 ))
663667 assert next (ite ) == 0
664668 assert next (ite ) == 1
665669 assert next (ite ) == 2
@@ -668,13 +672,14 @@ def src_fn() -> Iterable[int]:
668672 next (ite )
669673
670674
675+ def _src5 (N ) -> Iterable [int ]:
676+ return SourceIterable (N )
677+
678+
671679def test_iterate_in_subprocess_success ():
672680 N = 3
673681
674- def src_fn () -> Iterable [int ]:
675- return SourceIterable (N )
676-
677- hyp = list (iterate_in_subprocess (src_fn , buffer_size = - 1 , timeout = 3 ))
682+ hyp = list (iterate_in_subprocess (partial (_src5 , N ), buffer_size = - 1 , timeout = 3 ))
678683 assert hyp == list (range (N ))
679684
680685
@@ -684,13 +689,12 @@ def __iter__(self):
684689 yield 0
685690
686691
687- def test_iterate_in_subprocess_timeout () :
688- N = 3
692+ def _src6 () -> Iterable [ int ] :
693+ return SleepSourceIterable ( 3 )
689694
690- def src_fn () -> Iterable [int ]:
691- return SleepSourceIterable (N )
692695
693- iterable = iterate_in_subprocess (src_fn , buffer_size = - 1 , timeout = 3 )
696+ def test_iterate_in_subprocess_timeout ():
697+ iterable = iterate_in_subprocess (_src6 , buffer_size = - 1 , timeout = 3 )
694698 iterator = iter (iterable )
695699 with pytest .raises (
696700 RuntimeError , match = r"The worker process did not produce any data for"
0 commit comments