+
    Bi                       ^ RI t ^ RI Ht ^ RIHt ^ RIHt ^ RIHt ^ RIHt ^ RIHt ^ RIH	t	 ^ R	I
Ht ^ RIt^ RIt^ RIt^ RIt^ RIt^ RIt^ RIt^ RIt^ RIt^ RIt^ RIt^ RIt^ RIt^ RIt^ RIt^ RIt^ RIt^ RIt^ RIt^ R
IH t   ^ RI!t! ^ RI#t# ^ RI$t$ ^ RI%t% ^ RI&t&]PN                  '       d   ] PP                  ! R4      h]PR                  '       g   ] PP                  ! R4      h]PT                  R8H  t+]+'       d   Rt,MRt,R0t-].]/]03t1]Pd                  RR3s3R t4 ! R R] Pj                  4      t6 ! R R]74      t8 ! R R]Pr                  4      t: ! R R]64      t; ! R R]64      t<R t=] P|                  ! ]+R4       ! R R ]64      4       t?] P                  ! ]+R!4       ! R" R#]64      4       tA ! R$ R%] Pj                  4      tB] P                  ! ]C! ]R&4      R'4       ! R( R)];4      4       tD] P                  ! ]+R*4       ! R+ R,]64      4       tE ! R- R.]64      tF]GR/8X  d   ] P                  ! 4        R# R#   ]" d    Rt! ELi ; i  ]" d    Rt# ELi ; i  ]" d    Rt$ ELi ; i  ]" d    Rt% ELi ; i   Rt& EL; i)1    N)mock)support)check_sanitizer)import_helper)	os_helper)strace_helper)warnings_helper)assert_python_ok)FakePathztest is not helpful for PGOztest module requires subprocesswin32z@import msvcrt; msvcrt.setmode(sys.stdout.fileno(), os.O_BINARY); -cpassc                      \         P                  ! R 4      p V f   R# \        P                  ! V \        P                  4      '       d.   \
        P                  ! V .4      P                  ^ 8X  d   V 3sR# R# R# )trueN)	shutilwhichosaccessX_OK
subprocessrun
returncodeZERO_RETURN_CMD)
shell_trues    +/usr/lib/python3.14/test/test_subprocess.pysetUpModuler   O   sX    f%J
		*bgg&&
|$//14%- 	5 	'    c                   ,   a  ] tR t^Yt o R tR tRtV tR# )BaseTestCasec                0    \         P                  ! 4        R # N)r   reap_childrenselfs   &r   setUpBaseTestCase.setUpZ   s     	r   c                    \         '       g]   \        P                   F  pVP                  4        K  	  \        P                  ! 4        V P                  \        P                  R 4       V P                  4        \        P                  ! 4        R# )zsubprocess._active not emptyN)		mswindowsr   _activewait_cleanupassertFalse
doCleanupsr   r#   )r%   insts   & r   tearDownBaseTestCase.tearDown_   s^    y"**		 +!""$B 	r    N__name__
__module____qualname____firstlineno__r&   r0   __static_attributes____classdictcell____classdict__s   @r   r    r    Y   s      

  
 r   r    c                       ] tR t^ltRtR# )PopenTestExceptionr2   N)r4   r5   r6   r7   r8   r2   r   r   r=   r=   l   s    r   r=   c                   *   a  ] tR t^pt o RtR tRtV tR# )PopenExecuteChildRaisesz]Popen subclass for testing cleanup of subprocess.PIPE filehandles when
_execute_child fails.
c                    \        R 4      h)zForced Exception for Test)r=   )r%   argskwargss   &*,r   _execute_child&PopenExecuteChildRaises._execute_childt   s     !<==r   r2   N)r4   r5   r6   r7   __doc__rC   r8   r9   r:   s   @r   r?   r?   p   s     > >r   r?   c                   	  a  ] tR t^xt o R tR tR tR tR tR t	R t
R tR	 tR
 tR tR tR tR tR tR tR tR tR tR tR tR tR tR tR tR tR tR tR t ]!PD                  ! ]#R4      R 4       t$]!PD                  ! ]#R4      R  4       t%]!PD                  ! ]#R4      R! 4       t&R" t'R# t(R$ t)R% t*R& t+R' t,]!PD                  ! ]#R(4      R) 4       t-]!PD                  ! ]#R(4      R* 4       t.R+ t/]!PD                  ! ]0Pb                  ]0Pd                  8g  R,4      R- 4       t3]!PD                  ! ]0Pb                  ]0Pd                  8g  R,4      ]!PD                  ! ]4Pj                  ! 4       R.4      R/ 4       4       t6R0 t7R1 t8R2 t9R3 t:R4 t;R5 t<R6 t=R7 t>R8 t?R9 t@R: tAR; tBR< tCR= tDR> tER? tF]!P                  ! ]H;'       d
    ]I! ]HR@4      RA4      RB 4       tJ]!P                  ! ]H;'       d
    ]I! ]HR@4      RA4      RC 4       tKRD tL]!P                  ! ]0P                  RE8H  RF4      RG 4       tN]!PD                  ! ]0P                  RE8H  RH4      ]!PD                  ! ]4P                  ! RI4      ^8H  RJ4      ]!PD                  ! ]P! RKRL7      RM4      RN 4       4       4       tQ]!PD                  ! ]4P                  ! RI4      ^8H  RO4      ]!PD                  ! ]P! RKRL7      RM4      RP 4       4       tRRQ tSRR tT]!P                  ! ]0P                  RE8H  RF4      RS 4       tURT tVRU tWRV tXRW tYRX tZRY t[RZ t\R[ t]R\ t^R] t_R^ t`R_ taR` tbRa tcRb tdRc teRd tfRe tgRf thRg tiRh tjRi tkRj tlRk tmRl tnRm toRn tp]qP                  ! Ro4      Rp 4       tsRq ttRr tuRs tvRt twRu txRv tyRw tzRx t{]!P                  ! ]I! ]|Ry4      Rz4      ]!P                  ! ]I! ]}R{4      R|4      ]!P                  ! ]I! ]}R}4      R~4      R 4       4       4       t~]!P                  ! ]}P                  EP                  R]}EP                  ! 4       ,          4      R4      R 4       t]!PD                  ! ]#R4      R 4       t]!PD                  ! ]#R4      R 4       tR t]!P                  ! ]I! ]R4      R4      R 4       tRtV tR# )ProcessTestCasec                   \         P                  ! \        \         P                  \         P                  \         P                  R 7      p V P	                  VP
                  \        P                  4       V P	                  VP                  \        P                  4       V P	                  VP                  \        P                  4       VP
                  P                  4        VP                  P                  4        VP                  P                  4        VP                  4        R#   TP
                  P                  4        TP                  P                  4        TP                  P                  4        TP                  4        i ; i)stdinstdoutstderrN)r   Popenr   PIPEassertIsInstancerJ   ioBufferedIOBaserK   rL   closer+   r%   ps   & r   test_io_buffered_by_default+ProcessTestCase.test_io_buffered_by_defaultz   s    _#-??:??$.OO5	!!!''2+<+<=!!!((B,=,=>!!!((B,=,=>GGMMOHHNNHHNNFFH GGMMOHHNNHHNNFFHs   
A>D( (A Fc                   \         P                  ! \        \         P                  \         P                  \         P                  ^ R7      p V P	                  VP
                  \        P                  4       V P	                  VP                  \        P                  4       V P	                  VP                  \        P                  4       VP
                  P                  4        VP                  P                  4        VP                  P                  4        VP                  4        R#   TP
                  P                  4        TP                  P                  4        TP                  P                  4        TP                  4        i ; i)r   )rJ   rK   rL   bufsizeN)r   rM   r   rN   rO   rJ   rP   	RawIOBaserK   rL   rR   r+   rS   s   & r   test_io_unbuffered_works(ProcessTestCase.test_io_unbuffered_works   s    _#-??:??$.OOQ@	!!!''2<<8!!!((BLL9!!!((BLL9GGMMOHHNNHHNNFFH GGMMOHHNNHHNNFFHs   A>D) )A F	c                x    \         P                  ! \        P                  R R.4      pV P	                  V^/4       R# r   import sys; sys.exit(47)Nr   callsys
executableassertEqualr%   rcs   & r   test_call_seqProcessTestCase.test_call_seq   s0    __cnnd8: ;R r   c                    V P                  \        P                  \        P                  \        P
                  R R.RR7       R# )r   while True: pass皙?timeoutN)assertRaisesr   TimeoutExpiredr`   ra   rb   r$   s   &r   test_call_timeout!ProcessTestCase.test_call_timeout   s7    
 	*33Z__>>41CD"% 	 	'r   c                    \         P                  ! \        P                  R R.RR7       V P	                  R4        \         P                  ! \        P                  R R.^ R7       V P	                  R4       R#   \         P
                   d&   pT P                  R\        T4      4        Rp?LrRp?ii ; i  \         P
                   d'   pT P                  R\        T4      4        Rp?R# Rp?ii ; i)r   zimport time;time.sleep(9)rk   z,Expected TimeoutExpired exception not raisedz
-1 secondsNz	0 seconds)r   r   ra   rb   failrn   assertInstr)r%   es   & r   test_timeout_exception&ProcessTestCase.test_timeout_exception   s    	FNNCNND2MNZ\] IIDE	FNNCNND2MNZ[\ IIDE (( 	0MM,A//	0 (( 	/MM+s1v..	/s.   )A9 )B6 9B3B..B36C1C,,C1c                ^    \         P                  ! \        4      pV P                  V^ 4       R# r   N)r   
check_callr   rc   rd   s   & r   test_check_call_zero$ProcessTestCase.test_check_call_zero   s"    ""?3Qr   c                &   V P                  \        P                  4      ;_uu_ 4       p\        P                  ! \        P
                  R R.4       RRR4       V P                  XP                  P                  ^/4       R#   + '       g   i     L8; ir]   )	rm   r   CalledProcessErrorr{   ra   rb   rc   	exceptionr   r%   cs   & r   test_check_call_nonzero'ProcessTestCase.test_check_call_nonzero   sd    z<<==!!3>>4#=#? @ > 	//4 >=   (B  B	c                   \         P                  ! \        P                  R R.4      pV P	                  RV4       V P                  \        R4      ;_uu_ 4        \         P                  ! . RR7       RRR4       V P                  \        R4      ;_uu_ 4        \         P                  ! . RR7       RRR4       R#   + '       g   i     LQ; i  + '       g   i     R# ; i)	r   print('BDFL')   BDFLz2stdout argument not allowed, it will be overriddenNrK   z1check argument not allowed, it will be overriddenFcheck)r   check_outputra   rb   rt   assertRaisesRegex
ValueErrorr%   outputs   & r   test_check_output!ProcessTestCase.test_check_output   s    ((79gv&##JDF F##Bt4F ##JCE E##Be4E E	F FE E Es   B:C:C
	C	c                &   V P                  \        P                  4      ;_uu_ 4       p\        P                  ! \        P
                  R R.4       RRR4       V P                  XP                  P                  ^4       R#   + '       g   i     L8; i)r   zimport sys; sys.exit(5)N)	rm   r   r   r   ra   rb   rc   r   r   r   s   & r   test_check_output_nonzero)ProcessTestCase.test_check_output_nonzero   sc    z<<==##^^T+DEG > 	//3 >=r   c                    \         P                  ! \        P                  R R.\         P                  R7      pV P                  RV4       R# )r   $import sys; sys.stderr.write('BDFL')rL   r   N)r   r   ra   rb   STDOUTrt   r   s   & r   test_check_output_stderr(ProcessTestCase.test_check_output_stderr   s:    (('MN!((* 	gv&r   c                    \         P                  ! 4       pV P                  VP                  4       VP	                  R 4       VP                  ^ 4       \        P                  ! \        P                  RR.VR7      pV P                  RV4       R# )   pearr   6import sys; sys.stdout.write(sys.stdin.read().upper())rJ      PEARN)tempfileTemporaryFile
addCleanuprR   writeseekr   r   ra   rb   rt   )r%   tfr   s   &  r   test_check_output_stdin_arg+ProcessTestCase.test_check_output_stdin_arg   sl    ##%!


((IK 	gv&r   c                |    \         P                  ! \        P                  R R.RR7      pV P	                  RV4       R# )r   r   r   inputr   Nr   r   ra   rb   rt   r   s   & r   test_check_output_input_arg+ProcessTestCase.test_check_output_input_arg   s7    ((IK 	gv&r   c                |    \         P                  ! \        P                  RR.RR7      pV P	                  RV4       R# )z<input=None has a legacy meaning of input='' on check_output.r   3import sys; print('XX' if sys.stdin.read() else '')Nr   s   XXr   r   ra   rb   assertNotInr   s   & r   test_check_output_input_none,ProcessTestCase.test_check_output_input_none   s9    ((FH 	'r   c                ~    \         P                  ! \        P                  R R.RRR7      pV P	                  RV4       R# )r   r   NT)r   textXXr   r   s   & r   !test_check_output_input_none_text1ProcessTestCase.test_check_output_input_none_text   s;    ((FH' 	v&r   c                ~    \         P                  ! \        P                  R R.RRR7      pV P	                  RV4       R# )r   r   NT)r   universal_newlinesr   r   r   s   & r   /test_check_output_input_none_universal_newlines?ProcessTestCase.test_check_output_input_none_universal_newlines   s;    ((FHt5 	v&r   c                    \         P                  ! \        P                  R R.RRRR7      pV P	                  RV4       R# )r   zprint('foo')Nutf-8ignore)r   encodingerrorsfoor   r   s   & r   ,test_check_output_input_none_encoding_errors<ProcessTestCase.test_check_output_input_none_encoding_errors  s7    ((~6WX? 	eV$r   c                b   V P                  \        4      ;_uu_ 4       p\        P                  ! \        P
                  R R.\        P                  R7      pV P                  R4       RRR4       V P                  RXP                  P                  ^ ,          4       R#   + '       g   i     L?; i)r   print('will not be run')r   z-Expected ValueError when stdout arg supplied.NrK   )rm   r   r   r   ra   rb   rK   rs   rt   r   rA   r%   r   r   s   &  r   test_check_output_stdout_arg,ProcessTestCase.test_check_output_stdout_arg  sw    z**a,,^^T+EF::'F IIEF	 +
 	h 0 0 34 +*s   A	BB.	c                F   \         P                  ! 4       pV P                  VP                  4       VP	                  R 4       VP                  ^ 4       V P                  \        4      ;_uu_ 4       p\        P                  ! \        P                  RR.VRR7      pV P                  R4       RRR4       V P                  RXP                  P                  ^ ,          4       V P                  RVP                  P                  ^ ,          4       R#   + '       g   i     Ll; i)	r   r   r      harerJ   r   7Expected ValueError when stdin and input args supplied.NrJ   r   )r   r   r   rR   r   r   rm   r   r   r   ra   rb   rs   rt   r   rA   r%   r   r   r   s   &   r   &test_check_output_stdin_with_input_arg6ProcessTestCase.test_check_output_stdin_with_input_arg  s    ##%!


z**a,,^^T+EFG-F IIOP	 +
 	gq{{//23gq{{//23 +*s   0<DD 	c                    V P                  \        P                  4      ;_uu_ 4       p\        P                  ! \        P
                  R R.RR7      pRRR4       R#   + '       g   i     R# ; i)r   import time; time.sleep(3600)rj   rk   N)rm   r   rn   r   ra   rb   r   s   &  r   test_check_output_timeout)ProcessTestCase.test_check_output_timeout"  sN    z8899Q,,^^T46!F :999s   *AA-	c                    \         P                  P                  4       pR VR&   \        P                  ! \
        P                  RR.VR7      pV P                  V^4       R# )bananaFRUITr   z5import sys, os;sys.exit(os.getenv("FRUIT")=="banana")envN)r   environcopyr   r`   ra   rb   rc   )r%   newenvre   s   &  r   test_call_kwargs ProcessTestCase.test_call_kwargs*  sT    ""w__cnndGH "() 	Qr   c                   \         P                  ! 4       ;_uu_ 4       pV P                  \        \        P
                  ^R7       \        P
                  P                  P                  P                  p^ .V^,           ,          pV P                  ! \        \        P
                  .VO5!   RRR4       V P                  XP                  4       R4       R#   + '       g   i     L2; i)   )invalid_arg_nameNr   )r   captured_stderrrm   	TypeErrorr   rM   __init____code__co_argcountrc   getvalue)r%   sargcounttoo_many_argss   &   r   test_invalid_args!ProcessTestCase.test_invalid_args4  s     $$&&!i)9)9AN!''0099EEHC8a<0Mi)9)9JMJ	 '
 	r* '&s   BCC%	c                ~   \         P                  ! \        P                  R R.\         P                  \         P                  R7      pV P                  VP                  P                  4       V P                  VP                  P                  4       VP                  4        V P                  VP                  R4       R# )r   print("banana")rK   rL   N)r   rM   ra   rb   rN   r   rK   rR   rL   r+   rc   rJ   rS   s   & r   test_stdin_noneProcessTestCase.test_stdin_none>  ss    cnnd4EF *
I''	$'r   c                   R p\         P                  ! \        P                  RV.\         P                  \         P                  R7      pV P                  VP                  P                  4       V P                  VP                  P                  4       VP                  4       w  r4V P                  VP                  ^ V4       V P                  VP                  4       R4       R# )zimport sys; from subprocess import Popen, PIPE;p = Popen([sys.executable, "-c", "print('test_stdout_none')"],          stdin=PIPE, stderr=PIPE);p.wait(); assert p.stdout is None;r   r   s   test_stdout_noneNr   rM   ra   rb   rN   r   rK   rR   rL   communicaterc   r   rstripr%   coderT   outerrs   &    r   test_stdout_none ProcessTestCase.test_stdout_noneG  s    5 cnndD9$.OOJOOM''==?q#.':;r   c                ~   \         P                  ! \        P                  R R.\         P                  \         P                  R7      pV P                  VP                  P                  4       V P                  VP                  P                  4       VP                  4        V P                  VP                  R4       R# )r   r   rJ   rK   N)r   rM   ra   rb   rN   r   rK   rR   rJ   r+   rc   rL   rS   s   & r   test_stderr_none ProcessTestCase.test_stderr_none^  ss    cnnd4EF)zH'&	4(r   c                    VR .,           p\         P                  ! V3/ VB pVP                  4        V P                  ^/VP                  4       R# r^   N)r   rM   r+   rc   r   )r%   pre_argsrB   rA   rT   s   &&,  r   _assert_pythonProcessTestCase._assert_pythong  sD     566T,V,	Q\\*r   c                    \         P                  P                  \         P                  P                  \        P
                  4      R 4      pV P                  VR.\        P
                  R7       R# doesnotexistr   rb   N)r   pathjoindirnamera   rb   r  r%   r  s   & r   test_executableProcessTestCase.test_executableo  sH     ww||BGGOOCNN$C$24\40S^^Lr   c                
   \         P                  P                  \         P                  P                  \        P
                  4      R 4      pV P                  VR.\         P                  ! \        P
                  4      R7       R# r  )r   r
  r  r  ra   rb   r  fsencoder  s   & r   test_bytes_executable%ProcessTestCase.test_bytes_executablez  sU    ww||BGGOOCNN$C$24\40'){{3>>'B 	 	Dr   c                    \         P                  P                  \         P                  P                  \        P
                  4      R 4      pV P                  VR.\        \        P
                  4      R7       R# r  )r   r
  r  r  ra   rb   r  r   r  s   & r   test_pathlike_executable(ProcessTestCase.test_pathlike_executable  sQ    ww||BGGOOCNN$C$24\40'/'? 	 	Ar   c                    \         P                  R .pV P                  V4       V P                  \        V P                  V\
        ^ ,          R7       R# )r   r	  N)ra   rb   r  rm   NONEXISTING_ERRORSNONEXISTING_CMD)r%   r  s   & r    test_executable_takes_precedence0ProcessTestCase.test_executable_takes_precedence  sI     NND)H%,--x%4Q%7 	 	9r   z"executable argument replaces shellc                J    V P                  . \        P                  R R7       R# T)rb   shellN)r  ra   rb   r$   s   &r   test_executable_replaces_shell.ProcessTestCase.test_executable_replaces_shell  s     	B3>>Fr   c                r    V P                  . \        P                  ! \        P                  4      R R7       R# r  )r  r   r  ra   rb   r$   s   &r   $test_bytes_executable_replaces_shell4ProcessTestCase.test_bytes_executable_replaces_shell  s)    B2;;s~~+F"& 	 	(r   c                \    V P                  . \        \        P                  4      R R7       R# r  )r  r   ra   rb   r$   s   &r   'test_pathlike_executable_replaces_shell7ProcessTestCase.test_pathlike_executable_replaces_shell  s%    B8CNN+C"& 	 	(r   c                    \         P                  ! V4      ;_uu_ 4        \        P                  ! 4       uuR R R 4       #   + '       g   i     R # ; ir"   )r   
change_cwdr   getcwd)r%   cwds   &&r   _normalize_cwdProcessTestCase._normalize_cwd  s-     !!#&&99; '&&&s	   ?A	c                    \         P                  P                  \        P                  4      p\         P                  P                  V4      # r"   )r   r
  realpathra   rb   split)r%   python_paths   & r   _split_python_path"ProcessTestCase._split_python_path  s-    gg&&s~~6ww}}[))r   c                   \         P                  ! VR R.3R\         P                  /VB pV P                  VP                  P
                  4       VP                  4        V P                  ^/VP                  4       \        P                  P                  pV P                  V! V4      V! VP                  P                  4       P                  4       4      4       R# )r   zcimport os, sys; buf = sys.stdout.buffer; buf.write(os.getcwd().encode()); buf.flush(); sys.exit(47)rK   N)r   rM   rN   r   rK   rR   r+   rc   r   r   r
  normcasereaddecode)r%   expected_cwd
python_argrB   rT   r4  s   &&&,  r   _assert_cwdProcessTestCase._assert_cwd  s     j$-. ( &0__( !'( 	'	Q\\*77##,/!!((--/"8"8":;	=r   c                    \         P                  ! 4       pV P                  V4      pV P                  V\        P
                  VR 7       R# r*  N)r   
gettempdirr+  r9  ra   rb   r%   temp_dirs   & r   test_cwdProcessTestCase.test_cwd  s9    &&(&&x03>>x@r   c                    \         P                  ! 4       pV P                  V4      pV P                  V\        P
                  \        P                  ! V4      R 7       R# r<  )r   r>  r+  r9  ra   rb   r   r  r?  s   & r   test_cwd_with_bytes#ProcessTestCase.test_cwd_with_bytes  sB    &&(&&x03>>r{{87LMr   c                    \         P                  ! 4       pV P                  V4      pV P                  V\        P
                  \        V4      R 7       R# r<  )r   r>  r+  r9  ra   rb   r   r?  s   & r   test_cwd_with_pathlike&ProcessTestCase.test_cwd_with_pathlike  s>    &&(&&x03>>x7IJr   z"pending resolution of issue #15533c           	        V P                  4       w  r\        P                  P                  \        P                  V4      p\
        P                  ! 4       ;_uu_ 4       pV P                  \        \        P                  V.4       V P                  \        \        P                  V.VR 7       V P                  V4      pV P                  WVR 7       RRR4       R#   + '       g   i     R# ; ir<  r1  r   r
  r  curdirr   temp_cwdrm   FileNotFoundErrorr   rM   r+  r9  )r%   
python_dirpython_base
rel_python	wrong_dirs   &    r   test_cwd_with_relative_arg*ProcessTestCase.test_cwd_with_relative_arg  s     #'"9"9";
WW\\"))[9
!!Y /1A1A)l,/1A1A)l	  ;,,Z8JZD "!!!s   A3CC,	c           
        V P                  4       w  r\        P                  P                  \        P                  V4      pR p\
        P                  ! 4       ;_uu_ 4       pV P                  \        \        P                  V.VR7       V P                  \        \        P                  V.VVR7       V P                  V4      pV P                  WVVR7       RRR4       R#   + '       g   i     R# ; i)somethingyoudonthaver	  rb   r*  NrJ  )r%   rN  rO  rP  doesntexistrQ  s   &     r   !test_cwd_with_relative_executable1ProcessTestCase.test_cwd_with_relative_executable  s     #'"9"9";
WW\\"))[9
,!!Y /1A1A*m
  D/1A1A*m
"+  - ,,Z8JZ!+  - "!!!s    A7C!!C2	c           	        V P                  4       w  r\        P                  P                  W4      p\        P                  P                  \        P                  V4      p\
        P                  ! 4       ;_uu_ 4       pV P                  \        \        P                  V.VR 7       V P                  V4      pV P                  WSVR 7       RRR4       R#   + '       g   i     R# ; ir<  )r1  r   r
  r  rK  r   r@  rm   rM  r   rM   r+  r9  )r%   rN  rO  
abs_pythonrP  rQ  s   &     r   test_cwd_with_absolute_arg*ProcessTestCase.test_cwd_with_absolute_arg  s     #'"9"9";
WW\\*:
WW\\"))[9
!!Y /1A1A)l	  ;++I6IY	B "!!!s   =ACC%	zTest is not venv-compatiblec                    V P                  4       w  rV P                  V4      pV P                  VR \        P                  VR7       R# )rU  rV  N)r1  r+  r9  ra   rb   )r%   rN  rO  s   &  r   test_executable_with_cwd(ProcessTestCase.test_executable_with_cwd  sG     #'"9"9";
((4
%;$'NN
 	 	Dr   z#need an installed Python. See #7774c                p    V P                  \        P                  ! 4       R \        P                  R7       R# )rU  r	  N)r9  r   r)  ra   rb   r$   s   &r   test_executable_without_cwd+ProcessTestCase.test_executable_without_cwd  s)     	&<$'NN 	 	4r   c                6   \         P                  ! \        P                  R R.\         P                  R7      pVP
                  P                  R4       VP
                  P                  4        VP                  4        V P                  VP                  ^4       R# )r   0import sys; sys.exit(sys.stdin.read() == "pear")r   r   N)r   rM   ra   rb   rN   rJ   r   rR   r+   rc   r   rS   s   & r   test_stdin_pipeProcessTestCase.test_stdin_pipe  sf    cnndKM(oo/ 	
g		q)r   c                   \         P                  ! 4       pV P                  VP                  4       VP	                  4       p\
        P                  ! VR 4       \
        P                  ! V^ ^ 4       \        P                  ! \        P                  RR.VR7      pVP                  4        V P                  VP                  ^4       R# r   r   re  r   N)r   r   r   rR   filenor   r   lseekr   rM   ra   rb   r+   rc   r   r%   r   drT   s   &   r   test_stdin_filedes"ProcessTestCase.test_stdin_filedes  s    ##%!IIK
G
AqcnndKM " 	
q)r   c                T   \         P                  ! 4       pV P                  VP                  4       VP	                  R 4       VP                  ^ 4       \        P                  ! \        P                  RR.VR7      pVP                  4        V P                  VP                  ^4       R# ri  )r   r   r   rR   r   r   r   rM   ra   rb   r+   rc   r   r%   r   rT   s   &  r   test_stdin_fileobj"ProcessTestCase.test_stdin_fileobj,  sz    ##%!


cnndKM!# 	
q)r   c                   \         P                  ! \        P                  R R.\         P                  R7      pV;_uu_ 4        V P                  VP                  P                  4       R4       RRR4       R#   + '       g   i     R# ; ir   &import sys; sys.stdout.write("orange")r      orangeNr   rM   ra   rb   rN   rc   rK   r5  rS   s   & r   test_stdout_pipe ProcessTestCase.test_stdout_pipe8  sW    cnndBD *1 QQXX]]_i8 QQQ   +A77B	c                v   \         P                  ! 4       pV P                  VP                  4       VP	                  4       p\
        P                  ! \        P                  R R.VR7      pVP                  4        \        P                  ! V^ ^ 4       V P                  \        P                  ! VR4      R4       R# )r   rv  r      rw  Nr   r   r   rR   rj  r   rM   ra   rb   r+   r   rk  rc   r5  rl  s   &   r   test_stdout_filedes#ProcessTestCase.test_stdout_filedes@  s    ##%!IIKcnndBD !# 	

AqD)95r   c                :   \         P                  ! 4       pV P                  VP                  4       \        P
                  ! \        P                  R R.VR7      pVP                  4        VP                  ^ 4       V P                  VP                  4       R4       R# ru  r   r   r   rR   r   rM   ra   rb   r+   r   rc   r5  rq  s   &  r   test_stdout_fileobj#ProcessTestCase.test_stdout_fileobjL  sp    ##%!cnndBD "$ 	


I.r   c                   \         P                  ! \        P                  R R.\         P                  R7      pV;_uu_ 4        V P                  VP                  P                  4       R4       RRR4       R#   + '       g   i     R# ; ir   *import sys; sys.stderr.write("strawberry")r   
   strawberryN)r   rM   ra   rb   rN   rc   rL   r5  rS   s   & r   test_stderr_pipe ProcessTestCase.test_stderr_pipeW  sW    cnndFH *1 QQXX]]_m< QQQr{  c                v   \         P                  ! 4       pV P                  VP                  4       VP	                  4       p\
        P                  ! \        P                  R R.VR7      pVP                  4        \        P                  ! V^ ^ 4       V P                  \        P                  ! VR4      R4       R# )r   r  r   r}  r  Nr~  rl  s   &   r   test_stderr_filedes#ProcessTestCase.test_stderr_filedes_  s    ##%!IIKcnndFH !# 	

AqD)=9r   c                :   \         P                  ! 4       pV P                  VP                  4       \        P
                  ! \        P                  R R.VR7      pVP                  4        VP                  ^ 4       V P                  VP                  4       R4       R# r  r  rq  s   &  r   test_stderr_fileobj#ProcessTestCase.test_stderr_fileobjk  sp    ##%!cnndFH "$ 	


