R 3t'VdZddlmZddlmZddlmZddlmZddlmZddlm Z ddlm Z dd lm Z dd lm Z dd lm Z dd lmZdd lmZddlmZddlmZddlmZddlmZddlmZddlmZddlmZddlmZGddZdS)zFakeProcess class declaration) defaultdict)deque)Any)Callable)ClassVar) DefaultDict)Deque)Dict)List)Optional)Type)Union) exceptions)ProcessDispatcher)ProcessRecorder)COMMAND)OPTIONAL_TEXT_OR_ITERABLE)Command)Programc|eZdZUdZeZeeeed<e Z eee ed<ddZ d d e d e d e d ed eedeedeeeefdeededeedefdZeZ d!d e deddfdZd"dZdededdfdZdeddfdZd e defdZdeddfdZe d"dZ!dS)# FakeProcessz-Main class responsible for process operationsanyprogramreturnNctt|_t|_d|_d|_t |_dS)NF)rr definitionscalls_allow_unregistered_keep_last_processrselfs p/builddir/build/BUILD/cloudlinux-venv-1.0.10/venv/lib/python3.11/site-packages/pytest_subprocess/fake_process.py__init__zFakeProcess.__init__ sAKV L L &+WW ). (-$rrcommandstdoutstderr returncodewaitcallbackcallback_kwargssignal_callback occurrencesstdin_callablec ||tjdt|tst|}t } |j|||||||||| | d g| z| S)a Main method for registering the subprocess instances. Args: command: register the command that will be faked stdout: value of the standard output stderr: value of the error output returncode: return code of the faked process wait: artificially wait for the process to finish callback: function that will be executed instead of the process callback_kwargs: keyword arguments that will be passed into callback occurrences: allow multiple usages of the same command stdin_callable: function that will interact with stdin NzbThe 'callback' and 'wait' arguments cannot be used together. Add sleep() to your callback instead.) r&r'r(r)r*r+r,r-r/recorder)rIncorrectProcessDefinition isinstancerrrextend) r"r&r'r(r)r*r+r,r-r.r/r1s r#registerzFakeProcess.register*s6   47B '7++ 'g&&G"$$ !(( '$$", ('6'6&4 (       $r%ct|tst|}|j|dg|zdS)z Allow to use a real subprocess together with faked ones. Args: command: allow to execute the supplied command occurrences: allow multiple usages of the same command TN)r3rrr4)r"r&r.s r# pass_commandzFakeProcess.pass_commanddsL'7++ 'g&&G !(($+)=>>>>>r%c.tj||SN)rr5r!s r# __enter__zFakeProcess.__enter__us"4((( r%argskwargsc.tj|dSr9)r deregister)r"r;r<s r#__exit__zFakeProcess.__exit__ys$T*****r%allowc||_dS)z Allow / block unregistered processes execution. When allowed, the real subprocesses will be called. Blocking will raise the exception. Args: allow: decide whether the unregistered process shall be allowed N)r)r"r@s r#allow_unregisteredzFakeProcess.allow_unregistered|s$)   r%ct|tst|ttt fd|jS)z Count how many times a certain command was called. Can be used together with `fake_process.any()`. Args: command: lookup command Returns: number of times a command was called c|kSr9)elemcommand_instances r#z(FakeProcess.call_count..s T5E-Er%)r3rlentuplefilterr)r"r&rGs @r# call_countzFakeProcess.call_countsQ'7++ 0&w// 5 E E E EtzRRSSTTTr%keepc||_dS)z Keep last process definition from being removed. That can allow / block multiple execution of the same command. Args: keep: decide whether last process shall be kept N)r )r"rMs r#keep_last_processzFakeProcess.keep_last_processs#'r%c|S)zAReturn a new FakeProcess instance to use it as a context manager.rE)clss r#contextzFakeProcess.contextssuu r%)rN) NNrNNNNrN)r)rr)"__name__ __module__ __qualname____doc__rrrr __annotations__rrr$rrintr floatrr strAnyTyperr5register_subprocessr7r:r r?boolrBrLrO classmethodrRrEr%r#rrs177"C$s) """'.GXd7m $...%%%%-1,0 $'+8<.2-1666*6* 6  6 uo 68$6"$sG|"456"(+66!*6 6666p# ????  ????"+d+d+t++++)))))) U' Uc U U U U'd't''''[r%rN)rV collectionsrrtypingrr[rrrr r r r r rrprocess_dispatcherrprocess_recorderrtypesrrutilsrrrrEr%r#rfs########!!!!!!111111------,,,,,,HHHHHHHHHHr%