Viewing File: /opt/alt/python35/lib/python3.5/site-packages/click/__pycache__/testing.cpython-35.opt-1.pyc



e([V*@sddlZddlZddlZddlZddlZddlmZmZeje	j
dddZerddlm
Z
nddlZddlmZGdddeZd	d
ZGdddeZGd
ddeZdS)N)	iteritemsPY2.)StringIO)_find_binary_readerc@sveZdZddZddZddZddd	Zdd
dZdd
ZddZ	ddZ
dS)EchoingStdincCs||_||_dS)N)_input_output)selfinputoutputr/testing.py__init__s	zEchoingStdin.__init__cCst|j|S)N)getattrr	)rxrrr__getattr__szEchoingStdin.__getattr__cCs|jj||S)N)r
write)rrvrrr_echo!szEchoingStdin._echorcCs|j|jj|S)N)rr	read)rnrrrr%szEchoingStdin.readcCs|j|jj|S)N)rr	readline)rrrrrr(szEchoingStdin.readlinecs fddjjDS)Ncsg|]}j|qSr)r).0r)rrr
<listcomp>,s	z*EchoingStdin.readlines.<locals>.<listcomp>)r		readlines)rr)rrr+szEchoingStdin.readlinescs tfddjDS)Nc3s|]}j|VqdS)N)r)rr)rrr	<genexpr>/sz(EchoingStdin.__iter__.<locals>.<genexpr>)iterr	)rr)rr__iter__.szEchoingStdin.__iter__cCs
t|jS)N)reprr	)rrrr__repr__1szEchoingStdin.__repr__Nr")__name__
__module____qualname__rrrrrrrr!rrrrrsrcCst|drAtr|St|}|dk	r5|Std|dkrVd}nt|tst|j|}trt|Stj	|S)Nrz.Could not find binary reader for input stream.)
hasattrrr	TypeError
isinstancebytesencoderioBytesIO)rcharsetrrrrmake_input_stream5s	
r/c@sCeZdZdZdddZeddZddZdS)	Resultz3Holds the captured result of an invoked CLI script.NcCs1||_||_||_||_||_dS)N)runneroutput_bytes	exit_code	exceptionexc_info)rr1r2r3r4r5rrrrKs
				zResult.__init__cCs%|jj|jjdjddS)zThe output as unicode string.replacez

)r2decoder1r.r6)rrrrr
Xsz
Result.outputcCs#d|jrt|jpdfS)Nz<Result %s>Zokay)r4r )rrrrr!^szResult.__repr__)r#r$r%__doc__rpropertyr
r!rrrrr0Hsr0c@seZdZdZdddddZddZddd	Zejdddd
dZ	dddddd
dZ
ejddZdS)	CliRunneraIThe 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.  This is
                    UTF-8 by default and should not be changed currently as
                    the reporting to Click only works in Python 2 properly.
    :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.
    NFcCs7|dkrd}||_|p$i|_||_dS)Nzutf-8)r.env
echo_stdin)rr.r<r=rrrrts
	zCliRunner.__init__cCs
|jpdS)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)name)rclirrrget_default_prog_name{szCliRunner.get_default_prog_namecCs&t|j}|r"|j||S)z8Returns the environment overrides for invoking a script.)dictr<update)rZ	overridesrrrrmake_envs
zCliRunner.make_envc#st|jtj}tj}tj}tjj}dtj_|j	|}t
rtt_t_}|jrt
|n^tj}|jrt
|tjd|jtj|d|jt_t_t_dfdd}	dfdd}
dd	}|ddfd
d}tjj}
tjj}tjj}tjj}|	tj_|
tj_|tj_|tj_i}z{xot|D]a\}}tjj|||<|dkrytj|=Wqtk
r
YqXq|tj|<qW|VWdxYt|D]K\}}|dkrvytj|=Wqtk
rrYqXq8|tj|<q8W|t_|t_|t_|
tj_|tj_|tj_|tj_|tj_XdS)aA 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.

        .. versionadded:: 4.0
           The ``color`` parameter was added.

        :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.
        PencodingNcsPtjj|pdjjd}tjj|dtjj|S)Nz
r7)sysstdoutrrrstripflush)promptval)rrr
visible_inputs

z*CliRunner.isolation.<locals>.visible_inputcs:tjj|pddtjjjjdS)NrGr7z
)rHrIrrKrrJ)rL)rrrhidden_inputs
z)CliRunner.isolation.<locals>.hidden_inputcSs9tjjd}|r5tjj|tjj|S)Nr)rHstdinrrIrrK)Zechocharrrr_getchars

z%CliRunner.isolation.<locals>._getcharcs|dkrS|S)Nr)streamcolor)
default_colorrrshould_strip_ansisz.CliRunner.isolation.<locals>.should_strip_ansi)r/r.rHrPrIstderrclickpkgZ
formattingZFORCED_WIDTHrDrrr=rr,r-
TextIOWrapperZtermuiZvisible_prompt_funcZhidden_prompt_funcrRZutilsrVrosenvironget	Exception)rrr<rTZ	old_stdinZ
old_stdoutZ
old_stderrZold_forced_widthZbytes_outputrNrOrRrVZold_visible_prompt_funcZold_hidden_prompt_funcZold__getchar_funcZold_should_strip_ansiZold_envkeyvaluer)rUrr	isolationsr						
	
			zCliRunner.isolationTc&Ks~d}|jd|d|d|2}	d}
d}zy,|jd|pKfd|j||Wntk
r}zj|jdkr|}
tj}|j}t|tstj	j
t|tj	j
dd	}WYdd}~XnFtk
r3}z&|s	|}
d}tj}WYdd}~XnXWdtj	j
|	j}
XWdQRXtd
|d|
d|d
|
d|S)aeInvokes 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.

        .. versionadded:: 3.0
           The ``catch_exceptions`` parameter was added.

        .. versionchanged:: 3.0
           The result object now has an `exc_info` attribute with the
           traceback if available.

        .. versionadded:: 4.0
           The ``color`` parameter was added.

        :param cli: the command to invoke
        :param args: the arguments to invoke
        :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.
        Nrr<rTrargsZ	prog_namer7rr1r2r3r4r5r")r`mainrA
SystemExitcoderHr5r)intrIrstrr]rKgetvaluer0)rr@rarr<Zcatch_exceptionsrTextrar5outr4r3er
rrrinvokes:!	#
zCliRunner.invokeccsotj}tj}tj|z	|VWdtj|ytj|Wnttfk
riYnXXdS)zA context manager that creates a temporary folder and changes
        the current working directory to it for isolated filesystem tests.
        N)	rZgetcwdtempfilemkdtempchdirshutilrmtreeOSErrorIOError)rcwdtrrrisolated_filesystem3s
	
zCliRunner.isolated_filesystem)r#r$r%r9rrArD
contextlibcontextmanagerr`rkrvrrrrr;dsi	?r;)rZrHrprmrwZ_compatrrmodulesr#rsplitrX	cStringIOrr,robjectrr/r0r;rrrr<module>s
Back to Directory File Manager