+
    Dfj@5                         R t ^ RIt^ RIt^ RIt^ RIt^ RIt^ RIHt ^ RIH	t	H
t
HtHt ^ RIHt ^ RIHt ^ RIHt ^ RIHtHt  ! R R	]4      t ! R
 R]4      t ! R R]4      tR# )zD
Test running processes with the APIs in L{twisted.internet.utils}.
N)skipIf)error
interfacesreactorutils)Deferred)platform)SuppressedWarningsTests)SynchronousTestCaseTestCasec                     a  ] tR t^t o Rt]P                  ! ]R4      f   RtRt	Rt
]P                  tR tR tR tR tR tR	 t]! ]P,                  ! 4       R
4      R 4       tR tR tR tR tR tR tR tR tR t Rt!V t"R# )ProcessUtilsTestszh
Test running a process using L{getProcessOutput}, L{getProcessValue}, and
L{getProcessOutputAndValue}.
Nz)reactor doesn't implement IReactorProcessc                F   V P                  4       p\        VR4      ;_uu_ 4       pVP                  \        P                  P                  V4      \        P                  ,           4       RRR4       \        P                  P                  V4      #   + '       g   i     L/; i)zR
Write the given list of lines to a text file and return the absolute
path to it.
wtN)mktempopenwriteoslinesepjoinpathabspath)selfsourceLinesscript
scriptFiles   &&  :/usr/lib/python3/dist-packages/twisted/test/test_iutils.pymakeSourceFile ProcessUtilsTests.makeSourceFile$   sc    
 &$:RZZ__[9BJJFG  wwv&&  s   ABB 	c                    V P                  . RO4      p\        P                  ! V P                  RV.4      pVP	                  V P
                  R4      # )z
L{getProcessOutput} returns a L{Deferred} which fires with the complete
output of the process it runs after that process exits.
-us   hello world
)
import syszfor s in b'hello world\n':z    s = bytes([s])z    sys.stdout.buffer.write(s)z    sys.stdout.flush()r   r   getProcessOutputexeaddCallbackassertEqualr   r   ds   &  r   test_outputProcessUtilsTests.test_output.   sN    
 ((

 ""488dJ-?@}}T--/?@@    c                   a  S P                  RR.4      p\        P                  ! S P                  RV.4      pS P	                  V\
        4      pV 3R lpVP                  V4       V# )z
The L{Deferred} returned by L{getProcessOutput} is fired with an
L{IOError} L{Failure} if the child process writes to stderr.
r!   z!sys.stderr.write("hello world\n")r    c                 X   < SP                  V P                  \        P                  4      # N)assertFailureprocessEndedr   ProcessDone)errr   s   &r   cbFailed?ProcessUtilsTests.test_outputWithErrorIgnored.<locals>.cbFailedL   s"    %%c&6&68I8IJJr+   )r   r   r#   r$   r/   IOErrorr%   )r   r   r(   r3   s   f   r   test_outputWithErrorIgnored-ProcessUtilsTests.test_outputWithErrorIgnored?   sf     ((?@

 ""488dJ-?@q'*	K 	
hr+   c                    V P                  . RO4      p\        P                  ! V P                  RV.RR7      pVP	                  V P
                  R4      # )z
If a C{True} value is supplied for the C{errortoo} parameter to
L{getProcessOutput}, the returned L{Deferred} fires with the child's
stderr output as well as its stdout output.
r    T)errortoos   foofoo)r!   zsys.stdout.write("foo")sys.stdout.flush()zsys.stderr.write("foo")sys.stderr.flush()r"   r'   s   &  r   test_outputWithErrorCollected/ProcessUtilsTests.test_outputWithErrorCollectedR   sO     ((


 ""488dJ-?$O}}T--y99r+   c                    V P                  R.4      p\        P                  ! V P                  RV.4      pVP	                  V P
                  ^4      # )zd