M2r   c                6   \         P                  ! \        P                  R R.\         P                  \         P                  R7      pVP                  4       w  r#V P                  VR4       V P                  VR4       V P                  VP                  ^ 4       R# )r   zimport sys, subprocess;rc = subprocess.call([sys.executable, "-c",    "import sys;"    "sys.stderr.write('42')"],    stderr=subprocess.STDOUT);sys.exit(rc)r   s   42r   Nr   rM   ra   rb   rN   r   rc   r   r%   rT   rK   rL   s   &   r   ,test_stderr_redirect_with_no_stdout_redirect<ProcessTestCase.test_stderr_redirect_with_no_stdout_redirectv  sy     cnnd-. %/OO$.OO5 '%q)r   c                4   \         P                  ! \        P                  R R.\         P                  \         P
                  R7      pV;_uu_ 4        V P                  VP                  P                  4       R4       RRR4       R#   + '       g   i     R# ; ir   Rimport sys;sys.stdout.write("apple");sys.stdout.flush();sys.stderr.write("orange")r   s   appleorangeN)	r   rM   ra   rb   rN   r   rc   rK   r5  rS   s   & r   test_stdout_stderr_pipe'ProcessTestCase.test_stdout_stderr_pipe  sc    cnnd;<
 %/OO$.$5$57 QQXX]]_n= QQQs   +BB	c                <   \         P                  ! 4       pV P                  VP                  4       \        P
                  ! \        P                  R R.VVR7      pVP                  4        VP                  ^ 4       V P                  VP                  4       R4       R# r  r  rq  s   &  r   test_stdout_stderr_file'ProcessTestCase.test_stdout_stderr_file  sv    ##%!cnnd;<
 %'$&( 	


N3r   c                   R p\         P                  ! \        P                  RV.\         P                  \         P                  R7      pV P                  VP                  P                  4       V P                  VP                  P                  4       VP                  4       w  r4V P                  VP                  ^ V4       V P                  VP                  4       R4       R# )zimport sys, subprocess; rc = subprocess.call([sys.executable, "-c",     "import os, sys; sys.exit(os.write(sys.stdout.fileno(), b'test with stdout=1'))"], stdout=1); assert rc == 18r   r   s   test with stdout=1Nr   r   s   &    r   test_stdout_filedes_of_stdout-ProcessTestCase.test_stdout_filedes_of_stdout  s    "
 cnndD9$.OOJOOM''==?q#.'<=r   c                    \         P                  ! \        P                  R R.\         P                  R7      pVP                  4        V P                  VP                  R4       R# )r   z'for i in range(10240):print("x" * 1024)r   N)r   rM   ra   rb   DEVNULLr+   rc   rK   rS   s   & r   test_stdout_devnull#ProcessTestCase.test_stdout_devnull  sN    cnnd23 &0%7%79 	
4(r   c                    \         P                  ! \        P                  R R.\         P                  R7      pVP                  4        V P                  VP                  R4       R# )r   z=import sys
for i in range(10240):sys.stderr.write("x" * 1024)r   N)r   rM   ra   rb   r  r+   rc   rL   rS   s   & r   test_stderr_devnull#ProcessTestCase.test_stderr_devnull  sN    cnnd=> &0%7%7	9
 	
4(r   c                    \         P                  ! \        P                  R R.\         P                  R7      pVP                  4        V P                  VP                  R4       R# )r   zimport sys;sys.stdin.read(1)r   N)r   rM   ra   rb   r  r+   rc   rJ   rS   s   & r   test_stdin_devnull"ProcessTestCase.test_stdin_devnull  sN    cnnd23 %/$6$68 	
$'r   F_GETPIPE_SZz%fcntl.F_GETPIPE_SZ required for test.c                   \         P                  ! 4       w  r \        P                  ! V\        P                  4      p\         P                  ! V4       \         P                  ! V4       V^,          p\
        P                  ! 4       pWE8  d   \        P                  ! R4      h\        P                  ! \        P                  RR.\        P                  \        P                  \        P                  VR7      p VP                  VP                  VP                   3 FF  pV P#                  \        P                  ! VP%                  4       \        P                  4      V4       KH  	  VP                  P'                  R4       VP                  P	                  4        VP                  P	                  4        VP                   P	                  4        VP)                  4        VP+                  4        R#   \         P                  ! T4       \         P                  ! T4       i ; i  TP)                  4        TP+                  4        i ; i)   z+default pipesize too small to perform test.r   Qimport sys; sys.stdin.read(); sys.stdout.write("out"); sys.stderr.write("error!")rJ   rK   rL   pipesizer   N)r   pipefcntlr  rR   r   get_pagesizeunittestSkipTestr   rM   ra   rb   rN   rJ   rK   rL   rc   rj  r   killr+   )r%   test_pipe_rtest_pipe_wpipesize_defaultr  pagesize_defaultrT   fifos   &       r   test_pipesizesProcessTestCase.test_pipesizes  s    $&779 	"${{;8J8JKHH[!HH[!#q("//1&##=? ?^^T*+ //*//??X7	!((AHH5  KKu/A/AB 6 GGMM'"GGMMOHHNNHHNNFFHFFH7 HH[!HH[!2 FFHFFHs   %G3 ;CH$ 3.H!$"Ic                   \         P                  ! \        P                  R R.\         P                  \         P                  \         P                  RR7      pT;_uu_ 4         \
        P                  ! 4       w  r# \        P                  ! V\        P                  4      p\        P                  ! V\        P                  4      p\
        P                  ! V4       \
        P                  ! V4       V P                  \        P                  ! VP                  P                  4       \        P                  4      V4       V P                  \        P                  ! VP                  P                  4       \        P                  4      V4       V P                  \        P                  ! VP                  P                  4       \        P                  4      V4       VP                  4         RRR4       R#   \
        P                  ! T4       \
        P                  ! T4       i ; i  TP                  4        i ; i  + '       g   i     R# ; i)r   r  r  Nrr   )r   rM   ra   rb   rN   r   r  r  r  rR   rc   rJ   rj  rK   rL   r  )r%   procfp_rfp_wdefault_read_pipesizedefault_write_pipesizes   &     r   test_pipesize_default%ProcessTestCase.test_pipesize_default  s}    ^^T*+ //*//??R1 TWWY
#,1KKe>P>P,Q)-2[[u?Q?Q-R*HHTNHHTN  KK

 1 1 3U5G5GH)+   KK 2 2 4e6H6HI*,   KK 2 2 4e6H6HI*, 		- T HHTNHHTN 		- TTs>   !H9#H$;A
G3DH$H93.H!!H$$H66H99I
	c                N   \         P                  P                  4       pR VR&   \        P                  ! \
        P                  RR.\        P                  VR7      ;_uu_ 4       pVP                  4       w  r4V P                  VR4       RRR4       R#   + '       g   i     R# ; i)oranger   r   2import sys,os;sys.stdout.write(os.getenv("FRUIT"))rK   r   rw  N)
r   r   r   r   rM   ra   rb   rN   r   rc   r%   r   rT   rK   rL   s   &    r   test_envProcessTestCase.test_env  s    ""ws~~t FG &0__"(	* * ./]]_NFVY/* * * *s   $%BB$	r   zWindows only issuec                j   \         P                  P                  4       pR VR&   RVR&   RVR&   RVR&   \        P                  ! . RO\        P
                  VR7      ;_uu_ 4       pVP                  4       w  r4V P                  VP                  4       R	4       R
R
R
4       R
#   + '       g   i     R
# ; i)cherryfRUitlemonfruitr  r   r   frUitr  s   frUit=bananaNCMDz/cSETr  )	r   r   r   r   rM   rN   r   rc   strip)r%   r   rT   rK   _s   &    r   test_win32_duplicate_envs)ProcessTestCase.test_win32_duplicate_envs$  s    ""w!w"w"w;%/__"(* *-.IFV\\^_=	* * * *s   $3B!!B2	z#cannot test an empty env on WindowsPy_ENABLE_SHAREDzEThe Python shared library cannot be loaded with an empty environment.T)addressz)AddressSanitizer adds to the environment.c                   R p\         P                  ! \        P                  RR.\         P                  / R7      ;_uu_ 4       pVP                  4       w  r4\        VP                  4       4      pV P                  V\        4       V Uu. uF  pV! V4      '       d   K  VNK  	  ppV P                  V. 4       RRR4       R# u upi   + '       g   i     R# ; i)z+Verify that env={} is as empty as possible.c                    RV 9   ;'       g9    RV 9   ;'       g,    V R8H  ;'       g    V P                  R4      ;'       g    V R8H  # )z:Determine if an environment variable is under our control.	VERSIONER__CF
LD_PRELOADSANDBOXLC_CTYPE)
startswith)ns   &r   is_env_var_to_ignore<ProcessTestCase.test_empty_env.<locals>.is_env_var_to_ignore=  sZ    
  1$ $ $! $ $%$ $)*i)@$ $O%r   r   z)import os; print(list(os.environ.keys()))r  N)r   rM   ra   rb   rN   r   evalr  rO   listrc   )r%   r  rT   rK   rL   child_env_namesks   &      r   test_empty_envProcessTestCase.test_empty_env3  s    	% s~~tJL%/__"> >AB]]_NF"6<<>2O!!/48*9 ?/Q&:1&=  !q/O ?_b1> >?> > >s%   AC
CC%CCC	zLThe Python shared library cannot be loaded without some system environments.c           	     x   R R/p\         P                  RR.p\         P                  R8X  d   . ROp\        P                  ! V\        P
                  \        P
                  VR7      ;_uu_ 4       pVP                  4       w  rEVP                  '       dO   \        P                  '       d9   \        RVP                  RR4      4       \        R	VP                  RR4      4       V P                  VP                  ^ 4       V P                  VP                  4       R
4       RRR4       R#   + '       g   i     R# ; i)r  r  r   z;import sys,os;sys.stdout.write("fruit="+os.getenv("fruit"))r   )rK   rL   r   zSTDOUT:asciireplacezSTDERR:s   fruit=orangeNr  )ra   rb   platformr   rM   rN   r   r   r   verboseprintr6  rc   r  )r%   r   cmdrT   rK   rL   s   &     r   test_one_environment_variable-ProcessTestCase.test_one_environment_variableP  s     8$~~t OP <<7"/Cc*//*//W]^^bc]]_NF|||iw	!BCiw	!BCQ\\1-V\\^_= _^^^s   /:D(*A4D((D9	c                   \         P                  R ,           pV P                  \        4      ;_uu_ 4        \        P
                  ! VRR.4       RRR4       V P                  \        4      ;_uu_ 4        \        P
                  ! \         P                  RR.4       RRR4       R#   + '       g   i     L_; i  + '       g   i     R# ; i) r   r   Nzpass# )ra   rb   rm   r   r   rM   )r%   r  s   & r   test_invalid_cmd ProcessTestCase.test_invalid_cmdd  s    nnt#z**c401 + z**cnndI>? +*	 +* +**s   B&4(B9&B6	9C
	c                "   \         P                  P                  4       pR VR&   V P                  \        4      ;_uu_ 4        \
        P                  ! \        VR7       RRR4       \         P                  P                  4       pRVR&   V P                  \        4      ;_uu_ 4        \
        P                  ! \        VR7       RRR4       \         P                  P                  4       pRVR&   V P                  \        4      ;_uu_ 4        \
        P                  ! \        VR7       RRR4       \         P                  P                  4       pRVR&   \
        P                  ! \        P                  R	R
.\
        P                  VR7      ;_uu_ 4       pVP                  4       w  r4V P                  VR4       RRR4       R#   + '       g   i     ELm; i  + '       g   i     EL; i  + '       g   i     L; i  + '       g   i     R# ; i)cabbagezFRUIT VEGETABLEr   Nzorange VEGETABLE=cabbager   r  zFRUIT=ORANGEzorange=lemonr   z3import sys, os;sys.stdout.write(os.getenv("FRUIT"))r  s   orange=lemon)r   r   r   rm   r   r   rM   r   ra   rb   rN   r   rc   r  s   &    r   test_invalid_env ProcessTestCase.test_invalid_envn  sq   "%.!"z**_&9 + "5wz**_&9 + "!(~z**_&9 + "(ws~~t FG &0__"(	* * ./]]_NFV_5* *% +** +** +** * *s0   G&GG*%G=G	G'	*G:	=H	c                   \         P                  P                  4       pR VR&   V P                  \        4      ;_uu_ 4        \
        P                  ! \        VR7       RRR4       \         P                  P                  4       pR VR&   V P                  \        4      ;_uu_ 4        \
        P                  ! \        VR7       RRR4       R#   + '       g   i     Lw; i  + '       g   i     R# ; i)r  zFRUIT=VEGETABLEr   Nz==FRUIT)r   r   r   rm   r   r   rM   r   )r%   r   s   & r   test_win32_invalid_env&ProcessTestCase.test_win32_invalid_env  s     "$- !z**_&9 + "%yz**_&9 +* +*
 +**s   C&C C	 C1	c                    \         P                  ! \        P                  R R.\         P                  R7      pVP                  R4       V P                  VP                  ^4       R# )r   z/import sys;sys.exit(sys.stdin.read() == "pear")r   r   Nr  rS   s   & r   test_communicate_stdin&ProcessTestCase.test_communicate_stdin  sQ    cnndEF $.??4 	
gq)r   c                    \         P                  ! \        P                  R R.\         P                  R7      pVP                  4       w  r#V P                  VR4       V P                  VR4       R# )r   z)import sys; sys.stdout.write("pineapple")r   	   pineappleNr   rM   ra   rb   rN   r   rc   r  s   &   r   test_communicate_stdout'ProcessTestCase.test_communicate_stdout  sZ    cnndIK$.OO5 ==?.&r   c                    \         P                  ! \        P                  R R.\         P                  R7      pVP                  4       w  r#V P                  VR4       V P                  VR4       R# )r   z)import sys; sys.stderr.write("pineapple")r   Nr  r  r  s   &   r   test_communicate_stderr'ProcessTestCase.test_communicate_stderr  sZ    cnndIK$.OO5 ==?&.r   c                   \         P                  ! \        P                  R R.\         P                  \         P                  \         P                  R7      pV P                  VP                  P                  4       V P                  VP                  P                  4       V P                  VP                  P                  4       VP                  R4      w  r#V P                  VR4       V P                  VR4       R# )r   zNimport sys,os;sys.stderr.write("pineapple");sys.stdout.write(sys.stdin.read())rI      bananar  N)r   rM   ra   rb   rN   r   rK   rR   rL   rJ   r   rc   r  s   &   r   test_communicate ProcessTestCase.test_communicate  s    cnndCD $.??$.OO$.OO5 	''&==3+.r   c                   \         P                  ! \        P                  R R.R\         P                  \         P                  \         P                  R7      pV P                  \         P                  VP                  RRR7       VP                  4       w  r#V P                  VR4       V P                  VP                  4       R4       R# )	r   z~import sys,os,time;sys.stderr.write("pineapple\n");time.sleep(1);sys.stderr.write("pear\n");sys.stdout.write(sys.stdin.read())T)r   rJ   rK   rL   r   g333333?rk   s   pineapple
pear
N)
r   rM   ra   rb   rN   rm   rn   r   rc   encoder  s   &   r   test_communicate_timeout(ProcessTestCase.test_communicate_timeout  s    cnndCD 15#-??$.OO$.OO	5 	*33Q]]H"% 	 	' ==?**>?r   c                &   \         P                  ! \        P                  R R.\         P                  R7      pV P                  \         P                  VP                  RR7       VP                  4       w  r#V P                  \        V4      R4       R# )r   zimport sys,os,time;sys.stdout.write("a" * (64 * 1024));time.sleep(0.2);sys.stdout.write("a" * (64 * 1024));time.sleep(0.2);sys.stdout.write("a" * (64 * 1024));time.sleep(0.2);sys.stdout.write("a" * (64 * 1024));r   g?rk   Ni   )
r   rM   ra   rb   rN   rm   rn   r   rc   len)r%   rT   rK   r  s   &   r   %test_communicate_timeout_large_output5ProcessTestCase.test_communicate_timeout_large_output  sq    cnndEF %/OO	5 	*33Q]]CPmmoVm4r   c                   R EF>  pR EF3  pR EF(  p/ pV'       d   \         P                  VR&   V'       d   \         P                  VR&   V'       d   \         P                  VR&   V'       g   Ka  \         P                  ! \        3/ VB pVP	                  4        VP
                  e&   V P                  VP
                  P                  4       VP                  e&   V P                  VP                  P                  4       VP                  f   EK  V P                  VP                  P                  4       EK+  	  EK6  	  EKA  	  R# )FrJ   rK   rL   NFT)
r   rN   rM   r   r   rJ   
assertTrueclosedrK   rL   )r%   
stdin_pipestdout_pipestderr_pipeoptionsrT   s   &     r   test_communicate_pipe_fd_leak-ProcessTestCase.test_communicate_pipe_fd_leak  s    'J,#0K G!+5??(",6OO)",6OO)" "((DGDAMMOww*7xx+8xx+8# $1  - (r   c                    \         P                  ! \        P                  R R.4      pVP	                  4       w  r#V P                  VR4       V P                  VR4       R# r]   )r   rM   ra   rb   r   rc   r  s   &   r   test_communicate_returns(ProcessTestCase.test_communicate_returns  sP    cnnd8: ;==?&&r   c                   \         P                  ! 4       w  r\         P                  ! V4       \         P                  ! V4       \        P                  ! \
        P                  R R\        P                  ,          .\        P                  \        P                  \        P                  R7      pV P                  VP                  P                  4       V P                  VP                  P                  4       V P                  VP                  P                  4       R\        P                  ,          pVP                  V4      w  rVV P                  WT4       R# )r   zpimport sys,os;sys.stdout.write(sys.stdin.read(47));sys.stderr.write("x" * %d);sys.stdout.write(sys.stdin.read())rI      aN)r   r  rR   r   rM   ra   rb   r   PIPE_MAX_SIZErN   r   rK   rL   rJ   r   rc   )r%   xyrT   string_to_writerK   rL   s   &      r   test_communicate_pipe_buf)ProcessTestCase.test_communicate_pipe_buf  s     wwy

