bg'vddlZddlmZmZmZddlmZddlmZm Z ddl m Z m Z ddl mZddlmZddlmZmZmZmZmZmZmZd d lmZmZmZeeefZ eeeefZ!d e!d efd Z"Gdde#Z$d efdZ%Gdde#Z&Gdde#Z'dZ(ee(e'j)e'j*gdS)N)wrapspartialreduce) TextIOWrapper)chain zip_longest)STDOUTPIPE) TemporaryFile)extend_docstring)UnionCallableListOptionalSequenceTupleDict)Mockcall_Callcommandreturncnt|tsdd|D}|S)N c3>K|]}tj|VdSN)pipesquote).0parts c/builddir/build/BUILD/cloudlinux-venv-1.0.7/venv/lib/python3.11/site-packages/testfixtures/popen.py zshell_join..s,AA5;t,,AAAAAA) isinstancestrjoin)rs r" shell_joinr(s: gs # #B((AAAAAAA Nr$c :eZdZdZ d dededed ed ef d Zd S)PopenBehaviourzp An object representing the behaviour of a :class:`MockPopen` when simulating a particular command. r$rstdoutstderr returncodepid poll_countcL||_||_||_||_||_dSr)r-r.r/r0r1)selfr-r.r/r0r1s r"__init__zPopenBehaviour.__init__s+  $$r$N)r$r$rr+r,)__name__ __module__ __qualname____doc__bytesintr4r$r"r*r*sx  % % % % %  %  % % % % % %r$r*c<tfd}|S)NcJ|jjfg|Ri||g|Ri|Sr)_recordr5)r3argskwfuncs r"recorderzrecord..recorder,sJ dm%3333333tD&4&&&2&&&r$)r)rArBs` r"recordrC+s3 4[[''''[' Or$c 6eZdZUdZdZeed<dZeed<dZ eed< dd Z d Z d Z d Z eddedefdZeddededeeeffdZedeefdZededdfdZeddZeddZdS)MockPopenInstancez; A mock process as returned by :class:`MockPopen`. Nstdinr-r.rFTr;cht|_|jj|_||_g|_|j|_t|}|j ||j }|td|zt|r |||}||_ |j}|j}|t krit#jt'|d|d}dd|D}d}|j|_d||fd||ffD]\}}}d}|t.urdt1}||||d|s|s|rt9||| }t;||||t.krIt|_d D]3} t?|j d | f}!|!tC|j| _"4|j#|_#d|_$||_%dS) Nz Nothing specified for command %r)rrFTr$c3K|]}||V dSrr;)r ls r"r#z-MockPopenInstance.__init__..is'#B#B!#BA#B#B#B#B#B#Br$r-r.r)encodingerrors)writecloserF)&rmockPopen_instanceclass_instance_mock root_callcalls all_callsr(commandsgetdefault_behaviourKeyErrorcallable behaviourr-r.r r from_iterabler splitlinesr'r1r r rLflushseekrsetattrrFrr>getattr side_effectr0r/r?)"r3 mock_classrQr?bufsize executablerFr-r. preexec_fn close_fdsshellcwdenvuniversal_newlines startupinfo creationflagsrestore_signalsstart_new_sessionpass_fdsrJrKtextcmdrY stdout_value stderr_value line_iteratornameoption mock_valuevaluemethod record_writess" r"r4zMockPopenInstance.__init__DsS&& )3)G  )"$ %/%9'++C1MNN  =CDD D I   <! #U;;;I)2 '  ' V  !/ ''--''--11M88#B#B}#B#B#BBBLL(3 v| , v| ,) ' ' $D&*E~~% J'''  1 %SSS)%(6RRRE D$ & & & & D==DJ* H H ' w6G H H :G F++77! )-! r$c |j|jfD]}tt|||i|t|jf|j|jffD]4\}}|tt|||i|5dSr) rPrNrr_rrRrQrSappend)r3namesr?r@rN base_callstores r"r>zMockPopenInstance._records,di7 6 6D (F7E4 ( ($ 5" 5 5 5 5 4:  ^T^ ,!  I I Iu LL: ::DGBGG H H H H  I Ir$c|Srr;r3s r" __enter__zMockPopenInstance.__enter__s r$c|||j|jfD]}|r|dSr)waitr-r.rM)r3exc_typeexc_valexc_tbstreams r"__exit__zMockPopenInstance.__exit__sG k4;.  F    r$timeoutrc2|jj|_|jS)z/Simulate calls to :meth:`subprocess.Popen.wait`)rYr/)r3rs r"rzMockPopenInstance.waits.3r$inputc|jj|_|jo|j|jo|jfS)z6Simulate calls to :meth:`subprocess.Popen.communicate`)rYr/r-readr.)r3rrs r" communicatezMockPopenInstance.communicatesJ.3 2 0 0 2 2 2 0 0 2 24 4r$cr|jr|j|xjdzc_dS|jj|_|jS)z/Simulate calls to :meth:`subprocess.Popen.poll`Nr)r1r/rYrs r"pollzMockPopenInstance.polls@o $/"9 OOq OO4 .3r$signalcdS)z6Simulate calls to :meth:`subprocess.Popen.send_signal`Nr;)r3rs r" send_signalzMockPopenInstance.send_signal  r$cdS)z4Simulate calls to :meth:`subprocess.Popen.terminate`Nr;rs r" terminatezMockPopenInstance.terminaterr$cdS)z/Simulate calls to :meth:`subprocess.Popen.kill`Nr;rs r"killzMockPopenInstance.killrr$)rNNNNNFFNNFNrTFr;NNNr)NN)rN)r5r6r7r8rFr__annotations__r-r r.r4r>rrrCfloatr:rAnyStrrrrrrrrr;r$r"rErE3sE4!FM   !FM   .215DH.3DH3526@"@"@"@"DIII  ES V  4444%PVX^P^J_444 V4   hsm    V   # $    V      V      V   r$rEceZdZUdZdZeed<dZdZ dd e d e d e d e de de de ee ffdZ ddZdZdS) MockPopena A specialised mock for testing use of :class:`subprocess.Popen`. An instance of this class can be used in place of the :class:`subprocess.Popen` and is often inserted where it's needed using :func:`unittest.mock.patch` or a :class:`~testfixtures.Replacer`. NrVcHi|_t|_g|_dSr)rTrrNrSrs r"r4zMockPopen.__init__s!35 && &(r$c0|t|||||S|Sr)r*r3r-r.r/r0r1rYs r"_resolve_behaviourzMockPopen._resolve_behaviours-  ! C  r$r$rr+r,rr-r.r/r0r1rYcd||||||||jt|<dS)z Set the behaviour of this mock when it is used to simulate the specified command. :param command: A :class:`str` representing the command to be simulated. N)rrTr()r3rr-r.r/r0r1rYs r" set_commandzMockPopen.set_commands; .2-D-D FJZ. .  j))***r$cD||||||||_dS)z Set the behaviour of this mock when it is used to simulate commands that have no explicit behavior specified using :meth:`~MockPopen.set_command`. N)rrVrs r" set_defaultzMockPopen.set_defaults/"&!8!8 FJZ" " r$c|jj|i|tj|i|}|j|t ||g|Ri|Sr)rNPopenrrSr{rE)r3r?r@rQs r"__call__zMockPopen.__call__se $$$$J+++  i((( y>4>>>2>>>r$)r$r$rr+r,N)r5r6r7r8rVr*rr4rr&r9r:r rrrrr;r$r"rrs)-~,,,((( 9=           ^X56    (>?6:     ?????r$ra :param stdout: :class:`bytes` representing the simulated content written by the process to the stdout pipe. :param stderr: :class:`bytes` representing the simulated content written by the process to the stderr pipe. :param returncode: An integer representing the return code of the simulated process. :param pid: An integer representing the process identifier of the simulated process. This is useful if you have code the prints out the pids of running processes. :param poll_count: Specifies the number of times :meth:`~MockPopenInstance.poll` can be called before :attr:`~MockPopenInstance.returncode` is set and returned by :meth:`~MockPopenInstance.poll`. If supplied, ``behaviour`` must be either a :class:`PopenBehaviour` instance or a callable that takes the ``command`` string representing the command to be simulated and the ``stdin`` supplied when instantiating the :class:`subprocess.Popen` with that command and should return a :class:`PopenBehaviour` instance. )+r functoolsrrrior itertoolsrr subprocessr r tempfiler testfixtures.utilsr typingr rrrrrrrNrrrCallr&r9rCommandr(objectr*rCrErset_command_paramsrrr;r$r"rs  ,,,,,,,,,,((((((((########""""""//////IIIIIIIIIIIIIIIIII++++++++++ sEz  Xc]" #C %%%%%V%%%*HL L L L L L L L ^=?=?=?=?=?=?=?=?@6#')>?AAAAAr$