The L{Deferred} returned by L{getProcessValue} is fired with the exit
status of the child process.
zraise SystemExit(1)r    )r   r   getProcessValuer$   r%   r&   r'   s   &  r   
test_valueProcessUtilsTests.test_valueg   sJ    
 ((*?)@A
!!$((T:,>?}}T--q11r+   c                   a  S P                  . RO4      pV 3R lp\        P                  ! S P                  RV.4      pVP	                  V4      # )z
The L{Deferred} returned by L{getProcessOutputAndValue} fires with a
three-tuple, the elements of which give the data written to the child's
stdout, the data written to the child's stderr, and the exit status of
the child.
c                 ~   < V w  rpSP                  VR 4       SP                  VR4       SP                  V^4       R# )s   hello world!
s   goodbye world!
Nr&   )out_err_codeoutr2   coder   s   &   r   gotOutputAndValue@ProcessUtilsTests.test_outputAndValue.<locals>.gotOutputAndValue   s>    )NCdS"34S"56T1%r+   r    )r!   z*sys.stdout.buffer.write(b'hello world!\n')z,sys.stderr.buffer.write(b'goodbye world!\n')zsys.exit(1)r   r   getProcessOutputAndValuer$   r%   r   r   rH   r(   s   f   r   test_outputAndValue%ProcessUtilsTests.test_outputAndValueq   sL     ((

	& **488dJ5GH}}.//r+   z"Windows doesn't have real signals.c                   a  S P                  . RO4      pV 3R lp\        P                  ! S P                  RV.4      pS P	                  V\
        4      pVP                  V4      # )z
If the child process exits because of a signal, the L{Deferred}
returned by L{getProcessOutputAndValue} fires a L{Failure} of a tuple
containing the child's stdout, stderr, and the signal which caused
it to exit.
c                    < V w  rpSP                  VR 4       SP                  VR4       SP                  V\        P                  4       R# )s   stdout bytes
s   stderr bytes
N)r&   signalSIGKILL)out_err_sigrF   r2   sigr   s   &   r   rH   >ProcessUtilsTests.test_outputSignal.<locals>.gotOutputAndValue   sB    'MCcS"34S"34S&..1r+   r    )zimport sys, os, signalz"sys.stdout.write('stdout bytes\n')z"sys.stderr.write('stderr bytes\n')r:   r;   z$os.kill(os.getpid(), signal.SIGKILL))r   r   rK   r$   r/   tupler%   rL   s   f   r   test_outputSignal#ProcessUtilsTests.test_outputSignal   s^     ((	

	2 **488dJ5GHq%(}}.//r+   c                F   \         P                  P                  V P                  4       4      p\         P                  ! V4       V P                  R R.4      pV! V P                  RV.VR7      pVP                  W#P                  \        P                  ! 4       4      4       V# )import os, syszsys.stdout.write(os.getcwd())r    )r   )r   r   r   r   makedirsr   r$   r%   encodesysgetfilesystemencoding)r   utilFunccheckdirr   r(   s   &&&   r   	_pathTestProcessUtilsTests._pathTest   s{    ggoodkkm,