cnndC &33	45 $.??$.OO$.OO5 	''&!6!66==91r   c                2   \         P                  ! \        P                  R R.\         P                  \         P                  \         P                  R7      pV P                  VP                  P                  4       V P                  VP                  P                  4       V P                  VP                  P                  4       VP                  P                  R4       VP                  R4      w  r#V P                  VR4       V P                  VR4       R# )r   z0import sys,os;sys.stdout.write(sys.stdin.read())rI   r  s   splits   bananasplitr   N)r   rM   ra   rb   rN   r   rK   rR   rL   rJ   r   r   rc   r  s   &   r   test_writes_before_communicate.ProcessTestCase.test_writes_before_communicate  s    cnndCD $.??$.OO$.OO5 	''&	i ==20%r   c                   \         P                  R R\        ,           R,           .pR EF  p\        P                  ! V3/ R\        P
                  R\        P
                  VR/B pV;_uu_ 4        VP                  P                  R4       VP                  P                  4        V P                  VP                  P                  4       R4       VP                  P                  R4       VP                  P                  4        V P                  VP                  P                  4       V P                  VP                  P                  4       R4       V P                  VP                  P                  ^4      R4       V P                  VP                  P                  4       R	4       R
R
R
4       EK  	  R
#   + '       g   i     EK  ; i)r   import sys,os;a@  buf = sys.stdout.buffer;buf.write(sys.stdin.readline().encode());buf.flush();buf.write(b"line2\n");buf.flush();buf.write(sys.stdin.read().encode());buf.flush();buf.write(b"line4\n");buf.flush();buf.write(b"line5\r\n");buf.flush();buf.write(b"line6\r");buf.flush();buf.write(b"\nline7");buf.flush();buf.write(b"\nline8");rJ   rK   Tzline1
zline3
zline2
zline4
line5
line6
line7
line8N)r   r   )ra   rb   	SETBINARYr   rM   rN   rJ   r   flushrc   rK   readlinerR   r   r5  )r%   rA   extra_kwargrT   s   &   r    test_universal_newlines_and_text0ProcessTestCase.test_universal_newlines_and_text)  sC   NNDy(&&'( :K   >':??*2JOO*5t*= >A i(  !2!2!4i@i(/  !2!2!4!*,  q!1!*,  !DF 	 : s   /D9F77G	c                   \         P                  ! \        P                  R R\        ,           R,           .\         P
                  \         P
                  ^R7      pV P                  VP                  P                  4       V P                  VP                  P                  4       VP                  4       w  r#V P                  VR4       R# )r   r1  zbuf = sys.stdout.buffer;buf.write(b"line2\n");buf.flush();buf.write(b"line4\n");buf.flush();buf.write(b"line5\r\n");buf.flush();buf.write(b"line6\r");buf.flush();buf.write(b"\nline7");buf.flush();buf.write(b"\nline8");)rL   rK   r   z#line2
line4
line5
line6
line7
line8N)r   rM   ra   rb   r2  rN   r   rK   rR   rL   r   rc   r  s   &   r   #test_universal_newlines_communicate3ProcessTestCase.test_universal_newlines_communicateP  s    cnnd.:889 %/OO$.OO01!3" 	''==?C	Er   c                    \         P                  ! \        P                  R R\        ,           \
        P                  ! R4      ,           .\         P                  ^R7      pVP                  R4      w  r#V P                  VP                  ^ 4       R# )r   r1  a  
                               s = sys.stdin.readline()
                               assert s == "line1\n", repr(s)
                               s = sys.stdin.read()
                               assert s == "line3\n", repr(s)
                              )rJ   r   line1
line3
N)r   rM   ra   rb   r2  textwrapdedentrN   r   rc   r   r  s   &   r   )test_universal_newlines_communicate_stdin9ProcessTestCase.test_universal_newlines_communicate_stdini  sq    cnnd.:X__ N" ># #$ $.??013 ==)9:q)r   c                    \         P                  ! \        \         P                  \         P                  R R7      pVP	                  4        V P                  VP                  ^ 4       R# )T)rJ   rK   r   N)r   rM   r   rN   r   rc   r   rS   s   & r   .test_universal_newlines_communicate_input_none>ProcessTestCase.test_universal_newlines_communicate_input_nonew  sF    
 _#-??$.OO046 	
q)r   c                8   \         P                  ! \        P                  R R\        ,           \
        P                  ! R4      ,           .\         P                  \         P                  \         P                  RR7      pV P                  VP                  P                  4       V P                  VP                  P                  4       VP                  R4      w  r#V P                  VP                  ^ 4       V P                  RV4       V P                  VR4       R# )	r   r1  a  
                               s = sys.stdin.buffer.readline()
                               sys.stdout.buffer.write(s)
                               sys.stdout.buffer.write(b"line2\r")
                               sys.stderr.buffer.write(b"eline2\n")
                               s = sys.stdin.buffer.read()
                               sys.stdout.buffer.write(s)
                               sys.stdout.buffer.write(b"line4\n")
                               sys.stdout.buffer.write(b"line5\r\n")
                               sys.stderr.buffer.write(b"eline6\r")
                               sys.stderr.buffer.write(b"eline7\r\nz")
                              T)rJ   rL   rK   r   r<  zline1
line2
line3
line4
line5
zeline2
eline6
eline7
N)r   rM   ra   rb   r2  r=  r>  rN   r   rK   rR   rL   r   rc   r   assertStartsWithr  s   &   r   7test_universal_newlines_communicate_stdin_stdout_stderrGProcessTestCase.test_universal_newlines_communicate_stdin_stdout_stderr  s    cnnd.:X__ N" ># #$ $.??$.OO$.OO04!6" 	''==)9:q)>G 	f&@Ar   c                   R F{  pRV,          p\         P                  RV.p\        P                  ! V\        P                  \        P                  VR7      pVP                  RR7      w  rVV P                  VR4       K}  	  R# )	utf-16z@import sys; sys.stdout.buffer.write('1\r\n2\r3\n4'.encode('%s'))r   )rJ   rK   r   r   r   z1
2
3
4N)rI  z	utf-32-be)ra   rb   r   rM   rN   r   rc   )r%   r   r   rA   popenrK   rL   s   &      r   -test_universal_newlines_communicate_encodings=ProcessTestCase.test_universal_newlines_communicate_encodings  s|     0HLD NND$/D $$T+5??,6OO.68E #..R.8NFV\2 0r   c           	        R	 F  w  rRp\         P                  RV.p\        P                  ! V\        P                  \        P                  RVR7      pVP                  RR7      w  rgV P                  VRP                  V4      4       K  	  R# )
r   r   z2import sys; sys.stdout.buffer.write(b'[\x80\x80]')r   r   )rJ   rK   r   r   r   z[{}]N))r   r   )r  u   ��)surrogateescapeu   )backslashreplacez\x80\x80)ra   rb   r   rM   rN   r   rc   format)r%   r   expectedr   rA   rJ  rK   rL   s   &       r   test_communicate_errors'ProcessTestCase.test_communicate_errors  s    !
F>DNND$/D $$T+5??,6OO.5,2	4E
 #..R.8NFVV]]8%<=%!
r   c                   \         '       g   R pMRp\        '       d    \        P                  ! \        P                  4      w  r#VR8  dX   \        P                  ! \        P                  RV34       V P                  \        P                  \        P                  W#34       . p\        P                  ! 4       p \        V4       F{  p \        P                  P                  V\        P                  4      pVP!                  \        P"                  ! V\        P$                  \        P&                  ,          4      4       K}  	  V P-                  RV,          4       VP/                  4        \        ^
4       F'  p\        P0                  ! VP3                  4       4       K)  	  \        ^4       F  p\4        P6                  ! \8        P:                  RR.\4        P<                  \4        P<                  \4        P<                  R7      p	V	P?                  R4      ^ ,          p
V PA                  V
R4       K  	  V F  p\        P0                  ! V4       K  	  \B        PD                  ! V4       R#   \        \        3 d     ELi ; i  \         d.   pTP(                  \(        P*                  8w  d   h  Rp? EKY  Rp?ii ; i  T F  p\        P0                  ! T4       K  	  \B        PD                  ! T4       i ; i)	i  i  r}  Nz4failed to reach the file descriptor limit (tried %d)r   z-import sys;sys.stdout.write(sys.stdin.read())rI   s   lime)#r)   resource	getrlimitRLIMIT_NOFILE	setrlimitr   OSErrorr   r   mkdtempranger   r
  r  r   TESTFNappendopenO_WRONLYO_CREATerrnoEMFILEskipTestreverserR   popr   rM   ra   rb   rN   r   rc   r   rmtree)r%   max_handlessofthardhandlestmpdiritmpfilerv   rT   datahs   &           r   test_no_leakingProcessTestCase.test_no_leaking  s    yKK8%//0F0FG
$;&&x'='=d|LOOH$6$68N8N%)L2 !!#	";' ggll693C3CDGNN2777BKK

4J#KL (  !#./ 0 OO2Y'  2Y$$cnnd'K&L ,6??,6OO,6OO= }}W-a0  w/   MM&!G Z(   ww%,,.0  MM&!sJ   BI+ ;J> 
A7JC3J> +J ?J J; J6.J> 6J;;J> >7K5c                   V P                  \        P                  ! . RO4      R4       V P                  \        P                  ! . RO4      R4       V P                  \        P                  ! . RO4      R4       V P                  \        P                  ! . RO4      R4       V P                  \        P                  ! . RO4      R4       V P                  \        P                  ! . RO4      R4       V P                  \        P                  ! . RO4      R4       V P                  \        P                  ! RR	.4      R
4       R# )a b cz"a b c" d ez	ab\"c \ dzab\"c " \\" dza\\\b "de fg" hz
a\\\"b c dz"a\\b c" d ez"a\\b\ c" d eabr   zab ""N)rs  rm  rv   )ab"c\rm  )ru  z \rm  )za\\\bzde fgro  )za\"br   rm  )za\\b crm  rv   )za\\b\ crm  rv   )rc   r   list2cmdliner$   s   &r   test_list2cmdline!ProcessTestCase.test_list2cmdline  s    001DE&	(001DE&	(001EF+	-001KL-	/001DE(	*001GH)	+001IJ+	-00$< 	"r   c                   \         P                  ! \        P                  R R.\         P                  R7      pV P                  VP                  P                  4       V P                  VP                  4       4       \        P                  ! VP                  P                  4       R4       VP                  4        V P                  VP                  4       ^ 4       R# )r   zimport os; os.read(0, 1)r      AN)r   rM   ra   rb   rN   r   rJ   rR   assertIsNonepollr   r   rj  r+   rc   rS   s   & r   	test_pollProcessTestCase.test_poll  s    cnnd8:#-??4 	&!&&(#
!4(	1%r   c                    \         P                  ! \        4      pV P                  VP	                  4       ^ 4       V P                  VP	                  4       ^ 4       R# rz   r   rM   r   rc   r+   rS   s   & r   	test_waitProcessTestCase.test_wait  s>    _-1%1%r   c                   \         P                  ! \        P                  R R.4      pV P	                  \         P
                  4      ;_uu_ 4       pVP                  RR7       RRR4       V P                  R\        XP                  4      4       V P                  VP                  \        P                  R7      ^ 4       R#   + '       g   i     Lg; i)r   zimport time; time.sleep(0.3)-C6?rk   Nz0.0001)r   rM   ra   rb   rm   rn   r+   rt   ru   r   rc   r   SHORT_TIMEOUT)r%   rT   r   s   &  r   test_wait_timeout!ProcessTestCase.test_wait_timeout   s    cnn"$BD Ez8899QFF6F" :hAKK 01(=(=>B :9s   CC	c                    V P                  \        4      ;_uu_ 4        \        P                  ! \        R 4       RRR4       R#   + '       g   i     R# ; i)r  N)rm   r   r   rM   r   r$   s   &r   test_invalid_bufsize$ProcessTestCase.test_invalid_bufsize(  s4     y))_h7 *)))s   AA	c                    \         P                  ! \        R 4      pV P                  VP	                  4       ^ 4       \         P                  ! \        R R7      pV P                  VP	                  4       ^ 4       R # )N)rX   r  rS   s   & r   test_bufsize_is_none$ProcessTestCase.test_bufsize_is_none.  sR    _d31%_d;1%r   c           	        \         P                  ! \        P                  R R.\         P                  \         P                  \         P
                  ^VR7      ;_uu_ 4       pVP                  P                  V4       \        P                  ! VP                  P                  4       4       VP                  P                  4       p\        P                  ! 4       ;_uu_ 4         VP                  P                  4        RRR4       RVn        RRR4       V P!                  XP"                  ^ 4       V P!                  XV4       R#   \         d     LTi ; i  + '       g   i     L`; i  + '       g   i     Ld; i)r   zDimport sys;sys.stdout.write(sys.stdin.readline());sys.stdout.flush())rJ   rK   rL   rX   r   N)r   rM   ra   rb   rN   r  rJ   r   r   rR   rj  rK   r4  r   SuppressCrashReportrY  rc   r   )r%   linerQ  r   rT   	read_lines   &&&&  r   _test_bufsize_equal_one'ProcessTestCase._test_bufsize_equal_one6  s   s~~t 64 5 %/OO%/__%/%7%7&'1CE E IJGGMM$HHQWW^^%&))+I,,..GGMMO /
 AG!E" 	q)H-	   /.E EsC    BE(!E	#E=E(EE	EE	E% E((E8	c                0    R pV P                  WRR7       R# )zline
Tr   N)r  r%   r  s   & r    test_bufsize_equal_one_text_mode0ProcessTestCase.test_bufsize_equal_one_text_modeL  s     $$TD$Ir   c                    R \         P                  P                  4       ,           pV P                  \        R4      ;_uu_ 4        V P                  VRRR7       RRR4       R#   + '       g   i     R# ; i)s   linezline bufferingr   Fr  N)r   linesepr  assertWarnsRegexRuntimeWarningr  r  s   & r   "test_bufsize_equal_one_binary_mode2ProcessTestCase.test_bufsize_equal_one_binary_modeR  sT     **,,"">3CDD((su(M EDDDs   A##A4	cpuc           	        \        R 4       Fb  pV P                  \        4      ;_uu_ 4        \        P                  ! \
        \        P                  \        P                  R7       RRR4       Kd  	  R#   + '       g   i     Ky  ; i)r}  r   N)r[  rm   r  r   rM   r  rN   )r%   rl  s   & r   test_leaking_fds_on_error)ProcessTestCase.test_leaking_fds_on_errorY  sT     tA""#566  (2(29 76 666s   :A44Bc                     ^ RI pVP                   \
        P                  ! R\        : R24      p\        P                  RV.p\        P                  ! V\        P                  RR7      pV;_uu_ 4        VP                  4       ^,          pRRR4       V P                  XR4       V P                  VP                  ^ 4       R#   \        \        3 d    T P	                  R4        Li ; i  + '       g   i     Lh; i)	r   Nzneed msvcrt.CrtSetReportModezL
            import msvcrt
            import subprocess

            cmd = a  

            for report_type in [msvcrt.CRT_WARN,
                                msvcrt.CRT_ERROR,
                                msvcrt.CRT_ASSERT]:
                msvcrt.CrtSetReportMode(report_type, msvcrt.CRTDBG_MODE_FILE)
                msvcrt.CrtSetReportFile(report_type, msvcrt.CRTDBG_FILE_STDERR)

            try:
                subprocess.Popen(cmd,
                                 stdout=subprocess.PIPE,
                                 stderr=subprocess.PIPE)
            except OSError:
                pass
        r   T)rL   r   r   )msvcrtCrtSetReportModeAttributeErrorImportErrorrc  r=  r>  r  ra   rb   r   rM   rN   r   rc   r   )r%   r  r   r  r  rL   s   &     r   test_nonexisting_with_pipes+ProcessTestCase.test_nonexisting_with_pipesf  s    	:##  $ #% &		  & ~~tT*'1379 T%%'*F $!,; , 	:MM89	:4 Ts   C 5C-"C*)C*-C=	c           	       a . oV3R  lp\         P                  ! VR7      pVP                  4         V P                  \        4      ;_uu_ 4        \
        P                  ! \        \
        P                  \
        P                  \
        P                  R7       RRR4       VP                  4        RpS F  p \        P                  ! V4       K  	  Ve   VhR#   + '       g   i     LJ; i  \         d   pTp Rp?KL  Rp?ii ; i  TP                  4        RpS F5  p \        P                  ! T4       K    \         d   pTp Rp?K/  Rp?ii ; i	  Te   Thi ; i)c                     < \        ^4       F=  p SP                  \        P                  ! 4       4       \        P
                  ! R4       K?  	  R# )   gMbP?N)r[  extendr   r  timesleep)rl  fdss    r   open_fds<ProcessTestCase.test_double_close_on_error.<locals>.open_fds  s/    2Y

2779%

5! r   )targetrI   N)	threadingThreadstartrm   rY  r   rM   r  rN   r  r   rR   )r%   r  texcfdrv   r  s   &     @r   test_double_close_on_error*ProcessTestCase.test_double_close_on_error  s   	" H-			""7++  '1(2(29 , FFHCHHRL  	 ! ,+  C FFHCHHRL C  	 sf   D A	CD 8C-C*	%D -D8D  DE!D97E9E	E	EE	Ec                <  aa \         P                  ! \        P                  RR.4      oV P	                  SP
                  R4       . oVV3R lp\        P                  ! RV4      pVP                  4        \        '       d   ^pMRpSP                  \        P                  R7       V P	                  SP
                  VRR7       SP                  4        V P	                  SP
                  VR	R7       VP                  4        V P	                  RR
V3RV3.S4       R# )z?Issue21291: Popen.wait() needs to be threadsafe for returncode.r   zimport time; time.sleep(12)Nc                    < SP                  R S P                  4       34       S P                  4        S P                  4        SP                  RS P                  34       S P                  4        SP                  RS P                  34       R# )thread-start-poll-resultthread-after-kill-and-waitthread-after-second-waitN)r]  r}  r  r+   r   )r  resultss   r   kill_proc_timer_threadDProcessTestCase.test_threadsafe_wait.<locals>.kill_proc_timer_thread  sb    NN6		DEIIKIIKNN8$//JKIIKNN6HIr   皙?rk   z*unexpected result in wait from main threadmsgz&unexpected result in second main wait.r  r  i)r  N)r   rM   ra   rb   rc   r   r  Timerr  r)   r+   r   r  r  )r%   r  r  expected_errorcoder  r  s   &   @@r   test_threadsafe_wait$ProcessTestCase.test_threadsafe_wait  s   !>!@ A$/	J OOC!78		9!" "$
 			'//	0*<I 	 	K 			*<E 	 	G 	

 	<79KL57IJL !	"r   c                    R P                  R4      p\        P                  ! \        P                  RV.4      pV P                  VR4       R# );r   s   Hello World!N)zimport subprocess, syszJretcode = subprocess.call([sys.executable, '-c', 'print("Hello World!")'])zassert retcode == 0)r  r   r   ra   rb   rE  )r%   r   r   s   &  r   test_issue8780ProcessTestCase.test_issue8780  sD     xx # $
 ((#..$)EFfo6r   c                   \         P                  ! 4       w  r\         P                  ! 4       w  r4\         P                  ! 4       w  rV \        P                  ! R .WVR7       V P                  \
        P                  P                  V4      4       V P                  \
        P                  P                  V4      4       V P                  \
        P                  P                  V4      4       R#   \         d    \
        P                  ! T4       \
        P                  ! T4       \
        P                  ! T4       \
        P                  ! T4       \
        P                  ! T4       \
        P                  ! T4        ELi ; i)*rI   N)r   mkstempr   rM   rY  r   rR   remover-   r
  exists)r%   ifhandleifnameofhandleofnameefhandleefnames   &      r    test_handles_closed_on_exception0ProcessTestCase.test_handles_closed_on_exception  s     $++-#++-#++-		se8 	/0/0/0  	HHXIIfHHXIIfHHXIIf	s   C- -BF ?F c                   \         P                  ! \        \         P                  \         P                  \         P                  R 7      pV P	                  VP
                  P                  4       V P	                  VP                  P                  4       V P	                  VP                  P                  4       VP                  RR,          4       R# )rI      xN   )
r   rM   r   rN   r   rK   rR   rL   rJ   r   rS   s   & r   test_communicate_epipe&ProcessTestCase.test_communicate_epipe  sw    _#-??$.OO$.OO5 	''&	dUl#r   c                   R	R
R .RRR3. RORRR3\         P                  ! R4      R^R3.p\        P                  P                  P                  \        P                  R4      ;_uu_ 4        V F>  w  r#rE\        P                  ! W#R7      pWFn        V P                  \        V4      V4       K@  	  RRR4       R#   + '       g   i     R# ; i)lsFNz&<Popen: returncode: None args: ['ls']>zP<Popen: returncode: None args: ['ls', '--my-opts', 'aaaaaaaaaaaaaaaaaaaaaaaa...>z
my-tool.pyz4<Popen: returncode: 7 args: <FakePath 'my-tool.py'>>rC   r  )r  T{   z#<Popen: returncode: 123 args: 'ls'>)daaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaTr   zP<Popen: returncode: 0 args: 'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa...>)r  z	--my-optsr  )r   r   r  r   patchobjectr   rM   r   rc   repr)r%   casesr  r  r   sxrT   s   &      r   	test_reprProcessTestCase.test_repr
  s    DaVUD"JK+UD_a-uaCE	
 ]]  ''
