U a>@sddlZddlZddlZddlZddlZddlZddlZddlZddl m Z ddl m Z ddl m Z ddl mZddlmZejrddlmZGd d d Zejejeejdd d d ZGdddejZejejeeejfeejdddZ GdddZ!GdddZ"dS)N) TracebackType) formatting)termui)utils)_find_binary_reader) BaseCommandc@seZdZejejddddZeejdddZe e dd d Z de e d d dZ de e d ddZ de e d ddZeje dddZeje dddZedddZdS) EchoingStdinN)inputoutputreturncCs||_||_d|_dS)NF)_input_output_paused)selfr r rNC:\Users\vtejo\AppData\Local\Temp\pip-unpacked-wheel-s9fh6ldx\click\testing.py__init__szEchoingStdin.__init__)xr cCs t|j|SN)getattrr )rrrrr __getattr__szEchoingStdin.__getattr__)rvr cCs|js|j||Sr)rrwrite)rrrrr_echos zEchoingStdin._echo)nr cCs||j|Sr)rr readrrrrrr#szEchoingStdin.readcCs||j|Sr)rr read1rrrrr&szEchoingStdin.read1cCs||j|Sr)rr readlinerrrrr )szEchoingStdin.readliner csfddjDS)Ncsg|]}|qSrr.0rrrr -sz*EchoingStdin.readlines..)r readlinesr%rr%rr',szEchoingStdin.readlinescstfddjDS)Nc3s|]}|VqdSrr"r#r%rr 0sz(EchoingStdin.__iter__..)iterr r%rr%r__iter__/szEchoingStdin.__iter__cCs t|jSr)reprr r%rrr__repr__2szEchoingStdin.__repr__)r)r)r)__name__ __module__ __qualname__tBinaryIOrstrAnyrbytesrintrrr Listr'Iteratorr*r,rrrrr sr )streamr ccs&|dkrdVnd|_dVd|_dS)NTF)r)r8rrr _pause_echo6s r9csReZdZejeeejddfdd ZeedddZ eeddd Z Z S) _NamedTextIOWrapperN)buffernamemodekwargsr c s tj|f|||_||_dSr)superr_name_mode)rr;r<r=r> __class__rrrAsz_NamedTextIOWrapper.__init__r!cCs|jSr)r@r%rrrr<Hsz_NamedTextIOWrapper.namecCs|jSr)rAr%rrrr=Lsz_NamedTextIOWrapper.mode) r-r.r/r0r1r2r3rpropertyr<r= __classcell__rrrBrr:@sr:)r charsetr cCsdt|dr0tttj|}|dk r(|Std|dkr>d}nt|trR||}t tt |S)Nrz.Could not find binary reader for input stream.) hasattrrr0castIO TypeError isinstancer2encodeioBytesIOr4)r rFrrrrmake_input_streamQs   rPc @seZdZdZddeejeejeeje ejej ej e e e fdddZ eeddd Zeedd d Zeedd d ZedddZdS)Resultz3Holds the captured result of an invoked CLI script.N CliRunnerrunner stdout_bytes stderr_bytes return_value exit_code exceptionexc_infocCs.||_||_||_||_||_||_||_dSrrS)rrTrUrVrWrXrYrZrrrrhs zResult.__init__r!cCs|jS)z(The (standard) output as unicode string.)stdoutr%rrrr sz Result.outputcCs|j|jjdddS)z&The standard output as unicode string.replace  )rUdecoderTrFr\r%rrrr[sz Result.stdoutcCs,|jdkrtd|j|jjdddS)z%The standard error as unicode string.Nzstderr not separately capturedr\r]r^)rV ValueErrorr_rTrFr\r%rrrstderrs  z Result.stderrcCs,|jrt|jnd}dt|jd|dS)Nokay< >)rYr+typer-)rZexc_strrrrr,szResult.__repr__)N)r-r.r/__doc__r4r0Optionalr3r5 BaseExceptionTupleTyperrrDr2r r[rar,rrrrrQes(  rQc @sveZdZdZdeejejeejefeeddddZ d ed d d Z dejejeejefejeejefd ddZ e j dejejeeejfejejeejefeejejejejejfdddZdd ejejeejefejejeeejfejejeejefeeejedddZe j dejejeejfejedddZdS)rRaThe CLI runner provides functionality to invoke a Click command line script for unittesting purposes in a isolated environment. This only works in single-threaded systems without any concurrency as it changes the global interpreter state. :param charset: the character set for the input and output data. :param env: a dictionary with environment variables for overriding. :param echo_stdin: if this is set to `True`, then reading from stdin writes to stdout. This is useful for showing examples in some circumstances. Note that regular prompts will automatically echo the input. :param mix_stderr: if this is set to `False`, then stdout and stderr are preserved as independent streams. This is useful for Unix-philosophy apps that have predictable stdout and noisy stderr, such that each may be measured independently utf-8NFT)rFenv echo_stdin mix_stderrr cCs ||_|p i|_||_||_dSr)rFrmrnro)rrFrmrnrorrrrs zCliRunner.__init__r)clir cCs |jpdS)zGiven a command object it will return the default program name for it. The default is the `name` attribute or ``"root"`` if not set. root)r<)rrprrrget_default_prog_nameszCliRunner.get_default_prog_name) overridesr cCst|j}|r|||S)z8Returns the environment overrides for invoking a script.)dictrmupdate)rrsrrrrmake_envs  zCliRunner.make_env)r rmcolorr c#sxt||j}d}tj}tj}tj}tj} dt_||}t } |j r^t t jt|| }}t||jdddt_|j rd_t| |jdddt_d} |jrtjt_nt } t| |jd dd d t_t|dt jttd fd d } t|dt jttd fdd } t|ttddd}|dt jt jt jttdfdd }tj}tj}tj}tj}| t_| t_|t_|t_i}zl|D]T\}}tj "|||<|dkrz tj |=Wnt!k rYnXn |tj |<q| | fVW5|D]D\}}|dkr4z tj |=Wnt!k r0YnXn |tj |<q|t_|t_|t_|t_|t_|t_|t_| t_XdS)anA context manager that sets up the isolation for invoking of a command line tool. This sets up stdin with the given input data and `os.environ` with the overrides from the given dictionary. This also rebinds some internals in Click to be mocked (like the prompt functionality). This is automatically done in the :meth:`invoke` method. :param input: the input stream to put into sys.stdin. :param env: the environment overrides as dictionary. :param color: whether the output should contain color codes. The application can still override this explicitly. .. versionchanged:: 8.0 ``stderr`` is opened with ``errors="backslashreplace"`` instead of the default ``"strict"``. .. versionchanged:: 4.0 Added the ``color`` parameter. NPzr)encodingr<r=rzwzbackslashreplace)rzr<r=errors)promptr cs>tj|p dd}tj|dtj|S)Nr]r^)sysr[rr rstripflush)r~val text_inputrr visible_inputs  z*CliRunner.isolation..visible_inputcs.tj|p ddtjdS)Nrr^r])rr[rrr r)r~rrr hidden_inputs z)CliRunner.isolation..hidden_input)echor cSs*tjd}|rtj|tj|S)Nr)rstdinrr[rr)rcharrrr_getchar#s    z%CliRunner.isolation.._getchar)r8rwr cs|dkr S| Srr)r8rw) default_colorrrshould_strip_ansi/sz.CliRunner.isolation..should_strip_ansi)N)N)NN)#rPrFrrr[rarZ FORCED_WIDTHrvrNrOrnr0rIr1r r: _CHUNK_SIZEror9rhr2boolrJrZvisible_prompt_funcZhidden_prompt_funcrrritemsosenviron Exceptionget)rr rmrwZ bytes_inputZ echo_inputZ old_stdinZ old_stdoutZ old_stderrZold_forced_widthZ bytes_outputZ bytes_errorrrrrZold_visible_prompt_funcZold_hidden_prompt_funcZold__getchar_funcZold_should_strip_ansiZold_envkeyvaluer)rrr isolations          zCliRunner.isolation)rpargsr rmcatch_exceptionsrwextrar c Ksd}|j|||dz} d} d} d} t|tr8t|}z|d} Wntk rd||} YnXzz|j f|pvd| d|} Wntk r}ztt}ttjtjttjf|j}|dkrd}|dkr|} t|tstj t|tj dd}|} W5d}~XYn<tk rT}z|s4|} d} t}W5d}~XYnXW5tj | d }|j r~d}n | d }XW5QRXt|||| | | |d S) aInvokes a command in an isolated environment. The arguments are forwarded directly to the command line script, the `extra` keyword arguments are passed to the :meth:`~clickpkg.Command.main` function of the command. This returns a :class:`Result` object. :param cli: the command to invoke :param args: the arguments to invoke. It may be given as an iterable or a string. When given as string it will be interpreted as a Unix shell command. More details at :func:`shlex.split`. :param input: the input data for `sys.stdin`. :param env: the environment overrides. :param catch_exceptions: Whether to catch any other exceptions than ``SystemExit``. :param extra: the keyword arguments to pass to :meth:`main`. :param color: whether the output should contain color codes. The application can still override this explicitly. .. versionchanged:: 8.0 The result object has the ``return_value`` attribute with the value returned from the invoked command. .. versionchanged:: 4.0 Added the ``color`` parameter. .. versionchanged:: 3.0 Added the ``catch_exceptions`` parameter. .. versionchanged:: 3.0 The result object has the ``exc_info`` attribute with the traceback if available. N)r rmrwr prog_namerr)rrr^rS)rrLr2shlexsplitpopKeyErrorrrrr[rgetvalueromain SystemExitrZr0rIrhUnionr5r3coderrrQ)rrprr rmrrwrrZZ outstreamsrWrYrXrr[raeZe_coderrrinvoke]sZ,       zCliRunner.invoke)temp_dirr ccsft}tj|d}t|z |VW5t||dkr`zt|Wntk r^YnXXdS)aA context manager that creates a temporary directory and changes the current working directory to it. This isolates tests that affect the contents of the CWD to prevent them from interfering with each other. :param temp_dir: Create the temporary directory under this directory. If given, the created directory is not removed when exiting. .. versionchanged:: 8.0 Added the ``temp_dir`` parameter. )dirN)rgetcwdtempfilemkdtempchdirshutilrmtreeOSError)rrcwdr0rrrisolated_filesystems    zCliRunner.isolated_filesystem)rlNFT)N)NNF)NNNTF)N)r-r.r/rgr2r0rhMappingrrrrrv contextlibcontextmanagerrr4rJr7rjrNrOrSequencer3rQrrPathLikerrrrrrRsd   erR)#rrNrrrrrtypingr0typesrrrrr_compatr TYPE_CHECKINGcorerr rrhr7r9 TextIOWrapperr:rr2r4rJr1rPrQrRrrrrs0      "  :