@@ -529,91 +529,6 @@ def cancel_make_transport():
529529
530530class Test_UV_Process (_TestProcess , tb .UVTestCase ):
531531
532- def test_process_lated_stdio_init (self ):
533-
534- class TestProto :
535- def __init__ (self ):
536- self .lost = 0
537- self .stages = []
538-
539- def connection_made (self , transport ):
540- self .stages .append (('CM' , transport ))
541-
542- def pipe_data_received (self , fd , data ):
543- if fd == 1 :
544- self .stages .append (('STDOUT' , data ))
545-
546- def pipe_connection_lost (self , fd , exc ):
547- if fd == 1 :
548- self .stages .append (('STDOUT' , 'LOST' ))
549-
550- def process_exited (self ):
551- self .stages .append ('PROC_EXIT' )
552-
553- def connection_lost (self , exc ):
554- self .stages .append (('CL' , self .lost , exc ))
555- self .lost += 1
556-
557- async def run (** kwargs ):
558- return await self .loop .subprocess_shell (
559- lambda : TestProto (),
560- 'echo 1' ,
561- ** kwargs )
562-
563- with self .subTest ('paused, stdin pipe' ):
564- transport , proto = self .loop .run_until_complete (
565- run (stdin = subprocess .PIPE ,
566- stdout = subprocess .PIPE ,
567- stderr = subprocess .PIPE ,
568- __uvloop_sleep_after_fork = True ))
569- self .assertIsNot (transport , None )
570- self .assertEqual (transport .get_returncode (), 0 )
571- self .assertEqual (
572- set (proto .stages ),
573- {
574- ('CM' , transport ),
575- 'PROC_EXIT' ,
576- ('STDOUT' , b'1\n ' ),
577- ('STDOUT' , 'LOST' ),
578- ('CL' , 0 , None )
579- })
580-
581- with self .subTest ('paused, no stdin' ):
582- transport , proto = self .loop .run_until_complete (
583- run (stdin = None ,
584- stdout = subprocess .PIPE ,
585- stderr = subprocess .PIPE ,
586- __uvloop_sleep_after_fork = True ))
587- self .assertIsNot (transport , None )
588- self .assertEqual (transport .get_returncode (), 0 )
589- self .assertEqual (
590- set (proto .stages ),
591- {
592- ('CM' , transport ),
593- 'PROC_EXIT' ,
594- ('STDOUT' , b'1\n ' ),
595- ('STDOUT' , 'LOST' ),
596- ('CL' , 0 , None )
597- })
598-
599- with self .subTest ('no pause, no stdin' ):
600- transport , proto = self .loop .run_until_complete (
601- run (stdin = None ,
602- stdout = subprocess .PIPE ,
603- stderr = subprocess .PIPE ))
604- self .loop .run_until_complete (transport ._wait ())
605- self .assertEqual (transport .get_returncode (), 0 )
606- self .assertIsNot (transport , None )
607- self .assertEqual (
608- set (proto .stages ),
609- {
610- ('CM' , transport ),
611- 'PROC_EXIT' ,
612- ('STDOUT' , b'1\n ' ),
613- ('STDOUT' , 'LOST' ),
614- ('CL' , 0 , None )
615- })
616-
617532 def test_process_streams_redirect (self ):
618533 # This won't work for asyncio implementation of subprocess
619534
@@ -658,3 +573,92 @@ class TestAsyncio_UV_Process(_AsyncioTests, tb.UVTestCase):
658573
659574class TestAsyncio_AIO_Process (_AsyncioTests , tb .AIOTestCase ):
660575 pass
576+
577+
578+ class Test_UV_Process_Delayed (tb .UVTestCase ):
579+
580+ class TestProto :
581+ def __init__ (self ):
582+ self .lost = 0
583+ self .stages = []
584+
585+ def connection_made (self , transport ):
586+ self .stages .append (('CM' , transport ))
587+
588+ def pipe_data_received (self , fd , data ):
589+ if fd == 1 :
590+ self .stages .append (('STDOUT' , data ))
591+
592+ def pipe_connection_lost (self , fd , exc ):
593+ if fd == 1 :
594+ self .stages .append (('STDOUT' , 'LOST' ))
595+
596+ def process_exited (self ):
597+ self .stages .append ('PROC_EXIT' )
598+
599+ def connection_lost (self , exc ):
600+ self .stages .append (('CL' , self .lost , exc ))
601+ self .lost += 1
602+
603+ async def run_sub (self , ** kwargs ):
604+ return await self .loop .subprocess_shell (
605+ lambda : self .TestProto (),
606+ 'echo 1' ,
607+ ** kwargs )
608+
609+ def test_process_delayed_stdio__paused__stdin_pipe (self ):
610+ transport , proto = self .loop .run_until_complete (
611+ self .run_sub (
612+ stdin = subprocess .PIPE ,
613+ stdout = subprocess .PIPE ,
614+ stderr = subprocess .PIPE ,
615+ __uvloop_sleep_after_fork = True ))
616+ self .assertIsNot (transport , None )
617+ self .assertEqual (transport .get_returncode (), 0 )
618+ self .assertEqual (
619+ set (proto .stages ),
620+ {
621+ ('CM' , transport ),
622+ 'PROC_EXIT' ,
623+ ('STDOUT' , b'1\n ' ),
624+ ('STDOUT' , 'LOST' ),
625+ ('CL' , 0 , None )
626+ })
627+
628+ def test_process_delayed_stdio__paused__no_stdin (self ):
629+ transport , proto = self .loop .run_until_complete (
630+ self .run_sub (
631+ stdin = None ,
632+ stdout = subprocess .PIPE ,
633+ stderr = subprocess .PIPE ,
634+ __uvloop_sleep_after_fork = True ))
635+ self .assertIsNot (transport , None )
636+ self .assertEqual (transport .get_returncode (), 0 )
637+ self .assertEqual (
638+ set (proto .stages ),
639+ {
640+ ('CM' , transport ),
641+ 'PROC_EXIT' ,
642+ ('STDOUT' , b'1\n ' ),
643+ ('STDOUT' , 'LOST' ),
644+ ('CL' , 0 , None )
645+ })
646+
647+ def test_process_delayed_stdio__not_paused__no_stdin (self ):
648+ transport , proto = self .loop .run_until_complete (
649+ self .run_sub (
650+ stdin = None ,
651+ stdout = subprocess .PIPE ,
652+ stderr = subprocess .PIPE ))
653+ self .loop .run_until_complete (transport ._wait ())
654+ self .assertEqual (transport .get_returncode (), 0 )
655+ self .assertIsNot (transport , None )
656+ self .assertEqual (
657+ set (proto .stages ),
658+ {
659+ ('CM' , transport ),
660+ 'PROC_EXIT' ,
661+ ('STDOUT' , b'1\n ' ),
662+ ('STDOUT' , 'LOST' ),
663+ ('CL' , 0 , None )
664+ })
0 commit comments