(8(8:JKK(-$D$$S6#  a"- ). LKKKs   +AB::C	c                    \         P                  ! \        \         P                  R 7      pV P	                  VP
                  P                  4       VP                  4        VP                  RR,          4       R# )r   r  Nr  )	r   rM   r   rN   r   rJ   rR   r+   r   rS   s   & r   !test_communicate_epipe_only_stdin1ProcessTestCase.test_communicate_epipe_only_stdin  sH    _#-??4&		dUl#r   SIGUSR1zRequires signal.SIGUSR1r  zRequires os.killgetppidzRequires os.getppidc                   R  p\         P                   ! \         P                  V4      pV P                  \         P                   \         P                  V4       \        P                  RR.pR FM  pV\
        P                  /p\
        P                  ! V3/ VB ;_uu_ 4       pVP                  4        RRR4       KO  	  R#   + '       g   i     Kd  ; i)c                     R # r"   r2   )signumframes   &&r   handler7ProcessTestCase.test_communicate_eintr.<locals>.handler+      r   r   z7import os, signal;os.kill(os.getppid(), signal.SIGUSR1)Nr   )	signalr  r   ra   rb   r   rN   rM   r   )r%   r  old_handlerrA   streamkwprocesss   &      r   test_communicate_eintr&ProcessTestCase.test_communicate_eintr#  s    	mmFNNG<v~~{C89 +F*//*B!!$-"--##% .- +---s   !C  C/proc/%d/fdzLinux specificc           	        R\         P                  ! 4       ,          p\         P                  ! V4      pV P                  \        4      ;_uu_ 4        \        \        \        P                  \        P                  \        P                  R7       RRR4       \         P                  ! V4      pV P                  W#4       R#   + '       g   i     L9; i)z;Test for the fork() failure fd leak reported in issue16327.r  rI   N)
r   getpidlistdirrm   r=   r?   r   r   rN   rc   )r%   fd_directoryfds_before_popenfds_after_exceptions   &   r   !test_failed_child_execute_fd_leak1ProcessTestCase.test_failed_child_execute_fd_leak<  s     %ryy{2::l3122##:??%??:??D 3 !jj6)? 32s   >B??C	z+behavior currently not supported on Windowsc                    V P                  \        4      ;_uu_ 4       p\        P                  ! . RO4       RRR4       V P	                  XP
                  P                  R 4       R#   + '       g   i     L8; i)/opt/nonexistent_binaryN)r  withsomerA   )rm   rM  r   r`   rc   r   filenamer   s   & r   %test_file_not_found_includes_filename5ProcessTestCase.test_file_not_found_includes_filenameN  sL    011QOOOP 2--/HI 21s   A''A7	c                    V P                  \        4      ;_uu_ 4       p\        P                  ! R R.RR7       RRR4       V P	                  XP
                  P                  R4       R#   + '       g   i     L8; i)exit0z/some/nonexistent/directoryr=  N)rm   rM  r   rM   rc   r   r  r   s   & r    test_file_not_found_with_bad_cwd0ProcessTestCase.test_file_not_found_with_bad_cwdT  sT    011Qfc]0MN 2--/LM 21s   A))A9	c                    V P                  \        P                  \        ,          \        P
                  4       V P                  \        P                  \        ,          \        P
                  4       R # r"   )rO   r   rM   bytestypesGenericAliasCompletedProcessru   r$   s   &r   test_class_getitems#ProcessTestCase.test_class_getitemsZ  sD    j..u5u7I7IJj99#>@R@RSr   _winapizneed subprocess._winapic           	        \         P                  ! \        4      pT;_uu_ 4        \        P                  P                  \         P                  R \         P                  P                  R7      pV;_uu_ 4       pVP                  R4       VP                  VP                  ^ 4       RVn        RRR4       V P                  VP                  4       ^ 4       RRR4       R#   + '       g   i     L:; i  + '       g   i     R# ; i)WaitForSingleObjectreturn_valueNrr   )r   rM   r   r   r  r  r  WAIT_OBJECT_0r+   assert_called_once_with_handler   rc   )r%   r  r  	mock_waits   &   r   test_wait_negative_timeout*ProcessTestCase.test_wait_negative_timeout^  s     0TJJ%%""%'//== & ?E )		"11$,,B"& 
 TYY[!, T
  TTs$   AC285C	-(C2C/*C22D	r2   N)r4   r5   r6   r7   rU   rZ   rf   ro   rw   r|   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r  r  r  r  r  r  skipIfr)   r  r"  r%  r+  r1  r9  rA  rD  rG  rR  rX  r\  ra   base_prefixprefixr_  	sysconfigis_python_buildrb  rf  rn  rr  ry  r  r  r  r  r  r  r  r  r  r  r  r  
skipUnlessr  hasattrr  r  r  r  r  get_config_varr   r  r  r  r  r  r  r  r
  r  r  r  r   r#  r+  r.  r6  r9  r?  rB  rF  rK  rR  rp  rx  r~  r  r  r  r  r  r  r  r   requires_resourcer  r  r  r  r  r  r  r  r  r  r   r  r
  isdirr  r  r  r  r  r   r&  r8   r9   r:   s   @r   rG   rG   x   s    !'F 
554'
''(''%54! +(<.)+	MDA9 __Y DEG FG
 __Y DE( F( __Y DE( F(
*=&AN
K
 __Y DEE FE __Y DE- F-$C __S__

224D4D __S__

224__Y..0:<4<44**
*9
6	/=
:	3**
>4>&))( AA75.#A@B!B!F AA75.#A@BB@	0 02FG
> H
> __S\\W,:<__Y--.@AQF23 ___T2@B2B3<2, __Y--.@AQF9: ___T2@B>B:
>@6< 02FG
: H
:*'//@&5"9,'2.& %FNE2*
*B83,>*1"f"$	&&C8&.,JN u%
9 &
9'-R:2"h	71(	$."$ 324V,+-Y/.0&0-4&& }ryy{'BC)+@+@  __Y MNJ OJ
 __Y MNN ON
T Y724-4-r   rG   c                      a  ] tR tRt o R tR tR tR tR tR t	R t
R	 tR
 tR tR tR tR tR tR t]P(                  ! ]R4      R 4       tR tR tR tR t]P6                  ! ]R4      R 4       tR tRtV tR# )RunFuncTestCaseio  c                V    \         P                  RV.p\        P                  ! V3/ VB # )z4Run Python code in a subprocess using subprocess.runr   ra   rb   r   r   )r%   r   rB   argvs   &&, r   
run_pythonRunFuncTestCase.run_pythonp  s&    d+~~d-f--r   c                   V P                  R 4      pV P                  VP                  ^/4       V P                  \        P
                  4      ;_uu_ 4        VP                  4        RRR4       R#   + '       g   i     R# ; ir  )r7  rc   r   rm   r   r   check_returncoder%   cps   & r   test_returncodeRunFuncTestCase.test_returncodeu  sW    __78+z<<==! >===s   A00B	c                    V P                  \        P                  4      ;_uu_ 4       pV P                  R RR7       RRR4       V P	                  XP
                  P                  ^/4       R#   + '       g   i     L8; i)r^   Tr   N)rm   r   r   r7  rc   r   r   r   s   & r   
test_checkRunFuncTestCase.test_check|  sT    z<<==OO6dOC >//4 >=s   A,,A<	c                v    \         P                  ! \        R R7      pV P                  VP                  ^ 4       R# )Tr   N)r   r   r   rc   r   r;  s   & r   test_check_zeroRunFuncTestCase.test_check_zero  s&    ^^O48*r   c                    V P                  \        P                  4      ;_uu_ 4        V P                  R RR7       RRR4       R#   + '       g   i     R# ; i)ri   r  rk   N)rm   r   rn   r7  r$   s   &r   test_timeoutRunFuncTestCase.test_timeout  s;    
 z8899OO.O? :999s   AA	c                    V P                  R \        P                  R7      pV P                  RVP                  4       R# )r   r   r   Nr7  r   rN   rt   rK   r;  s   & r   test_capture_stdout#RunFuncTestCase.test_capture_stdout  s*    ___Z___Egryy)r   c                    V P                  R \        P                  R7      pV P                  RVP                  4       R# )r   r   r   N)r7  r   rN   rt   rL   r;  s   & r   test_capture_stderr#RunFuncTestCase.test_capture_stderr  s1    __C$.OO  5gryy)r   c                &   \         P                  ! 4       pV P                  VP                  4       VP	                  R 4       VP                  ^ 4       V P                  RV\        P                  R7      pV P                  RVP                  4       R# )r   r   r   r   N)r   r   r   rR   r   r   r7  r   rN   rt   rK   )r%   r   r<  s   &  r   r   +RunFuncTestCase.test_check_output_stdin_arg  sj    ##%!


__I  2 	gryy)r   c                    V P                  R R\        P                  R7      pV P                  RVP                  4       R# )r   r   )r   rK   r   NrI  r;  s   & r   r   +RunFuncTestCase.test_check_output_input_arg  s5    __Hjoo  7 	gryy)r   c                   \         P                  ! 4       pV P                  VP                  4       VP	                  R 4       VP                  ^ 4       V P                  \        RR7      ;_uu_ 4       pV P                  RVRR7      pRRR4       V P                  RXP                  P                  ^ ,          4       V P                  RVP                  P                  ^ ,          4       R#   + '       g   i     Ll; i)	r   r   r  r   r   r   NrJ   r   )r   r   r   rR   r   r   rm   r   r7  rt   r   rA   r   s   &   r   r   6RunFuncTestCase.test_check_output_stdin_with_input_arg  s    ##%!


zK  M MPQ__%?+-W % >FM 	gq{{//23gq{{//23M Ms   2C++C;	c                    V P                  \        P                  4      ;_uu_ 4       pV P                  R R\        P                  R7      pRRR4       R#   + '       g   i     R# ; i)r   rj   )rl   rK   N)rm   r   rn   r7  rN   )r%   r   r<  s   &  r   r   )RunFuncTestCase.test_check_output_timeout  sI    z8899Q3
 ! 9B :999s   #AA&	c                    \         P                  P                  4       pR VR&   V P                  RVR7      pV P	                  VP
                  ^!4       R# )r   r   zCimport sys, os;sys.exit(33 if os.getenv("FRUIT")=="banana" else 31)r   N)r   r   r   r7  rc   r   )r%   r   r<  s   &  r   test_run_kwargsRunFuncTestCase.test_run_kwargs  sM    ""w__ M!'  ) 	+r   c                   \         '       d   R MRp\        P                  ! V4      pVf   V P                  V R24       \	        V4      p\
        P                  ! V\
        P                  R7      pV P                  VP                  ^ 4       V P                  \        4      ;_uu_ 4        \
        P                  ! V\
        P                  RR7       RRR4       R#   + '       g   i     R# ; i)ztree.comr  Nz required for this testr   T)rK   r  )r)   r   r   rc  r   r   r   r  rc   r   rm   r   )r%   progr
  ress   &   r   test_run_with_pathlike_path+RunFuncTestCase.test_run_with_pathlike_path  s     'YzD||D!<MMTF"9:;~nnT**<*<=+y))NN4
(:(:$G *)))s   )(CC,	c                    \         P                  ! \        P                  4      pVR R.p\        P
                  ! V4      pV P                  VP                  ^94       R# )r   s   import sys; sys.exit(57)N)r   r  ra   rb   r   r   rc   r   r%   r
  rA   r\  s   &   r   &test_run_with_bytes_path_and_arguments6RunFuncTestCase.test_run_with_bytes_path_and_arguments  sC    {{3>>*d78nnT",r   c                    \        \        P                  4      pVR R.p\        P                  ! V4      pV P                  VP                  ^94       R# )r   zimport sys; sys.exit(57)N)r   ra   rb   r   r   rc   r   r`  s   &   r   )test_run_with_pathlike_path_and_arguments9RunFuncTestCase.test_run_with_pathlike_path_and_arguments  s?    'd67nnT",r   z#Maybe test trigger a leak on Ubuntuc                \    \         P                  R R.p\        P                  ! V/ R7       R# )r   r   r   Nr5  )r%   rA   s   & r   test_run_with_an_empty_env*RunFuncTestCase.test_run_with_an_empty_env  s$     f- 	t$r   c                    V P                  R RR7      pV P                  RVP                  4       V P                  RVP                  4       R# )z>import sys;sys.stdout.write('BDFL'); sys.stderr.write('FLUFL')Tcapture_outputr   s   FLUFLN)r7  rt   rK   rL   r;  s   & r   test_capture_output#RunFuncTestCase.test_capture_output  sE    __ : -1  2 	gryy)h		*r   c                    V P                  \        R R7      ;_uu_ 4        V P                  R\        P                  R7       RRR4       R#   + '       g   i     R# ; i)z"STDOUT can only be used for stderrr  r   r   N)rm   r   r7  r   r   r$   s   &r   test_stdout_stdout"RunFuncTestCase.test_stdout_stdout  sQ    z9  < <OO6#-#4#4  6< < < <s   "AA	c                   \         P                  ! 4       pV P                  VP                  4       V P	                  \
        R R7      ;_uu_ 4       pV P                  RRVR7      pRRR4       V P                  RXP                  P                  ^ ,          4       V P                  RVP                  P                  ^ ,          4       R#   + '       g   i     Ll; i)zAExpected ValueError when stdout and capture_output args supplied.r  r   T)rk  rK   NrK   rk  
r   r   r   rR   rm   r   r7  rt   r   rA   r   s   &   r   #test_stdout_with_capture_output_arg3RunFuncTestCase.test_stdout_with_capture_output_arg      ##%!z"  $ $'(__%?59" % FF$
 	h 0 0 34&(8(8(;<$ $   C		C	c                   \         P                  ! 4       pV P                  VP                  4       V P	                  \
        R R7      ;_uu_ 4       pV P                  RRVR7      pRRR4       V P                  RXP                  P                  ^ ,          4       V P                  RVP                  P                  ^ ,          4       R#   + '       g   i     Ll; i)zAExpected ValueError when stderr and capture_output args supplied.r  r   T)rk  rL   NrL   rk  rr  r   s   &   r   #test_stderr_with_capture_output_arg3RunFuncTestCase.test_stderr_with_capture_output_arg  ru  rv  z)requires posix like 'sleep' shell commandc                ^   \         P                  ! 4       p \        P                  ! RRRRR7       V P	                  R4       V P                  XV,
          RRX R	2R
7       R#   \        P
                   d5   p\         P                  ! 4       p\        P                  ! 4       p Rp?LeRp?ii ; i)zJOutput capturing after a timeout mustn't hang forever on open filehandles.zsleep 3Trj   )r  rl   rk  zTimeoutExpired not raised.Ng      ?z/TimeoutExpired was delayed! Bad traceback:
```
z```r  )	r  	monotonicr   r   rs   rn   	traceback
format_exc
assertLess)r%   before_secsr  
after_secsstackss   &    r   .test_run_with_shell_timeout_and_capture_output>RunFuncTestCase.test_run_with_shell_timeout_and_capture_output  s     nn&	4NN9D#*.0 II23
[0#O!(#' 	 	( (( 	,)J))+F	,s   A# #B,8*B''B,c                V   \         P                  ! R 4      p\        P                  ! \        P
                  RRV.RR7      pVP                  P                  4       pV P                  \        V4      ^V4       V P                  V^ ,          R4       V P                  V^,          R4       R# )z            from subprocess import *
            run("echo hello", shell=True, text=True)
            check_output("echo hello", shell=True, text=True)
            z-Xwarn_default_encodingr   Trj  s   <string>:2: EncodingWarning: s   <string>:3: EncodingWarning: N)r=  r>  r   r   ra   rb   rL   
splitlinesrc   r  rE  )r%   r   r<  liness   &   r   test_encoding_warning%RunFuncTestCase.test_encoding_warning$  s       
 ^^S^^-FdS+/1		$$&UQ.eAh(HIeAh(HIr   r2   N) r4   r5   r6   r7   r7  r=  r@  rC  rF  rJ  rM  r   r   r   r   rX  r]  ra  rd  r  r-  r)   rg  rl  ro  rs  rx  r(  r  r  r8   r9   r:   s   @r   r3  r3  o  s     .
"5
+
@*
*
	**49,H-- $IJ% K%+6
=
=  __Y KL( M(J Jr   r3  c                      R F*  p \         '       g   K   \         P                  ! V 4       V u # 	  \        P                  ! R4      h  \         d     KR  i ; i)staffz?No identified group name to use for this test on this platform.)r  nogroupgrpnobody	nfsnobody)r  getgrnamKeyErrorr  r  )
name_groups    r   _get_test_grp_namer  2  sS    H
3Z(  I  abb	  s   AAAzPOSIX specific testsc                     a a ] tR tRt oV 3R ltR tR tR tR t ! R R]	P                  4      t]P                  ! R	4      R
 4       t]P                  ! R	4      R 4       t]P"                  ! ]P&                  P)                  R4      '       * R4      R 4       tR t]P.                  ! ]! ]R4      ;'       d
    ]! ]R4      R4      R 4       t]P.                  ! ]! ]R4      R4      R 4       t]P"                  ! ]! ]R4      R4      R 4       t]P.                  ! ]! ]R4      R4      R 4       t]P"                  ! ]! ]R4      R4      R 4       t]P.                  ! ]! ]R4      R4      R  4       t]P.                  ! ]! ]R4      R4      R! 4       tR" t R# t!]P"                  ! ]";'       g    ]! ]R$4      '       * R%4      R& 4       t#R' t$R( t%R) t&R* t'R+ t(R, t) ! R- R.]	P                  4      t*]P"                  ! ]P&                  P)                  R/4      '       * R04      R1 4       t+R2 t,]P"                  ! ]-P\                  R38H  R44      R5 4       t/R6 t0R7 t1R8 t2R9 t3R: t4R; t5R< t6]P"                  ! ]-P\                  Po                  R4      R=4      R> 4       t8R? t9R@ t:RA t;RB t<RC t=RD t>RE t?RF t@RG tARH tBRI tCRJ tDRK tERL tFRM tGRN tHRO tIRP tJRQ tKRR tLRS tMRT tNRU tORV tPRW tQRX tRRY tSRZ tT]P"                  ! ]-P\                  Po                  R[4      ;'       d:    ]P                  ! R\4      P                  ]P                  ! R]4      P                  8H  R^4      R_ 4       tW]XP                  ! ^
^4      R` 4       tZRa t[Rb t\Rc t]Rd t^Re t_Rf t`Rg taRh tbRi tcRj td]XP                  Rk 4       tf]XP                  Rl 4       tgRm thRn tiRo tjRp tk]P.                  ! ]lRqJ;'       d
    ]! ]lRr4      Rs4      Rt 4       tmRu tnRv toRw tpRx tq]P"                  ! ]rP                  ! Ry4      '       * Rz4      ]tP                  ! 4       ]P                  ! R{R|R}7      R~ 4       4       4       tvRtwVtxV ;ty# )POSIXProcessTestCasei>  c                2   < \         SV `  4        R V n        R# )z/_this/pa.th/does/not/existN)superr&   _nonexistent_dirr%   	__class__s   &r   r&   POSIXProcessTestCase.setUpA  s     =r   c                     \         P                  ! V P                  4       V P                  R V P                  ,          4       X#   \         d   pTp Rp?T# Rp?ii ; i)z,chdir to nonexistent directory %s succeeded.N)r   chdirr  rs   rY  )r%   rv   desired_exceptions   &  r   _get_chdir_exception)POSIXProcessTestCase._get_chdir_exceptionE  s`    		-HHT**+ IID++, -    	" !" ! 	"s    A AAAc                   V P                  4       p \        P                  ! \        P                  RR.V P
                  R7      pV P                  RV,          4       R#   \         d~   pT P                  TP                  TP                  4       T P                  TP                  TP                  4       T P                  TP                  TP                  4        Rp?R# Rp?ii ; i)z;Test error in the child raised in the parent for a bad cwd.r   r   r=  Expected OSError: %sNr  r   rM   ra   rb   r  rs   rY  rc   ra  strerrorr  r%   r  rT   rv   s   &   r   test_exception_cwd'POSIXProcessTestCase.test_exception_cwdR  s     557
	B  #..$!;%)%:%:<A II,/@@A  	E .44agg>.77D.77DD	E   3A C'*A2C""C'c                   V P                  4       p \        P                  ! \        P                  RR.V P
                  R7      pV P                  RV,          4       R#   \         d~   pT P                  TP                  TP                  4       T P                  TP                  TP                  4       T P                  TP                  TP                  4        Rp?R# Rp?ii ; i)zBTest error in the child raised in the parent for a bad executable.r   r   r	  r  Nr  r  s   &   r   test_exception_bad_executable2POSIXProcessTestCase.test_exception_bad_executablea  s     557
	B  #..$!;,0,A,ACA II,/@@A  	E .44agg>.77D.77DD	Er  c                   V P                  4       p \        P                  ! V P                  RR.4      pV P	                  RV,          4       R#   \
         d~   pT P                  TP                  TP                  4       T P                  TP                  TP                  4       T P                  TP                  TP                  4        Rp?R# Rp?ii ; i)z?Test error in the child raised in the parent for a bad args[0].r   r   r  N)
r  r   rM   r  rs   rY  rc   ra  r  r  r  s   &   r   test_exception_bad_args_0.POSIXProcessTestCase.test_exception_bad_args_0p  s     557		B  $"7"7r!BCA II,/@@A  	E .44agg>.77D.77DD	Es   #A CA2CCc                   &   a  ] tR tRt o R tRtV tR# )&POSIXProcessTestCase.PopenNoDestructori  c                    R # r"   r2   r$   s   &r   __del__.POSIXProcessTestCase.PopenNoDestructor.__del__  r  r   r2   N)r4   r5   r6   r7   r  r8   r9   r:   s   @r   PopenNoDestructorr    s     	 	r   r  zsubprocess._fork_execc           	     0   R pW!n         \        P                  ! R\        R7      ;_uu_ 4        V P	                  \
        4      ;_uu_ 4        V P                  R.4       RRR4       RRR4       R#   + '       g   i     L; i  + '       g   i     R# ; i)z>Test error passing done through errpipe_write in the good casec                      V ^,          pRP                  \        P                  4      P                  4       p\        P
                  ! VRV,           R,           4       ^ # )   z{:x}s   OSError:   :)rP  ra  EISDIRr  r   r   )rA   errpipe_writeerr_codes   *  r   proper_errorHPOSIXProcessTestCase.test_exception_errpipe_normal.<locals>.proper_error  sA     HM}}U\\299;HHH]K($:T$ABr   subprocess.os.waitpidside_effectnon_existent_commandN)r  r   r  ChildProcessErrorrm   IsADirectoryErrorr  )r%   	fork_execr  s   && r   test_exception_errpipe_normal2POSIXProcessTestCase.test_exception_errpipe_normal  sp    	 !-ZZ/$57 7""#455&&(>'?@ 67 7557 7 7s#   BA1	B1B<BB	c           	       a RoV3R lpW!n         \        P                  ! R\        R7      ;_uu_ 4        V P	                  \
        P                  4      ;_uu_ 4       pV P                  R.4       RRR4       RRR4       V P                  \        S4      \        XP                  4      4       R#   + '       g   i     LH; i  + '       g   i     LS; i)zRTest error passing done through errpipe_write where its not
in the expected formats    ޭc                  H   < V ^,          p\         P                  ! VS4       ^ # )r  )r   r   )rA   r  
error_datas   * r   	bad_errorGPOSIXProcessTestCase.test_exception_errpipe_bad_data.<locals>.bad_error  s     HM HH]J/r   r  r  r  N)r  r   r  r  rm   r   SubprocessErrorr  rt   r  ru   r   )r%   r  r  rv   r  s   &&  @r   test_exception_errpipe_bad_data4POSIXProcessTestCase.test_exception_errpipe_bad_data  s     )
	 !*ZZ/$57 7"":#=#=>>!&&(>'?@ ?7
 	d:&AKK(89 ?>7 7s#   (CB/	/C/B?:CC	/proc/self/statuszneed /proc/self/statusc                   \         P                  ! R R.RR7      pVP                  4        F  pVP                  R4      '       g   K  Tp M	  V P	                  R4       \         P                  ! R R.RR7      pVP                  4        F  pVP                  R4      '       g   K  Tp M	  V P                  XXRR7       R	# )
catr  F)restore_signalss   SigIgnz&SigIgn not found in /proc/self/status.Tz=restore_signals=True should've unblocked SIGPIPE and friends.r  N)r   r   r  r  rc  assertNotEqual)r%   default_proc_statusr  default_sig_ign_maskrestored_proc_statusrestored_sig_ign_masks   &     r   test_restore_signals)POSIXProcessTestCase.test_restore_signals  s     )55+, %' (224Dy))'+$ 5
 MMBC)66+, $ & )335Dy))(,% 6 	02G!3 	 	4r   c                0    \         P                  ! \        P                  R R.RR7      p\        P
                  ! ^ 4      p\        V4      pV P                  W#4       R#   \         d,   pTP                  \        P                  8w  d   h  Rp?R# Rp?ii ; i)r   zimport os; print(os.getsid(0))T)start_new_sessionN)r   r   ra   rb   r   getsidintr  PermissionErrorra  EPERM)r%   r   
parent_sid	child_sidrv   s   &    r   test_start_new_session+POSIXProcessTestCase.test_start_new_session  sy    
	7,,^^T+KL&*,F 1JFI
6  	ww%++% &	   )A B* BBsetpgidgetpgidz!no setpgid or getpgid on platformc                0    \         P                  ! \        P                  R R.^ R7      p\        P
                  ! ^ 4      p\        V4      pV P                  W#4       R#   \         d,   pTP                  \        P                  8w  d   h  Rp?R# Rp?ii ; i)r   zimport os; print(os.getpgid(0)))process_groupN)r   r   ra   rb   r   r  r  r  r  ra  r  )r%   r   parent_pgid
child_pgidrv   s   &    r   test_process_group_0)POSIXProcessTestCase.test_process_group_0  sy    
	9,,^^T+LM"#%F **Q-KVJ8  	ww%++% &	r  setreuidzno setreuid on platformc           
        \         P                  ! 4       pVR 8w  d   R MRV.p\        P                  R8w  d   RMRp\        e)    \        P
                  ! V4       VP                  V4       V F  pR F  pV P                  WER7      ;_uu_ 4         \        P                  ! \        P                  RR.VVR7      p\        V\        4      '       d"   \        P
                  ! V4      P                  pMTp\        V4      pV P!                  W4       RRR4       K  	  K  	  V P-                  \.        4      ;_uu_ 4        \        P0                  ! \2        RR	7       RRR4       V P-                  \4        4      ;_uu_ 4        \        P0                  ! \2        \         P6                  \         P8                  RR
7       RRR4       \        fK   VeE   V P-                  \.        4      ;_uu_ 4        \        P0                  ! \2        VR	7       RRR4       R# R# R#   \         d    Rp ELi ; i  \"         dv   p	T	P$                  \$        P&                  8X  d1   T P!                  T	P(                  \        P                  4        Rp	?	ELtT P+                  T	P(                  4        Rp	?	ELRp	?	ii ; i  + '       g   i     EKM  ; i  + '       g   i     ELq; i  + '       g   i     EL%; i  + '       g   i     R# ; i)    darwinr  unknownN)user	close_fdsr   zimport os; print(os.getuid())r  )r*  r   r  r  rr               )r   geteuidra   r  pwdgetpwnamr]  r  subTestr   r   rb   
isinstanceru   pw_uidr  rc   r  ra  EACCESr  r|  rm   r   r{   r   OverflowErrorrK  r   )
r%   uid
test_usersname_uidr  r  r   user_uid
child_userrv   s
   &         r   	test_userPOSIXProcessTestCase.test_user  s(    jjl"e|e<
"||x78Y? X&!!(+
 D*	\\t\AA?!+!8!8!$!@!B%)*3	"5 &dC00'*||D'9'@'@H'+H%([
((>% BA + . z**!!/; + }--!!/&(iiRZZeM . ;8/"":..%%oHE /. 0;E     + :77ell2 ,,QZZHH --ajj99	: BAA( +** .--
 /..sz   'H J.	*H+<AJ.	>K ;K,K+H('H(+J+6A	J&?J.	J& J.	&J++J.	.K K	K(	+K<	z setreuid() available on platformc                    V P                  \        4      ;_uu_ 4        \        P                  ! \        R R7       RRR4       R#   + '       g   i     R# ; i)  r  Nrm   r   r   r{   r   r$   s   &r   test_user_error$POSIXProcessTestCase.test_user_error  s2    z**!!/> +***   AA	setregidzno setregid() on platformc           
        \         P                  ! 4       pVR 8w  d   R MR.p\        4       p\        e   VP	                  V4       W!.,            F  pR F  pV P                  WER7      ;_uu_ 4         \        P                  ! \        P                  RR.VVR7      p\        V\        4      '       d"   \        P                  ! V4      P                  pMTp\        V4      pV P                  W4       RRR4       K  	  K  	  V P'                  \(        4      ;_uu_ 4        \        P*                  ! \,        R	R7       RRR4       V P'                  \.        4      ;_uu_ 4        \        P*                  ! \,        \         P0                  \         P2                  R
R7       RRR4       \        fE   V P'                  \(        4      ;_uu_ 4        \        P*                  ! \,        VR7       RRR4       R# R#   \          d'   p	T P#                  T	P$                  4        Rp	?	EL,Rp	?	ii ; i  + '       g   i     EK  ; i  + '       g   i     EL; i  + '       g   i     L; i  + '       g   i     R# ; i)r  r  N)groupr  r   zimport os; print(os.getgid())r  )r*  r   r  r  rr   r  )r   getegidr  r  r]  r  r   r   ra   rb   r  ru   r  gr_gidr  rc   r  r|  r  rm   r   r{   r   r  rK  r   )
r%   gid
group_listr  r  r  r   	group_gidchild_grouprv   s
   &         r   
test_groupPOSIXProcessTestCase.test_group#  s   jjl"e|e7
')
?j)%''E*	\\\CCA!+!8!8!$!@!B&+*3	"5 &eS11(+U(;(B(BI(-I&)&k((@! DC + (, z**!!/< + }--!!/&(iiRZZuN . ;"":..%%oZH /. ' + 6))!**556 DCC& +** .-
 /..s[   0H%	2*G1AH%	H: ;II!1H"<HH%	H""H%	%H7:I	I	!I2	z setregid() available on platformc                    V P                  \        4      ;_uu_ 4        \        P                  ! \        R R7       RRR4       R#   + '       g   i     R# ; i)r  r  Nr  r$   s   &r   test_group_error%POSIXProcessTestCase.test_group_errorM  s2    z**!!/? +***r
  	setgroupszno setgroups() on platformc                l    \         P                  ! 4       pVR 8w  d   R MR.pV P                  WR7       R# )r  r  r  r  N)r   r  _test_extra_groups_impl)r%   r  r  s   &  r   test_extra_groups&POSIXProcessTestCase.test_extra_groupsR  s.    jjl"e|e7
$$$Dr   c                R    V P                  \        P                  ! 4       . R 7       R# )r  N)r  r   r  r$   s   &r   test_extra_groups_empty_list1POSIXProcessTestCase.test_extra_groups_empty_listX  s    $$"$Er   c               6   \        4       p\        e   VP                  V4        \        P                  ! \
        P                  RR.VR7      p\        P                  ! 4       p\        P                  ! V4      p\        eI   V Uu. uF;  p\        V\        4      '       d!   \        P                  ! V4      P                  MTNK=  	  ppMTpV P                  \!        V4      \!        V4      4       \        fF   V P+                  \,        4      ;_uu_ 4        \        P.                  ! \0        V.R7       R R R 4       R # R # u upi   \"         d7   p	T P%                  T	P&                  4       T P)                  R4        R p	?	LR p	?	ii ; i  + '       g   i     R # ; i)Nr   z;import os, sys, json; json.dump(os.getgroups(), sys.stdout)extra_groupsz-setgroup() EPERM; this test may require root.)r  r  r]  r   r   ra   rb   r   	getgroupsjsonloadsr  ru   r  r  rc   setr  r|  r  rc  rm   r   r{   r   )
r%   r  r  r  r   parent_groupschild_groupsgdesired_gidsrv   s
   &$$       r   r  ,POSIXProcessTestCase._test_extra_groups_impl\  sL   ')
?j)	C,,^^TRT!+-F LLNM::f-L)3 5)3A ;EQ:L:LQ 6 6RS S)3   5  *S.L0AB;"":..%%o4><A /.  5  	Kajj)MMIJJ	K  /..s*   )E AD>FF,E??FF	c           	        V P                  \        4      ;_uu_ 4        \        P                  ! \        R.R7       RRR4       V P                  \        4      ;_uu_ 4        \        P                  ! \        \
        P                  \
        P                  R.R7       RRR4       R#   + '       g   i     Ls; i  + '       g   i     R# ; i)r   r$  N)r*  r   r%  rr   r  )rm   r   r   r{   r   r   rK  r   r$   s   &r   &test_extra_groups_invalid_gid_t_values;POSIXProcessTestCase.test_extra_groups_invalid_gid_t_values|  s|    z**!!/E + z**!!/&(iiRZZ05w8 +* +* +**s   B'!<B:'B7	:C	umaskzPOSIX umask() is not available.c           	        R p \         P                  ! 4       p\        P                  P	                  VR4      p\
        P                  ! \        P                  RRV: R2.^+R7       \        P                  ! V4      P                  R,          pRpV P                  WC\        V4       R\        V4       2R	7       Ve   \        P                  ! V4       R # R #   Te   \        P                  ! T4       i i ; i)
Nbeansr   zopen(z, 'w').close())r2  i  i  z != r  )r   rZ  r   r
  r  r   r{   ra   rb   statst_moderc   octr   rf  )r%   rk  namer6  expected_modes   &    r   
test_umaskPOSIXProcessTestCase.test_umask  s     	&%%'F77<<0D !!^^TU4(.+IJ!
 ggdm++e3G!M]$'$6#7tCL>!J  L !f% "v!f% "s   B6C C5c                <   \         P                  ! 4       ;_uu_ 4        \        P                  ! \        P
                  R R.4      pVP                  4        RRR4       V P                  XP                  ) \        P                  4       R#   + '       g   i     L=; i)r   zimport os; os.abort()N)r   r  r   rM   ra   rb   r+   rc   r   r  SIGABRTrS   s   & r   test_run_abort#POSIXProcessTestCase.test_run_abort  sd    ((**  #..$"9"; <AFFH + 	!,,7	 +*s   8BB	c                0   \         P                  ! \        \        P                  4      ) R 4      p\        V4      pV P                  RVP                  4       4       V P                  RV4       V P                  \        \        P                  4      V4       R# )fake cmdr  SIGN)r   r   r  r  r=  ru   rt   lowerr%   r   error_strings   &  r   "test_CalledProcessError_str_signal7POSIXProcessTestCase.test_CalledProcessError_str_signal  si    ++S-@,@*M3x 	h 2 2 45 	e\*c&..)<8r   c                n    \         P                  ! RR4      p\        V4      pV P                  RV4       R# )i? rA  zunknown signal 9876543.NiKir   r   ru   rt   rD  s   &  r   *test_CalledProcessError_str_unknown_signal?POSIXProcessTestCase.test_CalledProcessError_str_unknown_signal  s,    ++HjA3x/>r   c                n    \         P                  ! ^R4      p\        V4      pV P                  RV4       R# )r  rA  znon-zero exit status 2.NrI  rD  s   &  r   $test_CalledProcessError_str_non_zero9POSIXProcessTestCase.test_CalledProcessError_str_non_zero  s,    ++Az:3x/>r   c                   \         P                  ! \        P                  R R.\         P                  R R7      pV;_uu_ 4        V P                  VP                  P                  4       R4       RRR4       R#   + '       g   i     R# ; i)r   r  c                  0    \         P                  ! R R4      # )r   apple)r   putenvr2   r   r   <lambda>3POSIXProcessTestCase.test_preexec.<locals>.<lambda>  s    		'70Kr   )rK   
preexec_fn   appleNrx  rS   s   & r   test_preexec!POSIXProcessTestCase.test_preexec  sb     cnndEF %/OO(K	M
 QQXX]]_h7 QQQs   +A99B
	c                v   R  p \         P                  ! \        P                  RR.VR7      pV P	                  R4       R#   \         P
                   d,   pT P                  \         P                  R4        Rp?R# Rp?i\         d/   pT P                  RTP                  ^ ,          4        Rp?R# Rp?ii ; i)c                      \        R 4      h)z'What if two swallows carried a coconut?r   r2   r   r   raise_it=POSIXProcessTestCase.test_preexec_exception.<locals>.raise_it  s    FGGr   r   r   rU  zEException raised by preexec_fn did not make it to the parent process.z)Expected a ValueError from the preexec_fnNcoconut)r   rM   ra   rb   rs   r  r  
_fork_execr   rt   rA   )r%   r\  rT   rv   s   &   r   test_preexec_exception+POSIXProcessTestCase.test_preexec_exception  s    	H	0  #..$!;,46A II / 0 )) 	AOO))?A A  	0MM)QVVAY//	0s)   )A B8 A<<B8	B8
#B33B8c                   0   a  ] tR tRt o RtR tR tRtV tR# )+POSIXProcessTestCase._TestExecuteChildPopeni  z3Used to test behavior at the end of _execute_child.c                Z    Wn         \        P                  P                  ! V .VO5/ VB  R # r"   )	_testcaser   rM   r   )r%   testcaserA   rB   s   &&*,r   r   4POSIXProcessTestCase._TestExecuteChildPopen.__init__  s%    %N%%d<T<V<r   c           
     8    \         P                  P                  ! V .VO5/ VB  \        ^4       Uu. uF(  p\        P
                  ! R\        P                  4      NK*  	  pp V Fk  pV P                  P                  WPP                  P                  4       V P                  P                  4       V P                  P                  4       3RR7       Km  	  V F  p\        P                  ! V4       K  	  R# u upi   T F  p\        P                  ! T4       K  	  i ; i  \        ^4       Uu. uF(  p\        P
                  ! R\        P                  4      NK*  	  Mu upi pp T Fk  pT P                  P                  YPP                  P                  4       T P                  P                  4       T P                  P                  4       3RR7       Km  	  T F  p\        P                  ! T4       K  	  i   T F  p\        P                  ! T4       K  	  i ; i; i)   	/dev/zeroz!At least one fd was closed early.r  N)r   rM   rC   r[  r   r^  O_RDONLYrf  r   rJ   rj  rK   rL   rR   )r%   rA   rB   r  devzero_fdsr  s   &*,   r   rC   :POSIXProcessTestCase._TestExecuteChildPopen._execute_child  s   %  //FtFvF ).a2(01  "ww{BKK@(0  2%)22 "ZZ%6%6%8$++:L:L:N%)[[%7%7%9%;$G 3 I * * *2 * * ).a2(01  "ww{BKK@(02 2%)22 "ZZ%6%6%8$++:L:L:N%)[[%7%7%9%;$G 3 I * * *k *sB   $D .C6$A1C; ;!DH-.EH$A1G5 H5!HH)rf  N)	r4   r5   r6   r7   rE   r   rC   r8   r9   r:   s   @r   _TestExecuteChildPopenrd    s     A	=	% 	%r   ro  rk  z/dev/zero required.c                   R pV P                  \        P                  4      ;_uu_ 4        V P                  V \        \        P
                  \        P
                  \        P
                  VR7       RRR4       R#   + '       g   i     R# ; i)z6Issue16140: Don't double close pipes on preexec error.c                  .    \         P                  ! R 4      h)z-force the _execute_child() errpipe_data path.)r   r  r2   r   r   r\  WPOSIXProcessTestCase.test_preexec_errpipe_does_not_double_close_pipes.<locals>.raise_it  s    ,,CE Er   )rJ   rK   rL   rU  N)rm   r   r  ro  r   rN   )r%   r\  s   & r   0test_preexec_errpipe_does_not_double_close_pipesEPOSIXProcessTestCase.test_preexec_errpipe_does_not_double_close_pipes  s_    	E z99::''o(oojoo)8 ( E ;:::s   AA;;B	c                   \         P                  ! 4       p \         P                  ! 4        V P                  \         P                  ! 4       4       \        P
                  ! \        P                  R R.R R7       V P                  \         P                  ! 4       R4       \         P                  ! 4        V P                  \         P                  ! 4       4       \        P
                  ! \        P                  R R.R R7       V P                  \         P                  ! 4       R4       V'       g   \         P                  ! 4        R# R#   T'       g   \         P                  ! 4        i i ; i)r   r   c                      R # r"   r2   r2   r   r   rS  EPOSIXProcessTestCase.test_preexec_gc_module_failure.<locals>.<lambda>	      tr   r^  z#Popen enabled gc when it shouldn't.c                      R # r"   r2   r2   r   r   rS  rw  		  rx  r   zPopen left gc disabled.N)
gc	isenableddisabler-   r   r`   ra   rb   enabler  )r%   enableds   & r   test_preexec_gc_module_failure3POSIXProcessTestCase.test_preexec_gc_module_failure  s     ,,.	JJLR\\^,OOS^^T26'35R\\^BD IIKOOBLLN+OOS^^T26'35OOBLLN,EF

 7

 s   DE  E(r  z!setrlimit() seems to fail on OS Xc                \    ^ RI HpHpHp X! X4      pVw  rgX! V^ V34       V P                  W#V4        \        P                  ! \        P                  RR.R R7       V P                  R4       R#   \         d   pT P                  T4        Rp?LRp?ii ; i  \         d     R# i ; i)r   )rV  rX  RLIMIT_NPROCNr   r   c                      R # r"   r2   r2   r   r   rS  @POSIXProcessTestCase.test_preexec_fork_failure.<locals>.<lambda>	  rx  r   r^  z.RLIMIT_NPROC had no effect; probably superuser)rU  rV  rX  r  r  rc  r   r   r`   ra   rb   BlockingIOError)r%   rV  rX  r  r   limitsr  ri  s   &       r   test_preexec_fork_failure.POSIXProcessTestCase.test_preexec_fork_failure	  s    
	CC <(	,D	*	8	LOOS^^T26'35 MMJK  	MM#	  		s(   
A3 *B 3B>BBB+*B+c                   \         P                  ! 4       w  r\        VR RR7      ;_uu_ 4       pVP                  R\        P
                  ,          4       VP                  R\        P                  ,          4       RRR4       \        P                  ! VR4       \        P                  ! V4      pVP                  4        \        P                  ! V4       V P                  VP                  ^/4       R#   + '       g   i     L; iwrN  )r   z#!%s
z(exec '%s' -c 'import sys; sys.exit(47)'
Ni  )r   r  r^  r   r   
unix_shellra   rb   r   chmodr   rM   r+   r  rc   r   )r%   r  fnamefobjrT   s   &    r   test_args_string%POSIXProcessTestCase.test_args_string%	  s    $$&	"c"344JJx'"4"445JJB~~& ' 5 	U#	
		%r* 54s   AC44D	c                    V P                  \        \        P                  \        P
                  R R.^/R7       V P                  \        \        P                  \        P
                  R R.^/R7       R# )r   r^   startupinfocreationflagsNrm   r   r   r`   ra   rb   r$   s   &r   r   &POSIXProcessTestCase.test_invalid_args3	  sb    *joo>>457&( 	 	* 	*joo>>457(* 	 	,r   c                ^   \         P                  P                  4       pR VR&   \        P                  ! R.^\        P
                  VR7      pV;_uu_ 4        V P                  VP                  P                  4       P                  R4      R4       RRR4       R#   + '       g   i     R# ; irQ  r   zecho $FRUITr  rK   r   s    	
rV  N
r   r   r   r   rM   rN   rc   rK   r5  r  r%   r   rT   s   &  r   test_shell_sequence(POSIXProcessTestCase.test_shell_sequence>	  ss    "!wm_A$.OO!') QQXX]]_22<@(K QQQs   :BB,	c                \   \         P                  P                  4       pR VR&   \        P                  ! R^\        P
                  VR7      pV;_uu_ 4        V P                  VP                  P                  4       P                  R4      R4       RRR4       R#   + '       g   i     R# ; ir  r  r  s   &  r   test_shell_string&POSIXProcessTestCase.test_shell_stringH	  sq    "!w]!$.OO!') QQXX]]_22<@(K QQQs   :BB+	c                   \         P                  ! 4       w  r\        VR RR7      ;_uu_ 4       pVP                  R\        P
                  ,          4       VP                  R\        P                  ,          4       RRR4       \        P                  ! VR4       \        P                  ! V4      p\        P                  ! V4       V P                  V^/4       R#   + '       g   i     Lg; ir  )r   r  r^  r   r   r  ra   rb   r   r  r   r`   r  rc   )r%   r  r  r  re   s   &    r   test_call_string%POSIXProcessTestCase.test_call_stringR	  s    $$&	"c"344JJx'"4"445JJB~~& ' 5 	__U#
		%R  54s   ACC*	c           
        . pR Fc  pR	 FZ  p\         P                  P                  W#4      p\         P                  P                  V4      '       g   KI  VP	                  V4       K\  	  Ke  	  V'       g   V P                  R4       Rp\         P                  P                  V4      '       d7   \         P                  P                  V4      '       g   VP	                  V4       V F  p\        P                  ! RVR\        P                  R7      pV;_uu_ 4        V P                  VP                  P                  4       P                  4       \        VR4      4       RRR4       K  	  R#   + '       g   i     K  ; i)
/binz"bash or ksh required for this testz/bin/shzecho $0T)rb   r  rK   r  N)r  z	/usr/bin/z/usr/local/bin)bashksh)r   r
  r  isfiler]  rc  islinkr   rM   rN   rc   rK   r5  r  r  )r%   shellsr*  r8  shrT   s   &     r   test_specific_shell(POSIXProcessTestCase.test_specific_shell_	  s    =F'WW\\&/77>>"%%MM"% ( >
 MM>?77>>"bggnnR&8&8MM"B  r(29A  !6!6!8%G:LM   s   AE**E;c                   \         P                   ! \         P                  \         P                  4      p \        P                  ! \
        P                  R R.R\        P                  \        P                  \        P                  R7      p\         P                   ! \         P                  V4       VP                  P                  ^4       \        WA4      ! V!   V#   \         P                   ! \         P                  T4       i ; i)r   zif 1:
                                 import sys, time
                                 sys.stdout.write('x\n')
                                 sys.stdout.flush()
                                 time.sleep(30)
                                 Tr  rJ   rK   rL   )r  SIGINTdefault_int_handlerr   rM   ra   rb   rN   rK   r5  getattr)r%   methodrA   r  rT   s   &&*  r   _kill_process"POSIXProcessTestCase._kill_processs	  s    
 mmFMM63M3MN	6  #..$ 9% "& ,0'1(2(2	9A MM&--5 	
aD! MM&--5s   AC 'Dz"Due to known OS bug (issue #16762)c                R   \         P                  ! \        P                  R R.R\         P                  \         P                  \         P                  R7      pVP
                  P                  ^4       \        P                  ! ^4       \        W14      ! V!   VP                  4        R# )r   zif 1:
                             import sys, time
                             sys.stdout.write('x\n')
                             sys.stdout.flush()
                             Tr  N)r   rM   ra   rb   rN   rK   r5  r  r  r  r   )r%   r  rA   rT   s   &&* r   _kill_dead_process'POSIXProcessTestCase._kill_dead_process	  ss    
 cnnd 5! "
 (,#-??$.OO$.OO5 	
a

1D!	r   c                    V P                  R \        P                  4      pVP                  4       w  r#V P	                  RV4       V P                  VP                  4       ^ 4       R# )send_signals   KeyboardInterruptN)r  r  r  r   rt   r  r+   r%   rT   r  rL   s   &   r   test_send_signal%POSIXProcessTestCase.test_send_signal	  sJ    }fmm<MMO	*F3AFFHa(r   c                    V P                  R 4      pVP                  4       w  r#V P                  VR4       V P                  VP                  4       \        P
                  ) 4       R# )r  r   N)r  r   rc   r+   r  SIGKILLr  s   &   r   	test_killPOSIXProcessTestCase.test_kill	  sK    v&MMO	%FNN?3r   c                    V P                  R 4      pVP                  4       w  r#V P                  VR4       V P                  VP                  4       \        P
                  ) 4       R# )	terminater   N)r  r   rc   r+   r  SIGTERMr  s   &   r   test_terminate#POSIXProcessTestCase.test_terminate	  sK    {+MMO	%FNN?3r   c                F    V P                  R \        P                  4       R# r  N)r  r  r  r$   s   &r   test_send_signal_dead*POSIXProcessTestCase.test_send_signal_dead	  s    v}}=r   c                (    V P                  R 4       R# r  Nr  r$   s   &r   test_kill_dead#POSIXProcessTestCase.test_kill_dead	  s    'r   c                (    V P                  R 4       R# r  Nr  r$   s   &r   test_terminate_dead(POSIXProcessTestCase.test_terminate_dead	  s    ,r   c                    . pV FB  p\         P                  ! V4      p\         P                  ! V4      pVP                  W5V34       KD  	  V# r"   )r   get_inheritabledupr]  )r%   save_fdsr  r  inheritablesaveds   &&    r   	_save_fdsPOSIXProcessTestCase._save_fds	  sF    B,,R0KFF2JEJJ;/0  
r   c                z    V F4  w  r#p\         P                  ! W2VR 7       \         P                  ! V4       K6  	  R# ))r  N)r   dup2rR   )r%   r  r  r  r  s   &&   r   _restore_fds!POSIXProcessTestCase._restore_fds	  s*    &)"B{GGE;7HHUO '*r   c                   ^ pV P                  V4      pV F  w  rEpV^ 8X  g   K  Tp M	   V F  p\        P                  ! V4       K  	  \        P                  ! \
        P                  RR.V\        P                  \        P                  R7      P                  4       w  rxV P                  VR4       V P                  VR4       V P                  V4       R#   T P                  T4       i ; i)r   r   r  rI   rV  rw  N)r  r   rR   r   rM   ra   rb   rN   r   rc   r  )	r%   r  rJ   	saved_fdsr  r  r  r   r   s	   &&       r   check_close_std_fds(POSIXProcessTestCase.check_close_std_fds	  s     NN3'	&/"B{Qw '0	) !'';)<
 #(oo(oo/ 0;{} C S(+S),i(Di(s   BC C,c                *    V P                  ^ .4       R# rz   r  r$   s   &r   test_close_fd_0$POSIXProcessTestCase.test_close_fd_0	        !%r   c                *    V P                  ^.4       R# r   Nr  r$   s   &r   test_close_fd_1$POSIXProcessTestCase.test_close_fd_1	  r  r   c                *    V P                  ^.4       R# )r  Nr  r$   s   &r   test_close_fd_2$POSIXProcessTestCase.test_close_fd_2	  r  r   c                ,    V P                  ^ ^.4       R# rz   r  r$   s   &r   test_close_fds_0_1'POSIXProcessTestCase.test_close_fds_0_1	        !Q(r   c                ,    V P                  ^ ^.4       R# rz   r  r$   s   &r   test_close_fds_0_2'POSIXProcessTestCase.test_close_fds_0_2	  r  r   c                ,    V P                  ^^.4       R# r  r  r$   s   &r   test_close_fds_1_2'POSIXProcessTestCase.test_close_fds_1_2	  r  r   c                ,    V P                  . RO4       R# )r   N)r   r   r  r  r$   s   &r   test_close_fds_0_1_2)POSIXProcessTestCase.test_close_fds_0_1_2	  s     	  +r   c                   \         P                  ! ^ 4      p\         P                  ! ^4      p \         P                  ! ^ 4       \         P                  ! ^4       \        P                  ! \
        P                  RR.4      P                  4        \         P                  ! V^ 4       \         P                  ! V^4       \         P                  ! V4       \         P                  ! V4       R#   \         P                  ! T^ 4       \         P                  ! T^4       \         P                  ! T4       \         P                  ! T4       i ; i)z=Issue #15798: Popen should work when stdio fds are available.r   z*print('AssertionError:0:CLOEXEC failure.')N)	r   r  rR   r   rM   ra   rb   r+   r  )r%   	new_stdin
new_stdouts   &  r   test_small_errpipe_write_fd0POSIXProcessTestCase.test_small_errpipe_write_fd	  s    FF1I	VVAY
	!HHQKHHQK
 NND@B CCG46 GGIq!GGJ"HHYHHZ  GGIq!GGJ"HHYHHZ s   A!C+ +AEc                z   \        ^4       Uu. uF  p\        P                  ! 4       NK  	  pp V UUu. uF  w  r4VNK	  	  pppV F  w  r4\        P                  ! V4       K  	  \        P
                  ! V^,          R4       \        P                  ! V^,          ^ ^ 4       V P                  \        ^4      4      p \        V4       F  w  r7\        P                  ! Ws4       K  	  \        P                  ! \        P                  RR.V^,          V^,          V^ ,          R7      pVP                  4        V P                  V4       V F  p\        P                  ! V^ ^ 4       K  	  \        P                   ! V^,          R4      p	\        P                   ! V^ ,          R4      P#                  4       p
V P%                  V	R4       V P%                  V
R4       V F  p\        P&                  ! V4       K  	  R# u upi u uppi   T P                  T4       i ; i  X F  p\        P&                  ! T4       K  	  i ; i	   s   STDINr   zZimport sys; got = sys.stdin.read();sys.stdout.write("got %s"%got); sys.stderr.write("err")rI   r}  s	   got STDINs   errN)r[  r   r  r   unlinkr   rk  r  	enumerater  r   rM   ra   rb   r+   r  r5  r  rc   rR   )r%   rl  tempsr  r  temp_fdsr  temp_fdrT   r   r   s   &          r   test_remapping_std_fds+POSIXProcessTestCase.test_remapping_std_fds
  s   -21X6X!!#X6(	,12EyrEH2 #			%  # HHXa[(+HHXa[!Q' uQx0I-#,X#6KBGGG( $7
 $$cnndN&O #1+#A;#A;( !!),Q"  ''(1+t,C''(1+t,224CS,/S&)  Q 726 !!),  s<   G8H G=A;H =A:H 7B H =H HH !H:c                   \        ^4       Uu. uF  p\        P                  ! 4       NK  	  ppV UUu. uF  w  rgVNK	  	  ppp V F  w  rg\        P                  ! V4       K  	  V P                  \        ^4      4      p	 \        V4       F  w  rj\        P                  ! W4       K  	  \        P                  ! VR4       \        P                  ! V^ ^ 4       \        P                  ! \        P                  RR.VVVR7      pVP                  4        V F  p\        P                  ! V^ ^ 4       K  	  \        P                  ! VR4      p\        P                  ! VR4      P!                  4       pV P#                  V	4       V P%                  VR4       V P%                  VR4       V F  p\        P&                  ! V4       K  	  R# u upi u uppi   T P#                  T	4       i ; i  T F  p\        P&                  ! T4       K  	  i ; ir  )r[  r   r  r   r  r  r  r  r   rk  r   rM   ra   rb   r+   r5  r  r  rc   rR   )r%   stdin_no	stdout_no	stderr_norl  r	  r  r  r
  r  r  rT   r   r   s   &&&&          r   check_swap_fds#POSIXProcessTestCase.check_swap_fds@
  s   -21X6X!!#X6(-.92B.'	"			%  # uQx0I-#,X#6KBGGG( $7 8,1a( $$cnndN&O #$$& "BHHRA& # ggi.ggi.446!!),S,/S&)  Q 7.B !!),  s/   GG;G(  C1G 15G( G%%G( (!H	c                    V P                  ^ ^^4       V P                  ^ ^^4       V P                  ^^ ^4       V P                  ^^^ 4       V P                  ^^ ^4       V P                  ^^^ 4       R# rz   )r  r$   s   &r   test_swap_fds"POSIXProcessTestCase.test_swap_fdsp
  sn    Aq!$Aq!$Aq!$Aq!$Aq!$Aq!$r   c                   V P                  \        ^4      4      p V FN  p\        P                  ! 4       ;_uu_ 4       p\        P
                  ! VP                  4       V4       RRR4       KP  	  \        \        ^4      4      \        V4      ,
          P                  4       p\        P                  ! V4       . ROp/ p\        W4       F  w  rIWHWy,          &   K  	  \        P                  ! R4      p
\        \        ^4      4      \        V4      ,
          P                  4       p\        P                  ! \        P                   RV
\#        V4      .3/ VB pV P%                  V^ 4       \        W4       F  w  rI\        P&                  ! V^ \        P(                  4       \        P*                  ! VR4      p\-        \/        \0        VP3                  R4      4      4      p\        P                  ! RV RV RV R	V R
V	 R24      pV P%                  V	.W4       K  	  V P5                  V4       R#   + '       g   i     EK!  ; i  T P5                  T4       i ; i)r  Nz
                import os, sys
                skipped_fd = int(sys.argv[1])
                for fd in range(3):
                    if fd != skipped_fd:
                        os.write(fd, str(fd).encode('ascii'))
            r   r}  r  z"
                    When testing z to z4 redirection,
                    parent descriptor z5 got redirected
                    to descriptor(s) z instead of descriptor z.
                rI   )r  r[  r   r   r   r  rj  r)  re  rR   zipr=  r>  r   r`   ra   rb   ru   rc   rk  SEEK_SETr5  r  mapr  r6  r  )r%   from_fdsto_fdsr  from_fdffd_to_close	arg_namesrB   to_fdr   
skipped_fdre   
read_bytesread_fdsr  s   &&&             r   #_check_swap_std_fds_with_one_closed8POSIXProcessTestCase._check_swap_std_fds_with_one_closedx
  s   NN58,	&	)#++--GGAHHJ0 .- $ uQx=3x=8==?KHH[!5IF"%h"7+2y'( #8 ?? $ D eAh-#f+5::<J#..$c*o!N +#)+BR#"%h"7!R[[1WWWd3
C):):7)C DEoo +""*4x 8''.i 0&&.Z/Fug N' 
   %(8 #8 i(I .--H i(s#   "I &H-$F6I -H?8
I Ic                    \         P                  ! \        ^4      ^4       F;  p\         P                  ! \        ^4      ^4       F  pV P	                  W4       K  	  K=  	  R# )r  N)	itertoolscombinationsr[  permutationsr%  )r%   r  r  s   &  r   !test_swap_std_fds_with_one_closed6POSIXProcessTestCase.test_swap_std_fds_with_one_closed
  sF    !..uQx;H#00q1=88J > <r   c                   R  p \         P                  ! \        VR7       V P                  R4       R#   \         dF   pT P                  \         P                  4       T P                  \        T4      R4        Rp?R# Rp?i\         P                   dF   pT P                  \         P                  4       T P                  \        T4      R4        Rp?R# Rp?ii ; i)c                      \        R 4      h)   surrogate:r[  r2   r   r   prepareCPOSIXProcessTestCase.test_surrogates_error_message.<locals>.prepare
  s    /00r   r^  z1Expected ValueError or subprocess.SubprocessErrorr/  Nz!Exception occurred in preexec_fn.)r   r`   r   rs   r   r|  r`  rc   ru   r  assertIsNotNone)r%   r0  r   s   &  r   test_surrogates_error_message2POSIXProcessTestCase.test_surrogates_error_message
  s    	1	KOO"$ IIIJ  	;j334SX'9::)) 	L  !6!67SX'JKK	Ls&   4 C:A??CC:CCc                   R EFa  w  rVP                  RR4      pR\        V4      ,          p\        P                  P	                  4       pW%V&   RVR&   Tp\
        P                  ! \        P                  RV.VR7      pVP                  R4      pV P                  VP                  R4      \        V4      4       VP                  RR4      pR	\        V4      ,          p\        P                  P	                  4       pW5V&   \
        P                  ! \        P                  RV.VR7      pVP                  R4      pV P                  VP                  R4      \        V4      4       EKd  	  R
# )testr  rN  z&import os; print(ascii(os.getenv(%s)))CLC_ALLr   r   s   
z'import os; print(ascii(os.getenvb(%s)))N))r6  u   abc)u   test42)r  r  r   r   r   r   r   ra   rb   r   rc   r6  r  )r%   keyvalueencoded_valuescriptr   decoded_valuerK   s   &       r   test_undecodable_env)POSIXProcessTestCase.test_undecodable_env
  s-   GJC!LL2CDM >S	IF**//#CH  CM!M,,v.F ]]7+FV]]73U=5IJ **W&78C>cJF**//#C$H,,v.F ]]7+FV]]73U=5IJ5 Hr   c                x   \         P                  ! \        ^ ,          4      p\        \        R,          4      p\         P                  P                  \        ^ ,          4      w  r4\         P                  ! V4      p\        P                  ! V.V,           4      pV P                  V^ 4       RVRP                  V4      P                  R4      3,          p\        P                  ! VRR7      pV P                  V^ 4       \         P                  P                  4       pW7R&   \        P                  ! V.V,           VR7      pV P                  V^ 4       \         P                  P                  4       p\         P                  ! V4      VR	&   \        P                  ! V.V,           VR7      pV P                  V^ 4       R
# )r   r   NNs   '%s' %s r   Tr  PATHr   s   PATHN)r   r  r   r  r
  r/  r   r`   rc   r  r  r   r   environb)	r%   abs_programrA   r
  programexitcoder  r   envbs	   &        r   test_bytes_program'POSIXProcessTestCase.test_bytes_program
  sA   kk/!"45OB'(oa&89++g& ??K=#561% K$)>)>w)GHH??3d31% jjooF??G9T>s;1% {{!D)W??G9T>t<1%r   c                "   \         P                  ! R RR7      p\         P                  ! RRR7      p\        P                  ! \        P
                  V.\        P                  \        P                  \        P                  RR7      pV P                  VP                  R4       \        P                  ! \        P
                  V.\        P                  RR7      pVP                  4       w  rV\        \        \        VP                  R4      4      4      p\        VP                  P                  4       VP                  P                  4       VP                   P                  4       .4      pV P#                  Wx,          R	V: R
Wx,          : 24       R# )zinput_reader.pysubprocessdatasubdirfd_status.pyF)rJ   rK   rL   r  r   rK   r     ,zExpected no fds from z to be open in child, found N)r   findfiler   rM   ra   rb   rN   r   r   r)  r  r  r/  rJ   rj  rK   rL   r-   )	r%   sleeper	fd_statusp1p2r   error
result_fdsunwanted_fdss	   &        r   test_pipe_cloexec&POSIXProcessTestCase.test_pipe_cloexec
  s   ""#4=MN$$^<LM	s~~w7$.OOJOO%/__G 	,s~~y9%/__G (S&,,t"456
BHHOO-ryy/?/?/AII,,.0 1 	2  ,Z-FH	Ir   c                  a
a \         P                  ! R RR7      p\         P                  ! RRR7      pRpV^,          R,           p\        P                  ! \        P
                  V.\        P                  \        P                  RR7      o
\        P                  ! \        P
                  W#.S
P                  \        P                  RR7      oV P                  S
P                  4       V P                  SP                  4       V
3R lpV3R	 lpV P                  V4       V P                  V4       S
P                  P                  V4       S
P                  P                  4        \        P                  ! SP                  .. . ^
4      w  rxp	V P                  VR
4       V P                  SP                  P!                  4       V4       S
P                  P                  4        SP                  P                  4        R# )zqcat.pyrM  rN  zqgrep.pys   zxcvbn   
F)rJ   rK   r  c                  N   <  S P                  4        R #   \         d     R # i ; ir"   r  ProcessLookupError)rV  s   r   kill_p1BPOSIXProcessTestCase.test_pipe_cloexec_real_tools.<locals>.kill_p1  #    %     $$c                  N   <  S P                  4        R #   \         d     R # i ; ir"   r`  )rW  s   r   kill_p2BPOSIXProcessTestCase.test_pipe_cloexec_real_tools.<locals>.kill_p2!  rd  re  zThe child hungN)r   rS  r   rM   ra   rb   rN   rK   r   r+   rJ   r   rR   selectr  rc   r5  )r%   qcatqgrepsubdatarn  rb  rg  	readfilesignored1ignored2rV  rW  s   &         @@r   test_pipe_cloexec_real_tools1POSIXProcessTestCase.test_pipe_cloexec_real_tools  s]   	2BC  4DE{U"s~~t4$.OOJOO(-/ s~~u>$&IIjoo(-/ 	  	
	
 	  
t
(.ryyk2r2(N%	X	#34)40
		
		r   c                  a
 \         P                  ! R RR7      p\        P                  ! 4       pV P	                  \        P
                  V^ ,          4       V P	                  \        P
                  V^,          4       \        V4      o
\        ^	4       Fg  p\        P                  ! \        P                  \        P                  4      pV P	                  \        P
                  V4       S
P                  V4       Ki  	  S
 F  p\        P                  ! VR4       K  	  \        P                  ! \        P                   V.\        P"                  RR7      pVP%                  4       w  rg\        \'        \(        VP+                  R4      4      4      pV P-                  VS
,          S
R4       \        P                  ! \        P                   V.\        P"                  RR7      pVP%                  4       w  rg\        \'        \(        VP+                  R4      4      4      pV P/                  VS
,          R4       V P1                  ^VR	4       \        V
3R
 l\        ^4       4       4      p	\        P                  ! \        P                   V.\        P"                  RV	R7      pVP%                  4       w  rg\        \'        \(        VP+                  R4      4      4      pV P/                  W,
          S
,          R4       V P1                  ^VR	4       R# )rP  rM  rN  TFrQ  rR  zSome fds were closedzSome fds were left openzSubprocess failedc              3   D   <"   T F  pSP                  4       x  K  	  R # 5ir"   )re  ).0r  r  s   & r   	<genexpr>6POSIXProcessTestCase.test_close_fds.<locals>.<genexpr>X  s     ;(Q(,,..(s    rK   r  pass_fdsz'Some fds not in pass_fds were left openN)r   rS  r   r  r   rR   r)  r[  r^  devnullrl  addset_inheritabler   rM   ra   rb   rN   r   r  r  r/  rc   r-   rt   )r%   rU  r  r  r  rT   r   ignoredremaining_fdsfds_to_keepr  s   &         @r   test_close_fds#POSIXProcessTestCase.test_close_fds4  s(   $$^<LM	ggi#a&)#a&)s8qAR[[1BOOBHHb)LL 
 Br4(  cnni8$.OOuF--/CV\\$%78918/	1 cnni8$.OOtE--/CV\\$%78912	4a(;< ;%(;;cnni8$.OOt&13 --/CV\\$%789-5AB	Da(;<r   freebsdz/devz/dev/fdz.Requires fdescfs mounted on /dev/fd on FreeBSDc                   \         P                  ! RRR7      p\        P                  ! \        P
                  R\        P                  ! RV,          4      .\        P                  R7      pVP                  4       w  r4VP                  4       pV P                  \        V4      ^RV,          R7       \        \        \        V^ ,          P!                  4       P#                  R	4      4      4      p\        \        \        V^,          P!                  4       P#                  R	4      4      4      pV P%                  Wv,          R
R7       R# )z;Confirm that issue21618 is fixed (may fail under valgrind).rP  rM  rN  r   aK  
        import os, resource, subprocess, sys, textwrap
        open_fds = set()
        # Add a bunch more fds to pass down.
        for _ in range(40):
            fd = os.open(os.devnull, os.O_RDONLY)
            open_fds.add(fd)

        # Leave a two pairs of low ones available for use by the
        # internal child error pipe and the stdout pipe.
        # We also leave 10 more open as some Python buildbots run into
        # "too many open files" errors during the test if we do not.
        for fd in sorted(open_fds)[:14]:
            os.close(fd)
            open_fds.remove(fd)

        for fd in open_fds:
            #self.addCleanup(os.close, fd)
            os.set_inheritable(fd, True)

        max_fd_open = max(open_fds)

        # Communicate the open_fds to the parent unittest.TestCase process.
        print(','.join(map(str, sorted(open_fds))))
        sys.stdout.flush()

        rlim_cur, rlim_max = resource.getrlimit(resource.RLIMIT_NOFILE)
        try:
            # 29 is lower than the highest fds we are leaving open.
            resource.setrlimit(resource.RLIMIT_NOFILE, (29, rlim_max))
            # Launch a new Python interpreter with our low fd rlim_cur that
            # inherits open fds above that limit.  It then uses subprocess
            # with close_fds=True to get a report of open fds in the child.
            # An explicit list of fds to check is passed to fd_status.py as
            # letting fd_status rely on its default logic would miss the
            # fds above rlim_cur as it normally only checks up to that limit.
            subprocess.Popen(
                [sys.executable, '-c',
                 textwrap.dedent("""
                     import subprocess, sys
                     subprocess.Popen([sys.executable, %r] +
                                      [str(x) for x in range({max_fd})],
                                      close_fds=True).wait()
                     """.format(max_fd=max_fd_open+1))],
                close_fds=False).wait()
        finally:
            resource.setrlimit(resource.RLIMIT_NOFILE, (rlim_cur, rlim_max))
        r   z(expected exactly two lines of output:
%rr  rR  zSome fds were left open.N)r   rS  r   rM   ra   rb   r=  r>  rN   r   r  rc   r  r)  r  r  r  r/  r-   )r%   rU  rT   r   unused_stderroutput_lines
opened_fdsr}  s   &       r   %test_close_fds_when_max_fd_is_lowered:POSIXProcessTestCase.test_close_fds_when_max_fd_is_loweredd  s   
 $$^<LM	 cnndHOO/	^ _/	05 0` #-//a03d !"((*\*AH6Q 	 	SS,q/"7"7"9"?"?"EFG
C\!_%:%:%<%B%B4%HIJ37 	 	9r   c                F   \         P                  ! R RR7      p\        4       p\        ^4       F  p\        P
                  ! 4       pV P                  \        P                  V^ ,          4       V P                  \        P                  V^,          4       \        P                  ! V^ ,          R4       \        P                  ! V^,          R4       VP                  V4       K  	  V EF"  p\        P                  ! \        P                  V.\        P                  RV3R7      pVP                  4       w  rx\        \!        \"        VP%                  R4      4      4      p	W%0,
          p
V P'                  WYR4       V P)                  W,          R4       V P+                  \,        4      ;_uu_ 4       pV P)                  \        P.                  ! \0        RV3R	7      4       R
R
R
4       V P'                  R\3        XP4                  4      4       EK%  	  R
#   + '       g   i     L<; i)rP  rM  rN  Trw  rR  zfd to be passed not passedzfd to be closed passedF)r  rx  Nzoverriding close_fds)r   rS  r)  r[  r   r  r   rR   r{  updater   rM   ra   rb   rN   r   r  r  r/  rt   r-   assertWarnsr  r`   r   ru   warning)r%   rU  r  r(  r  r  rT   r   r|  r}  to_be_closedcontexts   &           r   test_pass_fds"POSIXProcessTestCase.test_pass_fds  s   $$^<LM	5qA'')COOBHHc!f-OOBHHc!f-s1vt,s1vt,OOC   B  #..)!<(24+-&2A  mmoOFCd); <=M#d?LMM"-IJ]957 !!.11W  '"'2&": ; 2 MM0#goo2FG%  21s   ..HH c                L   \         P                  ! R RR7      p\        P                  ! 4       w  r#V P	                  \        P
                  V4       V P	                  \        P
                  V4       \        P                  ! VR4       \        P                  ! VR4       W#3p\        P                  V.pV\        \        \        V4      4      ,          p\        P                  ! V\        P                  RVR7      pVP                  4       w  rx\!        \        \"        VP%                  R4      4      4      p	V P'                  V	\!        V4      RV,          4       V P'                  \        P(                  ! V4      R4       V P'                  \        P(                  ! V4      R4       R# )	rP  rM  rN  TFrw  rR  z	output=%aN)r   rS  r   r  r   rR   r{  ra   rb   r  r  ru   r   rM   rN   r   r)  r  r/  rc   r  )
r%   r=  r  non_inheritablerx  rA   rT   r   r|  r  s
   &         r   test_pass_fds_inheritable.POSIXProcessTestCase.test_pass_fds_inheritable  s/   !!.9IJ')wwy$+./2
;-
?E21'Sh'((T$.OOt&.0 --/#c6<<-./ 	c(m[6-AB 	++K8$?++O<eDr   c           	        \         P                  ! RRR7      p. p\        ^4       Fg  p\        P                  ! \        P
                  \        P                  4      pV P                  \        P                  V4       VP                  V4       Ki  	  \        P                  ! 4       w  rVV P                  \        P                  V4       V P                  \        P                  V4       VP                  ^V4       \        P                  ! \        P                  V.V^ ,          V^,          V^,          RVR7      ;_uu_ 4        \        P                   ! VR4      pRRR4       XP#                  R4       Uu0 uF  p\%        V4      kK  	  p	pV P'                  V	0 R
m\)        V4      ,          R	V: 24       R#   + '       g   i     Ld; iu upi )z7Regression test for https://bugs.python.org/issue32270.rP  rM  rN  T)rJ   rK   rL   r  rx  r}  NrR  zoutput=>   r   r   r  )r   rS  r[  r   r^  ry  O_RDWRr   rR   r]  r  insertr   rM   ra   rb   r5  r/  r  rc   	frozenset)
r%   rU  rx  r  r  stdout_rstdout_wr   numr  s
   &         r   test_pass_fds_redirected-POSIXProcessTestCase.test_pass_fds_redirected  sG   $$^<LM	qARYY/BOOBHHb)OOB 
  WWY(+(+8$s~~y9$,QK%-a[%-a[(,'/1 1 WWXt,F1 $*<<#56#5Cs3x#56i)H*==
?ST1 1 7s   F76G
7G	c                    \         P                  ! \        P                  R 4      ;_uu_ 4       p\        P
                  ! \        WR7      pVP                  4        RRR4       R#   + '       g   i     R# ; i)r+)rK   rJ   NrP   r^  r   ry  r   rM   r   r+   r%   inoutrT   s   &  r   %test_stdout_stdin_are_single_inout_fd:POSIXProcessTestCase.test_stdout_stdin_are_single_inout_fd  F    WWRZZ&&%  (-<AFFH '&&&   -A%%A6	c                    \         P                  ! \        P                  R 4      ;_uu_ 4       p\        P
                  ! \        WR7      pVP                  4        RRR4       R#   + '       g   i     R# ; i)r  r   Nr  r  s   &  r   &test_stdout_stderr_are_single_inout_fd;POSIXProcessTestCase.test_stdout_stderr_are_single_inout_fd  sF    WWRZZ&&%  (-=AFFH '&&&r  c                    \         P                  ! \        P                  R 4      ;_uu_ 4       p\        P
                  ! \        WR7      pVP                  4        RRR4       R#   + '       g   i     R# ; i)r  )rL   rJ   Nr  r  s   &  r   %test_stderr_stdin_are_single_inout_fd:POSIXProcessTestCase.test_stderr_stdin_are_single_inout_fd  r  r  c                J   \         P                  ! R RR7      p\        P                  ! \        P
                  V.\        P                  \        P                  R7      pVP                  4       w  r4V P                  ^ VP                  RVP                  R4      ,          4       R# )zsigchild_ignore.pyrM  rN  r   z6sigchild_ignore.py exited non-zero with this error:
%sr   N)r   rS  r   rM   ra   rb   rN   r   rc   r   r6  )r%   sigchild_ignorerT   rK   rL   s   &    r   test_wait_when_sigchild_ignored4POSIXProcessTestCase.test_wait_when_sigchild_ignored#  s{    !**+?2BDcnno>$.OOJOOMALL +:w/+0 	1r   c           	        \         P                  ! R 4      p\        P                  ! \        P
                  RR.\        P                  ^ R7      pVP                  pV P                  VP                  4        V P                  VP                  ^4      R4       V P                  W1P                  ! V.. . R4      ^ ,          4       VP                  4        R#   TP                  4        i ; i)ri  r   z$import sys;sys.stdout.write("apple"))rK   rX   s   applg        N)r   import_moduler   rM   ra   rb   rN   rK   r   rR   rc   r5  rt   ri  r+   )r%   ri  rT   r  s   &   r   test_select_unbuffered+POSIXProcessTestCase.test_select_unbuffered.  s     ,,X6cnnd:; %/OO%&	(
 HH 	QVVAY0MM!]]A3B<Q?@FFHAFFHs   7AC C(c           	        \         P                  ! \        P                  R R.\         P                  \         P                  R7      pV P                  VP                  P                  4       V P                  VP                  P                  4       \        V4      pVP                  p\        P                  ! R\        34      ;_uu_ 4        RpRRR4       \        '       d"   V P                  \         P                   4       R# T P#                  T\         P                    Uu. uF  p\        V4      NK  	  up4       R#   + '       g   i     Lx; iu upi )r   z import sys, time;time.sleep(0.2)r   r   N)r   rM   ra   rb   rN   r   rK   rR   rL   idpidr	   check_warningsResourceWarningr)   r|  r*   rt   )r%   rT   identr  os   &    r   test_zombie_fast_process_del1POSIXProcessTestCase.test_zombie_fast_process_del?  s    
 cnnd01 %/OO$.OO	5
 	''1ee++R,ABBA C 9j001 MM%1C1C!D1CA"Q%1C!DE CB "Es   D?"E
?E	c           	        \         P                  ! \        P                  R R.\         P                  \         P                  R7      pV P                  VP                  P                  4       V P                  VP                  P                  4       \        V4      pVP                  p\        P                  ! R\        34      ;_uu_ 4        Rp\        P                  ! 4        RRR4       \         P"                  ! V\$        P&                  4       \(        '       d!   V P+                  \         P,                  4       M9T P/                  T\         P,                   Uu. uF  p\        V4      NK  	  up4       \0        P2                  ! R4       V P5                  \6        4      ;_uu_ 4        \         P                  ! \8        \         P                  \         P                  R7      ;_uu_ 4       p RRR4       RRR4       V P5                  \6        \         P:                  V^ 4       \(        '       d"   V P+                  \         P,                  4       R# T P=                  T\         P,                   Uu. uF  p\        V4      NK  	  up4       R#   + '       g   i     EL; iu upi   + '       g   i     L; i  + '       g   i     L; iu upi )r   zimport time;time.sleep(3)r   r   Nr  )r   rM   ra   rb   rN   r   rK   rR   rL   r  r  r	   r  r  r   
gc_collectr   r  r  r  r)   r|  r*   rt   r  r  rm   rY  r  waitpidr   )r%   rT   r  r  r  r  s   &     r   !test_leak_fast_process_del_killed6POSIXProcessTestCase.test_leak_fast_process_del_killedW  s    cnnd./ %/OO$.OO	5
 	''1ee++R,ABBA  C 	V^^$9j001 MM%1C1C!D1CA"Q%1C!DE 	