C((>?

 TXXj1<	eZZ(A(A(CDEr+   c                V    V P                  \        P                  V P                  4      # )zg
L{getProcessOutput} runs the given command with the working directory
given by the C{path} parameter.
)rb   r   r#   r&   r   s   &r   test_getProcessOutputPath+ProcessUtilsTests.test_getProcessOutputPath   s!    
 ~~e44d6F6FGGr+   c                P   a  V 3R lpS P                  \        P                  V4      # )zf
L{getProcessValue} runs the given command with the working directory
given by the C{path} parameter.
c                 ,   < SP                  V ^ 4       R#     NrD   resultignoredr   s   &&r   r`   9ProcessUtilsTests.test_getProcessValuePath.<locals>.check       VQ'r+   )rb   r   r?   r   r`   s   f r   test_getProcessValuePath*ProcessUtilsTests.test_getProcessValuePath   s!    	( ~~e33U;;r+   c                P   a  V 3R lpS P                  \        P                  V4      # )zo
L{getProcessOutputAndValue} runs the given command with the working
directory given by the C{path} parameter.
c                 X   < V w  r#pSP                  W!4       SP                  V^ 4       R# rj   rD   out_err_statusra   rF   r2   statusr   s   &&   r   r`   BProcessUtilsTests.test_getProcessOutputAndValuePath.<locals>.check   +    -CfS&VQ'r+   )rb   r   rK   rq   s   f r   !test_getProcessOutputAndValuePath3ProcessUtilsTests.test_getProcessOutputAndValuePath   s!    	(
 ~~e<<eDDr+   c                   \         P                  P                  V P                  4       4      p\         P                  ! V4       V P                  . RO4      pV P                  \         P                  \         P                  ! 4       4       \         P                  ! V4       \        P                  ! \         P                  ! R4      P                  4      p\         P                  ! V\        P                  \        P                  ,          4       V P                  \         P                  W54       V! V P                  RV.4      pVP!                  W#P#                  \$        P&                  ! 4       4      4       V# )rZ   .r    )rZ   zcdir = os.getcwd()zsys.stdout.write(cdir))r   r   r   r   r[   r   
addCleanupchdirgetcwdstatS_IMODEst_modechmodS_IXUSRS_IRUSRr$   r%   r\   r]   r^   )r   r_   r`   ra   r   originalModer(   s   &&&    r   _defaultPathTest"ProcessUtilsTests._defaultPathTest   s    ggoodkkm,
C((N


 	"))+.
 ||BGGCL$8$89
 	dllT\\12
 	#4TXXj12	eZZ(A(A(CDEr+   c                V    V P                  \        P                  V P                  4      # )z
If no value is supplied for the C{path} parameter, L{getProcessOutput}
runs the given command in the same working directory as the parent
process and succeeds even if the current working directory is not
accessible.
)r   r   r#   r&   re   s   &r    test_getProcessOutputDefaultPath2ProcessUtilsTests.test_getProcessOutputDefaultPath   s#     $$U%;%;T=M=MNNr+   c                P   a  V 3R lpS P                  \        P                  V4      # )z
If no value is supplied for the C{path} parameter, L{getProcessValue}
runs the given command in the same working directory as the parent
process and succeeds even if the current working directory is not
accessible.
c                 ,   < SP                  V ^ 4       R# rj   rD   rl   s   &&r   r`   @ProcessUtilsTests.test_getProcessValueDefaultPath.<locals>.check  rp   r+   )r   r   r?   rq   s   f r   test_getProcessValueDefaultPath1ProcessUtilsTests.test_getProcessValueDefaultPath   s#    	( $$U%:%:EBBr+   c                P   a  V 3R lpS P                  \        P                  V4      # )z
If no value is supplied for the C{path} parameter,
L{getProcessOutputAndValue} runs the given command in the same working
directory as the parent process and succeeds even if the current
working directory is not accessible.
c                 X   < V w  r#pSP                  W!4       SP                  V^ 4       R# rj   rD   rv   s   &&   r   r`   IProcessUtilsTests.test_getProcessOutputAndValueDefaultPath.<locals>.check  rz   r+   )r   r   rK   rq   s   f r   (test_getProcessOutputAndValueDefaultPath:ProcessUtilsTests.test_getProcessOutputAndValueDefaultPath  s#    	(
 $$U%C%CUKKr+   c                   a a S P                  RR.4      pRo\        P                  ! S P                  RV.SR7      pV V3R lpVP	                  V4       V# )zl
Standard input can be made available to the child process by passing
bytes for the `stdinBytes` parameter.
r!   z"sys.stdout.write(sys.stdin.read())s   These are the bytes to see.r    )
stdinBytesc                 Z   < V w  rpSP                  SV4       SP                  ^ V4       R# rj   )assertInr&   )rE   rF   r2   rG   r   r   s   &   r   rH   PProcessUtilsTests.test_get_processOutputAndValueStdin.<locals>.gotOutputAndValue(  s,    )NCd MM*c*Q%r+   rJ   )r   r   r(   rH   r   s   f   @r   #test_get_processOutputAndValueStdin5ProcessUtilsTests.test_get_processOutputAndValueStdin  sb    
 ((4

 4
**HH:!
	& 	
'(r+    )#__name__
__module____qualname____firstlineno____doc__r   IReactorProcessr   skipoutputvaluer]   
executabler$   r   r)   r6   r<   r@   rM   r   r   	isWindowsrW   rb   rf   rr   r{   r   r   r   r   r   __static_attributes____classdictcell____classdict__s   @r   r   r      s     
 !!'408:FE
..C'A"&:*202 H "FG0 H0>H	<E<OCL r+   r   c                   *   a  ] tR tRt o RtR tRtV tR# )SuppressWarningsTestsi4  z&
Tests for L{utils.suppressWarnings}.
c                d  a . oV3R lpV P                  \        RV4       R p\        P                  ! VR	\	        RR7      34      pV! R4       V P                  \        S4      ^4       V! R4       V P                  \        S4      ^4       V! R4       V P                  \        S4      ^4       R# )
z[
L{utils.suppressWarnings} decorates a function so that the given
warnings are suppressed.
c                 ,   < SP                  W34       R # r.   )append)r   akwrm   s   &*,r   showwarning@SuppressWarningsTests.test_suppressWarnings.<locals>.showwarning@  s    MM1'"r+   r   c                 2    \         P                  ! V 4       R # r.   )warningswarn)msgs   &r   f6SuppressWarningsTests.test_suppressWarnings.<locals>.fE  s    MM#r+   zThis is message)messagezSanity check messagezUnignored messageN)ignore)patchr   r   suppressWarningsdictr&   len)r   r   r   grm   s   &   @r   test_suppressWarnings+SuppressWarningsTests.test_suppressWarnings9  s    
 	# 	

8]K8	 ""1{DAR4S&TU 	

 !Va( 	

Va( 	

Va(r+   r   N)r   r   r   r   r   r   r   r   r   s   @r   r   r   4  s     ) )r+   r   c                   T   a  ] tR tRt o Rt]! ]P                  4      tR tR t	Rt
V tR# )DeferredSuppressedWarningsTestsiZ  zT
Tests for L{utils.runWithWarningsSuppressed}, the version that supports
Deferreds.
c                J  a R/ 3R/ 3.p\        4       oV P                  VV3R l4       \        P                  ! R4       SP	                  ^4       \        P                  ! R4       T P                  R.V P                  4        Uu. uF  q"R,          NK  	  up4       R# u upi )z
If the function called by L{utils.runWithWarningsSuppressed} returns a
C{Deferred}, the warning filters aren't removed until the Deferred
fires.
c                     < S # r.   r   rm   s   r   <lambda>GDeferredSuppressedWarningsTests.test_deferredCallback.<locals>.<lambda>l  s    r+   
ignore fooignore foo 2r   Nr   z.*foo.*r   z.*bar.*)r   runWithWarningsSuppressedr   r   callbackr&   flushWarnings)r   filterswrm   s   &  @r   test_deferredCallback5DeferredSuppressedWarningsTests.test_deferredCallbackd  s     *2.1F0KL&&w?l#n%.)$BTBTBV+WBVQiLLBV+WX+Ws   B 
c                ~  a R/ 3R/ 3.p\        4       oV P                  VV3R l4      p\        P                  ! R4       SP	                  \        4       4       VP                  R 4       \        P                  ! R4       T P                  R.V P                  4        Uu. uF  q3R,          NK  	  up4       R# u upi )	z
If the function called by L{utils.runWithWarningsSuppressed} returns a
C{Deferred}, the warning filters aren't removed until the Deferred
fires with an errback.
c                     < S # r.   r   r   s   r   r   FDeferredSuppressedWarningsTests.test_deferredErrback.<locals>.<lambda>z  s    Fr+   r   c                 ,    V P                  \        4      # r.   )trapZeroDivisionError)r   s   &r   r   r   }  s    qvv&78r+   r   r   Nr   r   )	r   r   r   r   errbackr   
addErrbackr&   r   )r   r   r(   r   rm   s   &   @r   test_deferredErrback4DeferredSuppressedWarningsTests.test_deferredErrbackr  s     *2.1F0KL**7NCl#(*+	89n%.)$BTBTBV+WBVQiLLBV+WX+Ws    B:
r   N)r   r   r   r   r   staticmethodr   r   r   r   r   r   r   s   @r   r   r   Z  s/      !-U-L-L MYY Yr+   r   )r   r   rQ   r   r]   r   unittestr   twisted.internetr   r   r   r   twisted.internet.deferr   twisted.python.runtimer   twisted.python.test.test_utilr	   twisted.trial.unittestr
   r   r   r   r   r   r+   r   <module>r      s\   
 
   
   > > + + A @Z Zz#)/ #)L%Y&= %Yr+   