3w''!!/)3)3: :=A: ( 	'2::sA69j001UJ4F4F$G4FqRU4F$GH5 CBB "E: : (' %Hs=   JJ
)AJ7+J$	-J7.K

J	$J4/J77K	c                  a \         P                  ! R RR7      p\        P                  ! ^4      oV P	                  \        P
                  S4       \        P                  ! \        P                  V.\        P                  RV3R lR7      pVP                  4       w  r4\        \        \        VP                  R4      4      4      pV P!                  SV4       R# )rP  rM  rN  Tc                  2   < \         P                  ! ^S 4      # r   )r   r  )r  s   r   rS  CPOSIXProcessTestCase.test_close_fds_after_preexec.<locals>.<lambda>  s    2r   )rK   r  rU  rR  N)r   rS  r   r  r   rR   r   rM   ra   rb   rN   r   r)  r  r  r/  r   )r%   rU  rT   r   r|  r}  r  s   &     @r   test_close_fds_after_preexec1POSIXProcessTestCase.test_close_fds_after_preexec  s    $$^<LM	 VVAY"%cnni8$.OOt(>@ --/CV\\$%789]+r   c                F   ^ RI p\        P                  ! 4       p R p\        P                  ! 4        ^{R.RR.3R.^{RR.3R.R.^{R.3R.R.R^{33 Fv  w  rErgV P	                  \
        4      ;_uu_ 4       pVP                  WERR	WgR
R
R
R
^^^^RR^ R. ^ R
VR4       RRR4       V P                  R\        XP                  4      4       Kx  	  V'       g   \        P                  ! 4        R# R#   + '       g   i     LZ; i  T'       g   \        P                  ! 4        i i ; i)r   Nc                      R # r"   r2   r2   r   r   rS  5POSIXProcessTestCase.test_fork_exec.<locals>.<lambda>  s    4r   s   exe   envs   argTFztakes exactlyr2   rr   )_posixsubprocessrz  r{  r}  rm   r   r  r   ru   r   r|  )	r%   r  
gc_enabledfuncrA   exe_listr*  env_listr   s	   &        r   test_fork_exec#POSIXProcessTestCase.test_fork_exec  s     	 \\^
 	  DIIK F8TF843TF84F8SF84F8T3/	2- &&y11S$..b#BB1adAr1be% 2    #cmm2DE-20 

 % 21$ 

 s$   AD  5&C-1D  -C=8D    D c                f   ^ RI p ! R R4      p\        P                  ! 4       p \        P                  ! 4        RRRRRV! ^4      V! ^4      33 F  pV P	                  \
        RP                  V4      R7      ;_uu_ 4       pVP                  R.R.RVRR.R
R
R
R
^^^^RR^ RRRR
R4       RRR4       V P                  R	\        XP                  4      4       K  	  V'       g   \        P                  ! 4        R# R#   + '       g   i     LZ; i  T'       g   \        P                  ! 4        i i ; i)r   Nc                   0   a  ] tR tRt o RtR tR tRtV tR# )JPOSIXProcessTestCase.test_fork_exec_sorted_fd_sanity_check.<locals>.BadInti  Tc                    Wn         R # r"   )r;  )r%   r;  s   &&r   r   SPOSIXProcessTestCase.test_fork_exec_sorted_fd_sanity_check.<locals>.BadInt.__init__  s    "
r   c                X    V P                   '       d   R V n         V P                  # \        h)F)firstr;  r   r$   s   &r   __int__RPOSIXProcessTestCase.test_fork_exec_sorted_fd_sanity_check.<locals>.BadInt.__int__  s"    :::!&DJ::%  r   )r  r;  N)	r4   r5   r6   r7   r  r   r  r8   r9   r:   s   @r   BadIntr    s     E#! !r   r  zfds_to_keep={}r  s   falseTr  r~  rr   )rr   r  r        )ru   r  )      *   l            )r  r  )      r  rj  )r  rz  r{  r}  rm   r   rP  r  rt   ru   r   r|  )r%   r  r  r  r~  r   s   &     r   %test_fork_exec_sorted_fd_sanity_check:POSIXProcessTestCase.test_fork_exec_sorted_fd_sanity_check  s#    	 	! 	! \\^
	IIK !#F1I&  &&",33K@ ' B BEF$..!
XJk4&BB1adAdD"B mS-=>' * 

 B B 

 s$   AD *C=+1D =DD  D0c           	        \         P                  ! \        4      pT;_uu_ 4        \        P                  P                  VR 4      ;_uu_ 4       p\        VP                  n        VP                  4        VP                  P                  4        RRR4       RRR4       R#   + '       g   i     L; i  + '       g   i     R# ; i)rJ   N)r   rM   r   r   r  r  BrokenPipeErrorrR   r  r   assert_called_withr%   r  mock_proc_stdins   &  r   ,test_communicate_BrokenPipeError_stdin_closeAPOSIXProcessTestCase.test_communicate_BrokenPipeError_stdin_close  st     0T4::$$T7330?O!!-!!446 4TT33TTTs$   )B3A B 	B3 B0+B33C	c           	        \         P                  ! \        4      pT;_uu_ 4        \        P                  P                  VR 4      ;_uu_ 4       p\        VP                  n        VP                  R4       VP                  P                  R4       VP                  P                  4        RRR4       RRR4       R#   + '       g   i     L; i  + '       g   i     R# ; i)rJ      stuffN)r   rM   r   r   r  r  r  r   r  r   r#  rR   r  s   &  r   ,test_communicate_BrokenPipeError_stdin_writeAPOSIXProcessTestCase.test_communicate_BrokenPipeError_stdin_write  s     0T4::$$T7330?O!!-X&!!99(C!!99;	 4TT33TTTs$   )CAB<	*C<CCC 	c                   \         P                  ! \        P                  R .\         P                  \         P                  R7      pT;_uu_ 4        \
        P                  P                  VR4      ;_uu_ 4       p\        \        P                  R4      ;_uu_ 4       p\        VP                  n        VP                  4       VP                  n        VP!                  R4       VP                  P#                  4        RRR4       RRR4       RRR4       R#   + '       g   i     L"; i  + '       g   i     L-; i  + '       g   i     R# ; i)-hr   rJ   wbr  N)r   rM   ra   rb   rN   r   r  r  r^  r   ry  r  r3  r  rj  r!  r   r#  )r%   r  r  dev_nulls   &   r   ,test_communicate_BrokenPipeError_stdin_flushAPOSIXProcessTestCase.test_communicate_BrokenPipeError_stdin_flush  s      6&0oo'18 T4::$$T733RZZ&&(0?O!!-2://2CO""/X&!!99; ' 4TT&& 43TTTs=   )D<9#D)	A D<D)	D<D&!D)	)D94D<<E	c           	        \         P                  ! \        P                  R .\         P                  \         P                  R7      pT;_uu_ 4        \
        P                  P                  VR4      ;_uu_ 4       p\        VP                  n
        VP                  RR7       VP                  P                  4        RRR4       RRR4       R#   + '       g   i     L; i  + '       g   i     R# ; i)r  r   rJ   i  rk   N)r   rM   ra   rb   rN   r   r  r  r  rR   r  r   r#  r  s   &  r   9test_communicate_BrokenPipeError_stdin_close_with_timeoutNPOSIXProcessTestCase.test_communicate_BrokenPipeError_stdin_close_with_timeout  s      6&0oo'18 T4::$$T7330?O!!-S)!!99;	 4TT33TTTs%   )C 9AC	;C CC  C1	N
W_STOPCODEzneed _testcapi.W_STOPCODEc                   \         p\        P                  ! V4      p\        P                  ! VP
                  ^ R7       \        P                  ! ^4      p\        P                  ! RVP
                  V3R7      ;_uu_ 4        VP                  4       pRRR4       V P                  XR4       R#   + '       g   i     L$; i)zATest wait() behavior when waitpid returns WIFSTOPPED; issue29335.rH  r  r   N)r   r   rM   r   wait_processr  	_testcapir  r   r  r+   rc   )r%   rA   r  statusr   s   &    r   test_stopped!POSIXProcessTestCase.test_stopped  s    
 % 	TXX2%%a(ZZ/txx>PQQJ R 	R( RQs   B..B>	c                   \         P                  ! \        4      p\        P                  ! VP
                  ^ R7       V P                  VP                  4       \        P                  ! R4      ;_uu_ 4       pVP                  \        P                  4       RRR4       XP                  4        V P                  VP                  4       R#   + '       g   i     L=; i)r   r  zos.killN)r   rM   r   r   r  r  r|  r   r   r  r  r  r  assert_not_calledr2  )r%   r  	mock_kills   &  r   test_send_signal_race*POSIXProcessTestCase.test_send_signal_race$  s     0 	TXX2 	$//*ZZ	""iV^^, #
 	##% 	T__- #"s   6 CC	c                   \         P                  ! \        P                  R R.4      pVP                  '       g   VP                  4        K$  \        P                  P                  VRR R7      ;_uu_ 4        RVn        VP                  \        P                  4       RRR4       VP                  4        R#   + '       g   i     L"; i)r   zexit(1)r}  c                      R # r"   r2   r2   r   r   rS  =POSIXProcessTestCase.test_send_signal_race2.<locals>.<lambda>C  s    dr   newN)r   rM   ra   rb   r   r}  r   r  r  r  r  r  r  rS   s   & r   test_send_signal_race2+POSIXProcessTestCase.test_send_signal_race2:  s     cnndI>? ,,,FFHZZq&l;;ALMM&..) < 	
 <;s   7'B88C	c                    \         P                  ! \        P                  R R.\         P                  R7      p  VP                  RR7       R#   \         P                   d     K.  i ; i)r   z+import os, time; os.close(1), time.sleep(2)r   rj   rk   N)r   rM   ra   rb   rN   r   rn   r%   r  s   & r   1test_communicate_repeated_call_after_stdout_closeFPOSIXProcessTestCase.test_communicate_repeated_call_after_stdout_closeH  s`    !N!P'18    -,, s   A A'&A'c                    R \          R2p\        RV4      w  r#pV P                  VP                  4       R4       V P	                  RV4       R# )zif 1:
        import atexit
        import subprocess

        def dummy():
            pass

        class AtFinalization:
            def __del__(self):
                print("OK")
                subprocess.Popen(zu, preexec_fn=dummy)
                print("shouldn't be printed")
        at_finalization = AtFinalization()
        r   s   OKs0   preexec_fn not supported at interpreter shutdownN)r   r
   rc   r  rt   )r%   r   r  r   r   s   &    r   test_preexec_at_exit)POSIXProcessTestCase.test_preexec_at_exitS  sR    
" #2!2 3	 'tT2e,I3Or   
HAVE_VFORKz!vfork() not enabled by configure.zsubprocess._USE_POSIX_SPAWNFr  c                d   R pR.pV P                  RR7      ;_uu_ 4        \        P                  ! RV: R2V4      pV P                  VP                  R4       RRR4       RR	RR
\
        P                  ! 4        2R3RRR\
        P                  ! 4        2R3R3 Fj  w  rErgV P                  VR7      ;_uu_ 4        \        P                  ! RV RV: RV RV R2	V4      pV P                  VP                  R4       RRR4       Kl  	  R#   + '       g   i     L; i  + '       g   i     K  ; i)z	/bin/truez--trace=%processdefault_is_vfork)r8  zI                import subprocess
                subprocess.check_call([z])s	   (?i)vforkNr   setgidzgroup=Tsetuidzuser=z:                    import subprocess
                    zj
                    try:
                        subprocess.check_call(
                                [z
], **dict(zN))
                    except PermissionError:
                        if not z#:
                            raise)preexecr   zpreexec_fn=lambda: NoneF)r  r   zextra_groups=[]T)	r  r   strace_pythonassertRegexevent_bytesr   getgidgetuidassertNotRegex)	r%   true_binarystrace_argsvfork_resultsub_namepreamblesp_kwargexpect_permission_errornon_vfork_results	   &        r   test_vfork_used_when_expected2POSIXProcessTestCase.test_vfork_used_when_expectedf  sE   " ")*\\1\22(66((3b< 	L \55}E 3 B2		}5t<2ryy{m4d;:	F
AH 8,,#0#>#>J " #.
8* E  78 9"%  $  ##$4$@$@-P -,F
 32( -,,s   9D;ADD	D/)r  )netbsdopenbsd)zr4   r5   r6   r7   r&   r  r  r  r  r   rM   r  r   r  r  r  r  r(  r   r
  r  r  r  r-  r.  r  r  r  r  r  r  r!  r  r0  r)   r:  r>  rF  rJ  rM  rW  ra  ro  rs  r  ra   r  r  r  r   r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r%  r+  r3  r?  rJ  r[  rp  r  r5  st_devr  r   requires_mac_verr  r  r  r  r  r  r  r  r  r  r  cpython_onlyr  r  r  r  r  r  r  r  r  r  r  r  r+  r/  r   requires_stracer*  r8   r9   __classcell__r  r;   s   @@r   r  r  >  sg    >!BBB*J,,  
ZZ'(A )A  
ZZ'(: ):* __(;<<-/4/4,7  Y/JJGB	4J<>9>9  Z02KL1F M1Ff __WR,.PQ? R? Z02MN'I O'IR __WR,.PQ@ R@ [13OPE QE
 [13OPF QFA@8 __Y::gb'&:":68&8&(8	9?
?
	80 %!1!1 %2 __446KLE ME* __ "EGLGL(+	,LL!N(2 __S\\,,-BC9;;*)44>(-
)2&&&))),
!*+Z+`%()XK
K&K:&6I.'R-=` __S\\,,Y7 I IWWV_++rwwy/A/H/HHEGI9GI9` b!$H %HBE<U4	1"F0)IV," % %N ' 'R7<<
< $. > >$Y=46)6).,	P& __11,??8:""$	ZZ-592Q : %:2Q 2Qr   r  zWindows specific testsc                      a  ] tR tRt o R tR tR tR tR t]	P                  R 4       tR tR	 tR
 tR tR tR tR tR tR tR tR tR tR tR tR tR tRtV tR# )Win32ProcessTestCasei  c                    ^p^p\         P                  ! 4       pWn        W#n        \         P                  ! \
        VR7       R# )r   r  N)r   STARTUPINFOdwFlagswShowWindowr`   r   )r%   STARTF_USESHOWWINDOWSW_MAXIMIZEr  s   &   r   test_startupinfo%Win32ProcessTestCase.test_startupinfo  s<      ! ,,.2"- 	$/	1r   c                v    ^p^p\         P                  ! VVR7      p\         P                  ! \        VR7       R# )r   )r8  r9  r  N)r   r7  r`   r   )r%   STARTF_USERSHOWWINDOWr;  r  s   &   r   test_startupinfo_keywords.Win32ProcessTestCase.test_startupinfo_keywords  s8     !" ,,)#
 	$/	1r   c           
        \         P                  ! 4       p\         P                  Vn        \         P                  Vn        \        ^4       EF_  p\        p\        \        P                  R4      ;_uu_ 4       p\         P                  ! VV\         P                  VR7      pV;_uu_ 4        VP                  4        RRR4       V P                  VP                  ^ 4       RRR4       V P                  VP                  \         P                  4       V P!                  VP"                  4       V P!                  VP$                  4       V P!                  VP&                  4       V P                  VP
                  \         P                  4       V P                  VP(                  R. /4       EKb  	  R#   + '       g   i     L; i  + '       g   i     L; i)r  r  )rK   rL   r  Nhandle_list)r   r7  r:  r8  SW_HIDEr9  r[  r   r^  r   ry  rM   r   r   rc   r   r|  	hStdInput
hStdOutput	hStdErrorlpAttributeList)r%   r  r  r  nullr  s   &     r   test_startupinfo_copy*Win32ProcessTestCase.test_startupinfo_copy  sL    ,,.(==","4"4 qA!Cbjj#&&$!''/3/9/@/@4?A T$$&   !4 ' [00'<<>k334k445k334[44j6H6HI[88=":MN#  T '&s$   73G*F1;$G1G<GGc                    ^p\         P                  P                  R4       \        P                  ! \         P
                  R,           VR7       R# )   z'    a DOS box should flash briefly ...
z# -c "import time; time.sleep(0.25)"r  N)ra   rL   r   r   r`   rb   )r%   CREATE_NEW_CONSOLEs   & r   test_creationflags'Win32ProcessTestCase.test_creationflags  s8    

CD=>&8	:r   c                x    V P                  \        \        P                  \        P
                  R R.R R7       R# )r   r^   c                      ^# r  r2   r2   r   r   rS  8Win32ProcessTestCase.test_invalid_args.<locals>.<lambda>  s    Qr   r^  Nr  r$   s   &r   r   &Win32ProcessTestCase.test_invalid_args  s1    *joo>>457%. 	 	0r   c                     ! R  R\         4      pV P                  \        4      ;_uu_ 4        \        P                  ! \
        V! 4       R7       RRR4       R#   + '       g   i     R# ; i)c                       ] tR tRtRtRtR# )4Win32ProcessTestCase.test_issue31471.<locals>.BadEnvi  Nr2   )r4   r5   r6   r7   keysr8   r2   r   r   BadEnvrW    s    Dr   rY  r   N)dictrm   r   r   rM   r   )r%   rY  s   & r   test_issue31471$Win32ProcessTestCase.test_issue31471  s@    	T 	y))_&(; *)))s   "AA*	c                |    \         P                  ! \        P                  R R.RR7      pV P	                  V^/4       R# )r   r^   T)r  Nr_   rd   s   & r   r  #Win32ProcessTestCase.test_close_fds  s5    __cnnd8:(,. 	R r   c           
        ^ RI p\        P                  ! 4       pV P                  \        P                  V^ ,          4       V P                  \        P                  V^,          4       . pV F:  p\        P
                  ! VR4       VP                  VP                  V4      4       K<  	  \        P                  ! \        P                  RRP                  V^ ,          4      .\        P                  RR7      pVP                  4       w  rgV P                  VP                   ^ 4       \#        VP%                  4       4       \        P                  ! \        P                  RRP                  V^ ,          4      .\        P                  \        P                  RR7      pVP                  4       w  rgV P                  VP                   ^4       V P'                  RV4       . p\        P(                  ! 4       p	R	V/V	n        \        P                  ! \        P                  RRP                  V^ ,          4      .\        P                  \        P                  V	RR
7      pVP                  4       w  rgV P                  VP                   ^4       V P'                  RV4       \,        P.                  ! R\0        34      ;_uu_ 4        \        P(                  ! 4       p	R	VR,          /V	n        \        P                  ! \        P                  RRP                  V^ ,          4      .\        P                  \        P                  V	RR
7      pVP                  4       w  rgV P                  VP                   ^ 4       RRR4       R#   + '       g   i     R# ; i)r   NTr   z2import msvcrt; print(msvcrt.open_osfhandle({}, 0))FrQ  )rK   rL   r  s   OSErrorrC  )rK   rL   r  r  z.*overriding close_fds:NNN)r  r   r  r   rR   r{  r]  get_osfhandler   rM   ra   rb   rP  rN   r   rc   r   r  r  rt   r7  rH  r	   r  r  )
r%   r  r  rj  r  rT   rK   rL   rC  r  s
   &         r   test_close_fds_with_stdio.Win32ProcessTestCase.test_close_fds_with_stdio  s   ggi#a&)#a&)Br4(NN6//34  cnndRYYZabcZdeg$.OOuF q)FLLNcnndRYYZabcZdeg$.OOJOOW[] q)j&)  ,,.'4k&B#cnndRYYZabcZdeg$.OOJOO)4F q)j&) ++-E-;-= > >$002K+8'!**EK'  #..$"V"]"]^efg^h"i"k(2
-8EKA ]]_NFQ\\1-> > > >s   >B2M::N	c                v    \         P                  ! 4       p/ Vn        \         P                  ! \        VR 7       R# )r  Nr   r7  rH  r`   r   r%   r  s   & r   test_empty_attribute_list.Win32ProcessTestCase.test_empty_attribute_list-  s)     ,,.&(#$/	1r   c                z    \         P                  ! 4       pR . /Vn        \         P                  ! \        VR7       R# )rC  r  Nrd  re  s   & r   test_empty_handle_list+Win32ProcessTestCase.test_empty_handle_list3  s.     ,,.'4b&9#$/	1r   c                @   \         P                  P                  4       pR VR&   \        P                  ! R.^\        P
                  VR7      pV;_uu_ 4        V P                  RVP                  P                  4       4       RRR4       R#   + '       g   i     R# ; iphysalisr   r)  r  s   physalisN	r   r   r   r   rM   rN   rt   rK   r5  r  s   &  r   r  (Win32ProcessTestCase.test_shell_sequence9  sf    "$weWA$.OO!') QMM+qxx}}7 QQQs   +BB	c                >   \         P                  P                  4       pR VR&   \        P                  ! R^\        P
                  VR7      pV;_uu_ 4        V P                  RVP                  P                  4       4       RRR4       R#   + '       g   i     R# ; irl  rn  r  s   &  r   r  &Win32ProcessTestCase.test_shell_stringC  sd    "$wU!$.OO!') QMM+qxx}}7 QQQs   +BB	c           	     T   R F  p\         P                  P                  4       pRVR&   \        P                  ! R^\        P
                  VVR7      pV;_uu_ 4        V P                  RVP                  P                  4       V4       RRR4       K  	  R#   + '       g   i     K  ; i)ansirm  r   r)  )r  rK   r   r   N)rs  oemrn  )r%   encr   rT   s   &   r   test_shell_encodings)Win32ProcessTestCase.test_shell_encodingsM  sx    "CZZ__&F(F7O  a(2%+*-/A j!((--/3?  # s   ,BB'c                    \         P                  ! \        P                  R ,           4      pV P	                  V^/4       R# )z -c "import sys; sys.exit(47)"Nr_   rd   s   & r   r  %Win32ProcessTestCase.test_call_stringY  s.    __S^^=> ?R r   c                   \         P                  ! \        P                  R R.\         P                  \         P                  \         P                  R7      pV;_uu_ 4        VP
                  P                  ^4       \        W14      ! V!   VP                  4       w  rEV P                  VR4       VP                  4       pRRR4       V P                  X^ 4       R#   + '       g   i     L$; i)r   zif 1:
                             import sys, time
                             sys.stdout.write('x\n')
                             sys.stdout.flush()
                             time.sleep(30)
                             rI   r   N)r   rM   ra   rb   rN   rK   r5  r  r   rc   r+   r  )r%   r  rA   rT   r  rL   r   s   &&*    r   r  "Win32ProcessTestCase._kill_process_  s    cnnd 5! " $.??$.OO$.OO5 Q HHMM!A%IAVS)J  	J* Qs    ACC+	c                   \         P                  ! \        P                  R R.\         P                  \         P                  \         P                  R7      pV;_uu_ 4        VP
                  P                  ^4       \        P                  ! ^4       \        W14      ! V!   VP                  4       w  rEV P                  VR4       VP                  4       pRRR4       V P                  X^*4       R#   + '       g   i     L$; i)r   zif 1:
                             import sys, time
                             sys.stdout.write('x\n')
                             sys.stdout.flush()
                             sys.exit(42)
                             rI   r   N)r   rM   ra   rb   rN   rK   r5  r  r  r  r   rc   r+   )r%   r  rA   rT   r  rL   re   s   &&*    r   r  'Win32ProcessTestCase._kill_dead_processt  s    cnnd 5! " $.??$.OO$.OO5 Q HHMM!JJqMA%IAVS)B  	R  Qs    A5C11D	c                F    V P                  R \        P                  4       R# r  )r  r  r  r$   s   &r   r  %Win32ProcessTestCase.test_send_signal  s    =&..9r   c                (    V P                  R 4       R# r  r  r$   s   &r   r  Win32ProcessTestCase.test_kill  s    6"r   c                (    V P                  R 4       R# r  r  r$   s   &r   r  #Win32ProcessTestCase.test_terminate  s    ;'r   c                F    V P                  R \        P                  4       R# r  )r  r  r  r$   s   &r   r  *Win32ProcessTestCase.test_send_signal_dead  s    v~~>r   c                (    V P                  R 4       R# r  r  r$   s   &r   r  #Win32ProcessTestCase.test_kill_dead  s    'r   c                (    V P                  R 4       R# r  r  r$   s   &r   r  (Win32ProcessTestCase.test_terminate_dead  s    ,r   r2   N)r4   r5   r6   r7   r<  r@  rJ  rO  r   r   r0  r[  r  ra  rf  ri  r  r  rv  r  r  r  r  r  r  r  r  r  r8   r9   r:   s   @r   r5  r5    s     11 O6:0 < <!0.d1188
@!+*!.:#(?(- -r   r5  c                      a  ] tR tRt o  ! R R]P
                  4      t]P                  P                  ]P
                  R4      R 4       t
R tR tR tR	 tR
 tRtV tR# )	MiscTestsi  c                   :   a a ] tR tRt oRt. tV 3R ltRtVtV ;t	# )MiscTests.RecordingPopeni  z<A Popen that saves a reference to each instance for testing.c                ^   < \         SV `  ! V/ VB  V P                  P                  V 4       R # r"   )r  r   instances_createdr]  )r%   rA   rB   r  s   &*,r   r   !MiscTests.RecordingPopen.__init__  s)    Gd-f-""))$/r   r2   )
r4   r5   r6   r7   rE   r  r   r8   r9   r2  r3  s   @@r   RecordingPopenr    s     J	0 	0r   r  _communicatec                   \         Vn         \        P                  P	                  \
        P                  R4      ;_uu_ 4       p\         Vn        \        P                  P	                  \
        RV P                  4      ;_uu_ 4        V P                  \         4      ;_uu_ 4        V! \        P                  RR.3R\
        P                  /VB  RRR4       RRR4       VP                  R,           F8  pV P                  V\        P                  ! RR7      R	VP                   24       K:  	  . pVP                   F2  pV\        P                  ! R
R7      8X  g   K!  VP                  V4       K4  	  V P!                  VP"                  ^VP                  R7       V P%                  \'        V4      ^VP                  R7       RRR4       V P                  P(                  P+                  4       pVP-                  4        VP/                  4        V P%                  . V P                  P(                  4       R#   + '       g   i     ELo; i  + '       g   i     EL{; i  + '       g   i     L; i  T P                  P(                  P+                  4       pTP-                  4        TP/                  4        T P%                  . T P                  P(                  4       i ; i)a_  Fake a SIGINT happening during Popen._communicate() and ._wait().

This avoids the need to actually try and get test environments to send
and receive signals reliably across platforms.  The net effect of a ^C
happening during a blocking subprocess execution which we want to clean
up from is a KeyboardInterrupt coming out of communicate() or wait().
_waitrM   r   zLimport time
time.sleep(9)
import sys
sys.stderr.write('\n!runaway child!\n')rK   NrB  rk   z.no open-ended wait() after the first allowed: g      ?r  )KeyboardInterruptr  r   r  r  r   rM   r  rm   ra   rb   r  call_args_listr  r`   r]  assertLessEqual
call_countrc   r  r  re  r  r+   )r%   popenermock__communicaterB   
mock__waitr`   sigint_callsr  s   &&&,    r   _test_keyboardinterrupt_no_kill)MiscTests._test_keyboardinterrupt_no_kill  sD    ):%	H"":#3#3W== *;
&ZZ&&z7'+':':< <**+<=="M!N E (2'9'9E >DE >< '55b99D'' $))D"9L)889;< :
  "&55Dtyy66$++D1 6 $$Z%:%:A)3)B)B % D  \!2A%/%>%> ! @- >4 ));;??AGLLNLLNR!4!4!F!FG/ >==< < <	 >=4 ));;??AGLLNLLNR!4!4!F!FGs]   6I0 AII		$+H5I		BIA$II0 5I 	I			I	II-	(I0 0A,Kc                H    V P                  \        P                  R R7       R# gT㥛 @rk   N)r  r   r`   r$   s   &r   #test_call_keyboardinterrupt_no_kill-MiscTests.test_call_keyboardinterrupt_no_kill  s    ,,Z__e,Lr   c                H    V P                  \        P                  R R7       R# r  )r  r   r   r$   s   &r   "test_run_keyboardinterrupt_no_kill,MiscTests.test_run_keyboardinterrupt_no_kill  s    ,,Z^^U,Kr   c                .    R  pV P                  V4       R# )c                  t    \         P                  ! V / VB ;_uu_ 4       p\        h  + '       g   i     R # ; ir"   )r   rM   r  )rA   rB   unused_processs   *, r   popen_via_context_manager[MiscTests.test_context_manager_keyboardinterrupt_no_kill.<locals>.popen_via_context_manager  s,    !!42622n'' 322s   &7	N)r  )r%   r  s   & r   .test_context_manager_keyboardinterrupt_no_kill8MiscTests.test_context_manager_keyboardinterrupt_no_kill  s    	( 	,,-FGr   c                   V P                  \        P                  ! R 4      R4       V P                  \        P                  ! R 4      R4       Rp \        P
                  ! 4       p\        P                  P                  VR4      p\        P                  ! \        '       d   RMRV,           4      w  r4V P                  V^ 4       Ve   \        P                  ! V4       R# R#   Te   \        P                  ! T4       i i ; i)z
echo xyzzyxyzzyNr   ztype zcat )r   r  )rc   r   	getoutputgetstatusoutputr   rZ  r   r
  r  r)   r  rmdir)r%   dirr8  r   r   s   &    r   test_getoutputMiscTests.test_getoutput  s    --l;WE33LA%	' 	""$C77<<U+D'77%I6T9;NF* s s   A4C" "C?c                j   0 Rmp\        \        P                  4      p\        4       p^ RIp\        P                  P                  4        FM  w  rVVP                  R4      '       d   K  \        WdP                  34      '       d   K<  VP                  V4       KO  	  V P                  W#V,
          4       R# )z*Ensure that __all__ is populated properly.Nr  >   r  r  r  Handlerw  )r)  r   __all__r  __dict__itemsr  r  
ModuleTyperz  rc   )r%   intentionally_excludedexportedpossible_exportsr  r8  r;  s   &      r   test__all__MiscTests.test__all__  s    !Rz))*5%..446KDs##%"2"2!455  & 7 	6L#LMr   r2   N)r4   r5   r6   r7   r   rM   r  r   r  r  r  r  r  r  r  r  r8   r9   r:   s   @r   r  r    sh     0)) 0 
ZZz''8)H 9)HVMLH&N Nr   r  PollSelectorz!Test needs selectors.PollSelectorc                   ,   a  ] tR tRt o R tR tRtV tR# )ProcessTestCaseNoPolli  c                    \         P                  V n        \        P                  \         n        \
        P                  V 4       R # r"   )r   _PopenSelectororig_selector	selectorsSelectSelectorrG   r&   r$   s   &r   r&   ProcessTestCaseNoPoll.setUp  s,    '66$-$<$<
!d#r   c                Z    V P                   \        n        \        P	                  V 4       R # r"   )r  r   r  rG   r0   r$   s   &r   r0   ProcessTestCaseNoPoll.tearDown	  s    $($6$6
!  &r   )r  Nr3   r:   s   @r   r  r    s     $
' 'r   r  zWindows-specific testsc                   \   a a ] tR tRt oV 3R ltV 3R ltR tR tR tR t	R t
R	tVtV ;t# )
CommandsWithSpacesi  c                   < \         SV `  4        \        P                  ! R R4      w  rVP	                  4       V n        \        P                  ! VR4       \        P                  ! V4       R# )z.pyzte stsV   import sys;sys.stdout.write('%d %s' % (len(sys.argv), [a.lower () for a in sys.argv]))N)	r  r&   r   r  rC  r  r   r   rR   )r%   r  r  r  s   &  r   r&   CommandsWithSpaces.setUp  sN    ##E73[[^

 c 	
 	r   c                d   < \         P                  ! V P                  4       \        SV `  4        R # r"   )r   r  r  r  r0   r  s   &r   r0   CommandsWithSpaces.tearDown  s    
		$**r   c                :   \         P                  VR &   \         P                  ! V/ VB pV;_uu_ 4        V P                  VP                  P                  4       P                  R4      RV P                  ,          4       RRR4       R#   + '       g   i     R# ; i)rK   mbcsz2 [%r, 'ab cd']N)r   rN   rM   rc   rK   r5  r6  r  )r%   rA   rB   rT   s   &*, r   with_spacesCommandsWithSpaces.with_spaces  si    %??xd-f-Qhhmm%%f-$**, QQQs   AB		B	c           	     v    V P                  R \        P                  : RV P                  : RR: R 2^R7       R# )"" "ab cdr  Nr  ra   rb   r  r$   s   &r   test_shell_string_with_spaces0CommandsWithSpaces.test_shell_string_with_spaces'  s-    S^^TZZ-46=> 	 	@r   c                b    V P                  \        P                  V P                  R .^R7       R# )r  r  Nr  r$   s   &r   test_shell_sequence_with_spaces2CommandsWithSpaces.test_shell_sequence_with_spaces,  s$    #..$**g>aHr   c           	     r    V P                  R \        P                  : RV P                  : RR: R 24       R# )r  r  r  Nr  r$   s   &r   test_noshell_string_with_spaces2CommandsWithSpaces.test_noshell_string_with_spaces0  s$    S^^TZZ$& 	'r   c                ^    V P                  \        P                  V P                  R .4       R# )r  Nr  r$   s   &r   !test_noshell_sequence_with_spaces4CommandsWithSpaces.test_noshell_sequence_with_spaces5  s    #..$**g>?r   )r  )r4   r5   r6   r7   r&   r0   r  r  r  r  r  r8   r9   r2  r3  s   @@r   r  r    s1     @
I'
@ @r   r  c                   >   a  ] tR tRt o R tR tR tR tR tRt	V t
R# )	ContextManagerTestsi:  c                   \         P                  ! \        P                  R R.\         P                  \         P                  R7      ;_uu_ 4       pV P                  VP                  P                  4       R4       V P                  VP                  P                  4       R4       RRR4       V P                  XP                  P                  4       V P                  VP                  P                  4       R#   + '       g   i     L\; i)r   zAimport sys;sys.stdout.write('stdout');sys.stderr.write('stderr');r   s   stdouts   stderrN)r   rM   ra   rb   rN   rc   rK   r5  rL   r  r  r  s   & r   	test_pipeContextManagerTests.test_pipe<  s    s~~t => &0__%/__6 6
 :>T[[--/;T[[--/;6 	**+**+6 6s   AC88D	c                    \         P                  ! \        P                  R R.4      ;_uu_ 4       p RRR4       V P	                  XP
                  ^d4       R#   + '       g   i     L.; i)r   zimport sys; sys.exit(100)N)r   rM   ra   rb   rc   r   r  s   & r   r=  #ContextManagerTests.test_returncodeI  sQ    s~~t:< = =@D= 	#.	= =s   AA(	c                   \         P                  ! \        P                  R R.\         P                  R7      ;_uu_ 4       pVP                  R4       V P                  VP                  ^4       RRR4       R#   + '       g   i     R# ; i)r   z2import sys;sys.exit(sys.stdin.read() == 'context')r   s   contextNr  r  s   & r   r  *ContextManagerTests.test_communicate_stdinP  sn    s~~tHI $.??4 4 8<Z(T__a04 4 4 4s    .A88B		c           	     6   V P                  \        4      ;_uu_ 4        \        P                  ! \        \        P
                  \        P
                  R 7      ;_uu_ 4       p RRR4       RRR4       R#   + '       g   i     L; i  + '       g   i     R# ; i)r   N)rm   r  r   rM   r  rN   r  s   & r   r   %ContextManagerTests.test_invalid_argsX  sa    122!!/)3)3: :=A: 32: : 322s$   AB A4	"B4B?BB	c                   \         P                  ! \        \         P                  \        P
                  ^,          R7      pVP                  4       pVP                  P                  R\        P
                  ,          4       V P                  VP                  4       V P                  \        VP                  RRR4       V P                  VP                  ^ 4       V P                  VP                  P                   4       R# )z9Broken pipe error should not prevent wait() (Issue 21619))rJ   rX   r  N)r   rM   r   rN   r   r'  	__enter__rJ   r   r|  r   rm   rY  __exit__rc   r  r  r  s   & r   test_broken_pipe_cleanup,ContextManagerTests.test_broken_pipe_cleanup_  s    &0oo(/(=(=a(?A ~~ 	

 5 556$//*'4==$dC!,

))*r   r2   N)r4   r5   r6   r7   r  r=  r  r   r  r8   r9   r:   s   @r   r  r  :  s#     ,/1+ +r   r  __main__)nonexisting_i_hope)Ir  r   r6  r   test.supportr   r   r   r   r	   test.support.script_helperr
   r   ra   r  rP   r(  r   ra  r   r  r|  r  r  r+  ri  r   r  rz  r=  r'  test.support.os_helperr   r  r  r  r  rU  r  PGOr  has_subprocess_supportr  r)   r2  r  rM  NotADirectoryErrorr  r  rb   r   r   TestCaser    	Exceptionr=   rM   r?   rG   r3  r  r(  r  r-  r5  r  r.  r  r  r  r4   mainr2   r   r   <module>r     s      ( & " & ( 7  
  	  	           	   + ;;;


9
::%%%


=
>>\\W$	 @I I)');_M >>40( 8$$  &	 	>j.. >t-l t-n/@Jl @JF	c 
23]Q< ]Q 4]Q@3 
Y 89{-< {- :{-zaN!! aNH 
WY78:'O ':' 
Y 89(@, (@ :(@V3+, 3+l zMMO _z  I
  
C  
C  H
EsT   H2 I I I" I2 2	H?>H?	II	II"	I/.I/2I9