Your IP : 52.15.92.58


Current Path : /opt/alt/python39/lib64/python3.9/__pycache__/
Upload File :
Current File : //opt/alt/python39/lib64/python3.9/__pycache__/doctest.cpython-39.opt-2.pyc

a

R�fx��@s2dZgd�ZddlZddlZddlZddlZddlZddlZddlZddl	Z	ddl
Z
ddlZddlm
Z
ddlmZedd�ZiZdd	�Zed
�Zed�Zed�Zed
�Zed�Zed�ZeeBeBeBeBeBZed�Zed�Zed�Zed�Zed�ZeeBeBeBeBZdZ dZ!dd�Z"dqdd�Z#dd�Z$dd�Z%drd!d"�Z&d#d$�Z'Gd%d&�d&e
�Z(d'd(�Z)d)d*�Z*d+d,�Z+Gd-d.�d.ej,�Z-d/d0�Z.Gd1d2�d2�Z/Gd3d4�d4�Z0Gd5d6�d6�Z1Gd7d8�d8�Z2Gd9d:�d:�Z3Gd;d<�d<�Z4Gd=d>�d>e5�Z6Gd?d@�d@e5�Z7GdAdB�dBe3�Z8da9dsdEdF�Z:dCdddddCdddDe1�dfdGdH�Z;dtdJdK�Z<da=dLdM�Z>GdNdO�dOej?�Z@GdPdQ�dQe@�ZAGdRdS�dSejB�ZCdudTdU�ZDGdVdW�dWe@�ZEdCdde1�dfdXdY�ZFdZd[�ZGd\d]�ZHd^d_�ZIdvd`da�ZJdwdbdc�ZKdxddde�ZLGdfdg�dg�ZMeMdhdidjdkdldm�ZNdndo�ZOePdpk�r.e	�QeO��dS)yzreStructuredText en)!�register_optionflag�DONT_ACCEPT_TRUE_FOR_1�DONT_ACCEPT_BLANKLINE�NORMALIZE_WHITESPACE�ELLIPSIS�SKIP�IGNORE_EXCEPTION_DETAIL�COMPARISON_FLAGS�REPORT_UDIFF�REPORT_CDIFF�REPORT_NDIFF�REPORT_ONLY_FIRST_FAILURE�REPORTING_FLAGS�	FAIL_FAST�Example�DocTest�
DocTestParser�
DocTestFinder�
DocTestRunner�
OutputChecker�DocTestFailure�UnexpectedException�DebugRunner�testmod�testfile�run_docstring_examples�DocTestSuite�DocFileSuite�set_unittest_reportflags�script_from_examples�
testsource�	debug_src�debug�N)�StringIO)�
namedtuple�TestResultszfailed attemptedcCst�|dtt�>�S)N�)�OPTIONFLAGS_BY_NAME�
setdefault�len��name�r,�,/opt/alt/python39/lib64/python3.9/doctest.pyr�srrrrrrrr	r
rrrz<BLANKLINE>z...cCs8d}tjD](}|�|d�}|tt|�ur
||jO}q
|S)Nr")�
__future__Zall_feature_names�get�getattrZ
compiler_flag)�globs�flagsZfnameZfeaturer,r,r-�_extract_future_flags�s
r3�cCsVt�|�r|St|t�r,t|t�t�dg�S|durJtjt�	|�j
dStd��dS)N�*�__name__z"Expected a module, string, or None)�inspect�ismodule�
isinstance�str�
__import__�globals�locals�sys�modules�	_getframe�	f_globals�	TypeError)�moduleZdepthr,r,r-�_normalize_module�s


rDcCsdD]}|�|d�}q|S)N)z
�
�
)�replace)�data�newliner,r,r-�_newline_convert�srJcCs�|rVt|d�}t||�}t|dd�durVt|jd�rV|j�|�}|�|�}t|�|fSt||d��}|�	�|fWd�S1s�0YdS)N��
__loader__�get_data)�encoding)
rD�_module_relative_pathr0�hasattrrLrM�decoderJ�open�read)�filename�package�module_relativerNZ
file_contents�fr,r,r-�_load_testfile�s


rX�cCst�d|d|�S)Nz
(?m)^(?!$)� )�re�sub)�s�indentr,r,r-�_indent�sr_cCs*t�}|\}}}tj||||d�|��S)N)�file)r#�	traceback�print_exception�getvalue)�exc_infoZexcout�exc_typeZexc_valZexc_tbr,r,r-�_exception_traceback�s
rfc@seZdZdd�Zddd�ZdS)�	_SpoofOutcCs$t�|�}|r |�d�s |d7}|S�NrF)r#rc�endswith)�self�resultr,r,r-rcs
z_SpoofOut.getvalueNcCs|�|�t�|�dS�N)�seekr#�truncate)rj�sizer,r,r-rn	s
z_SpoofOut.truncate)N)r6�
__module__�__qualname__rcrnr,r,r,r-rg�s	rgcCs�t|vr||kS|�t�}dt|�}}|d}|rR|�|�rNt|�}|d=ndS|d}|r�|�|�r||t|�8}|d=ndS||kr�dS|D],}|�|||�}|dkr�dS|t|�7}q�dS)Nr"F���T)�ELLIPSIS_MARKER�splitr)�
startswithri�find)�want�gotZws�startpos�endpos�wr,r,r-�_ellipsis_matchs0


r|cCs|��}|rd|SdSdS)Nz# �#)�rstrip)�liner,r,r-�
_comment_line?sr�cCshdt|�}}|�d�}|dkr$|}|�dd|�}|dkr>|}|�dd|�}|dkr\|d}|||�S)Nr"rF�:�.r&)r)rv�rfind)�msg�start�end�ir,r,r-�_strip_exception_detailsGs
r�c@s.eZdZdd�Zd
dd�Zdd�Zdd	�ZdS)�_OutputRedirectingPdbcCs(||_d|_tjj||dd�d|_dS)NFT)�stdout�nosigintr&)�_OutputRedirectingPdb__out�$_OutputRedirectingPdb__debugger_used�pdb�Pdb�__init__Zuse_rawinput)rj�outr,r,r-r�gsz_OutputRedirectingPdb.__init__NcCs*d|_|durt��j}tj�||�dS)NT)r�r>r@�f_backr�r��	set_trace)rj�framer,r,r-r�os
z_OutputRedirectingPdb.set_tracecCs|jrtj�|�dSrl)r�r�r��set_continue�rjr,r,r-r�usz"_OutputRedirectingPdb.set_continuecGs8tj}|jt_ztjj|g|�R�W|t_S|t_0dSrl)r>r�r�r�r��trace_dispatch)rj�args�save_stdoutr,r,r-r�{s�z$_OutputRedirectingPdb.trace_dispatch)N)r6rprqr�r�r�r�r,r,r,r-r�as
r�cCs�t�|�std|��|�d�r(td��tjj|�d��}t	|d�rXtj�|j
�d}n�|jdkr�tt
j�dkr�t
jddkr�tj�t
jd�d}q�tj}nFt	|d�r�|jD]&}tj�||�}tj�|�r�|Sq�td	|j��tj�||�S)
NzExpected a module: %r�/z1Module-relative files may not have absolute paths�__file__r"�__main__��__path__zBCan't resolve paths relative to the module %r (it has no __file__))r7r8rBru�
ValueError�os�path�joinrtrPr�r6r)r>�argv�curdirr��exists)rCZ	test_pathZbasedirZ	directory�fullpathr,r,r-rO�s(






�rOc@s&eZdZd	dd�Zdd�Zdd�ZdS)
rNr"cCsv|�d�s|d7}|r(|�d�s(|d7}|durB|�d�sB|d7}||_||_||_||_|durfi}||_||_dSrh)ri�sourcerw�linenor^�options�exc_msg)rjr�rwr�r�r^r�r,r,r-r��s
zExample.__init__cCs\t|�t|�urtS|j|jkoZ|j|jkoZ|j|jkoZ|j|jkoZ|j|jkoZ|j|jkSrl)�type�NotImplementedr�rwr�r^r�r��rj�otherr,r,r-�__eq__�s
�
�
�
�
�zExample.__eq__cCst|j|j|j|j|jf�Srl)�hashr�rwr�r^r�r�r,r,r-�__hash__�s�zExample.__hash__)Nr"r"N)r6rprqr�r�r�r,r,r,r-r�s
#�
rc@s4eZdZdd�Zdd�Zdd�Zdd�Zd	d
�ZdS)rcCs,||_||_|��|_||_||_||_dSrl)�examples�	docstring�copyr1r+rTr�)rjr�r1r+rTr�r�r,r,r-r�s
zDocTest.__init__cCsRt|j�dkrd}n"t|j�dkr(d}ndt|j�}d|jj|j|j|j|fS)Nr"zno examplesr&z	1 examplez%d examplesz<%s %s from %s:%s (%s)>)r)r��	__class__r6r+rTr�)rjr�r,r,r-�__repr__s��zDocTest.__repr__cCs\t|�t|�urtS|j|jkoZ|j|jkoZ|j|jkoZ|j|jkoZ|j|jkoZ|j|jkSrl)r�r�r�r�r1r+rTr�r�r,r,r-r�)s
�
�
�
�
�zDocTest.__eq__cCst|j|j|j|jf�Srl)r�r�r+rTr�r�r,r,r-r�4szDocTest.__hash__cCs:t|t�stS|j|j|jt|�f|j|j|jt|�fkSrl)r9rr�r+rTr��idr�r,r,r-�__lt__8s

�zDocTest.__lt__N)r6rprqr�r�r�r�r�r,r,r,r-r�s
rc@s�eZdZe�dejejB�Ze�dejejBejB�Z	e�d�j
Zddd�Zdd�Z
dd	d
�Zdd�Ze�d
ej�Zdd�Ze�dej�Zdd�Zdd�Zdd�ZdS)ra�
        # Source consists of a PS1 line followed by zero or more PS2 lines.
        (?P<source>
            (?:^(?P<indent> [ ]*) >>>    .*)    # PS1 line
            (?:\n           [ ]*  \.\.\. .*)*)  # PS2 lines
        \n?
        # Want consists of any non-blank lines that do not start with PS1.
        (?P<want> (?:(?![ ]*$)    # Not a blank line
                     (?![ ]*>>>)  # Not a line starting with PS1
                     .+$\n?       # But any other line
                  )*)
        a�
        # Grab the traceback header.  Different versions of Python have
        # said different things on the first traceback line.
        ^(?P<hdr> Traceback\ \(
            (?: most\ recent\ call\ last
            |   innermost\ last
            ) \) :
        )
        \s* $                # toss trailing whitespace on the header.
        (?P<stack> .*?)      # don't blink: absorb stuff until...
        ^ (?P<msg> \w+ .*)   #     a line *starts* with alphanum.
        z^[ ]*(#.*)?$�<string>c
s|��}|�|���dkr8d��fdd�|�d�D��}g}d\}}|j�|�D]�}|�|||����||�d||���7}|�	|||�\}}}	}
|�
|�s�|�t||	|
|�t|�
d��|d��||�d|��|���7}|��}qP|�||d��|S)Nr"rFcsg|]}|�d��qSrlr,��.0�l�Z
min_indentr,r-�
<listcomp>�z'DocTestParser.parse.<locals>.<listcomp>�r"r"r^)r�r^r�)�
expandtabs�_min_indentr�rt�_EXAMPLE_RE�finditer�appendr��count�_parse_example�_IS_BLANK_OR_COMMENTrr)�groupr�)rj�stringr+�outputZcharnor��mr�r�rwr�r,r�r-�parsess*
�

�
zDocTestParser.parsecCst|�||�|||||�Srl)r�get_examples)rjr�r1r+rTr�r,r,r-�get_doctest�s	�zDocTestParser.get_doctestcCsdd�|�||�D�S)NcSsg|]}t|t�r|�qSr,)r9r)r��xr,r,r-r��s
�z.DocTestParser.get_examples.<locals>.<listcomp>)r�)rjr�r+r,r,r-r��szDocTestParser.get_examplesc
s
t|�d���|�d��d�}|�|�||�|�|dd�d�d||�d��fdd�|D��}|�d	�}|�d�}t|�dkr�t�d
|d�r�|d=|�|d�||t|��d��fdd�|D��}|j�|�}|r�|�d
�}nd}|�	|||�}	||	||fS)Nr^r�rFr&rZr�csg|]}|�dd��qS)rYNr,)r�Zsl�r^r,r-r��r�z0DocTestParser._parse_example.<locals>.<listcomp>rwz *$rrcsg|]}|�d��qSrlr,)r�Zwlr�r,r-r��r�r�)
r)r�rt�_check_prompt_blank�
_check_prefixr�r[�match�
_EXCEPTION_RE�
_find_options)
rjr�r+r��source_linesr�rw�
want_linesr�r�r,r�r-r��s& 


�zDocTestParser._parse_examplez#\s*doctest:\s*([^\n\'"]*)$c	Cs�i}|j�|�D]v}|�d��dd���}|D]V}|ddvsN|dd�tvrdtd|d||f��t|dd�}|ddk||<q.q|r�|�|�r�td|||f��|S)	Nr&�,rZr"z+-z7line %r of the doctest for %s has an invalid option: %r�+zSline %r of the doctest for %s has an option directive on a line with no example: %r)�_OPTION_DIRECTIVE_REr�r�rGrtr'r�r�)	rjr�r+r�r�r�Zoption_strings�option�flagr,r,r-r��s"���zDocTestParser._find_optionsz
^([ ]*)(?=\S)cCs2dd�|j�|�D�}t|�dkr*t|�SdSdS)NcSsg|]}t|��qSr,)r))r�r^r,r,r-r�
r�z-DocTestParser._min_indent.<locals>.<listcomp>r")�
_INDENT_RE�findallr)�min)rjr]�indentsr,r,r-r�szDocTestParser._min_indentc	Cs^t|�D]P\}}t|�|dkr||ddkrtd||d||||d�|f��qdS)NrYrKrZz8line %r of the docstring for %s lacks blank after %s: %rr&)�	enumerater)r�)rj�linesr^r+r�r�rr,r,r-r�s ��z!DocTestParser._check_prompt_blankcCs>t|�D]0\}}|r|�|�std||d||f��qdS)NzGline %r of the docstring for %s has inconsistent leading whitespace: %rr&)r�rur�)rjr��prefixr+r�r�rr,r,r-r�s
�zDocTestParser._check_prefixN)r�)r�)r6rprqr[�compile�	MULTILINE�VERBOSEr��DOTALLr�r�r�r�r�r�r�r�r�r�r�r�r�r,r,r,r-rCs&	
��
'
3�rc@sJeZdZde�ddfdd�Zddd�Zdd	�Zd
d�Zdd
�Zdd�Z	dS)rFTcCs||_||_||_||_dSrl)�_parser�_verbose�_recurse�_exclude_empty)rj�verbose�parser�recurse�
exclude_emptyr,r,r-r�7szDocTestFinder.__init__Nc		CsL|dur.t|dd�}|dur.tdt|�f��|dur<d}n|durNt�|�}zt�|�}Wntyrd}Ynd0|s�t�|�}|d|dd�dks�d}|dur�d}n*|dur�t�	||j
�}n
t�	|�}|s�d}|dur�|dur�i}n
|j
��}n|��}|du�r|�|�d|v�r&d|d<g}|�
||||||i�|��|S)Nr6zJDocTestFinder.find: name must be given when obj.__name__ doesn't exist: %rFr"���z<]>r�)r0r�r�r7�	getmoduleZ
getsourcefilerBZgetfile�	linecache�getlines�__dict__r��update�_find�sort)	rj�objr+rCr1�
extraglobsr`r��testsr,r,r-rvMsJ$�






zDocTestFinder.findcCs�|durdSt�|�dur(|t�|�uSt�|�r>|j|juSt�|�r|t|d�r\|jj}nt|d�rn|j}ndS|j	|kSt�
|�r�|j	|jkSt|d�r�|j	|jkSt|t�r�dSt
d��dS)NT�__objclass__rpz"object must be a class or function)r7r��
isfunctionr��__globals__ZismethoddescriptorrPr�rpr6�isclassr9�propertyr�)rjrC�objectZobj_modr,r,r-�_from_module�s(








zDocTestFinder._from_modulec
Cs|jrtd|�t|�|vr"dSd|t|�<|�|||||�}|durR|�|�t�|�r�|jr�|j�	�D]P\}	}
d||	f}	t�
t�|
��s�t�|
�rl|�
||
�rl|�||
|	||||�qlt�|��rn|j�rnt|di��	�D]�\}	}
t|	t��stdt|	�f��t�
|
��sJt�|
��sJt�|
��sJt|
t��sJtdt|
�f��d||	f}	|�||
|	||||�q�t�|��r|j�r|j�	�D]t\}	}
t|
ttf��r�|
j}
t�
|
��s�t�|
��s�t|
t��r�|�
||
��r�d||	f}	|�||
|	||||��q�dS)NzFinding tests in %sr&z%s.%s�__test__z5DocTestFinder.find: __test__ keys must be strings: %rz`DocTestFinder.find: __test__ values must be strings, functions, methods, classes, or modules: %rz%s.__test__.%s)r��printr��	_get_testr�r7r8r�r��itemsZ	isroutineZunwrapr�rr�r0r9r:r�r��staticmethod�classmethod�__func__r)rjr�r�r+rCr�r1�seen�testZvalname�valr,r,r-r��sd
�
��������
��zDocTestFinder._findc		Cs�t|t�r|}nHz,|jdur"d}n|j}t|t�s:t|�}WnttfyVd}Yn0|�||�}|jrr|srdS|dur�d}n.t|dd�p�|j}|dd�dkr�|dd�}|j	�
|||||�S)Nr�r�����.pycrr)r9r:�__doc__rB�AttributeError�_find_linenor�r0r6r�r�)	rjr�r+rCr1r�r�r�rTr,r,r-rs*




�zDocTestFinder._get_testcCsd}t�|�rd}t�|�rb|dur(dSt�dt|dd��}t|�D]\}}|�|�rF|}qbqFt�|�rr|j	}t�
|�r�|j}t�|�r�|j
}t�|�r�|j}t�|�r�t|dd�d}|du�r
|dur�|dSt�d�}t|t|��D]}|�||�r�|Sq�dS)Nr"z^\s*class\s*%s\br6�-�co_firstlinenor&z(^|.*:)\s*\w*("|\'))r7r8r�r[r�r0r�r�Zismethodr	r��__code__Zistraceback�tb_frameZisframe�f_codeZiscode�ranger))rjr�r�r�Zpatr�rr,r,r-r2s6


�




zDocTestFinder._find_lineno)NNNN)
r6rprqrr�rvrr�rrr,r,r,r-r.s	�

f=&rc@s�eZdZdZddd�Zdd�Zdd	�Zd
d�Zdd
�Zdd�Z	dd�Z
dd�Ze�
d�Zddd�Zd dd�Zd!dd�Zdd�ZdS)"rzF**********************************************************************Nr"cCsN|pt�|_|durdtjv}||_||_||_d|_d|_i|_	t
�|_dS)N�-vr")r�_checkerr>r�r��optionflags�original_optionflags�tries�failures�_name2ftrg�_fakeout)rj�checkerr�rr,r,r-r��s
zDocTestRunner.__init__cCsH|jrD|jr.|dt|j�dt|j��n|dt|j�d�dS)NzTrying:
zExpecting:
zExpecting nothing
)r�rwr_r�)rjr�r�exampler,r,r-�report_start�s���zDocTestRunner.report_startcCs|jr|d�dS)Nzok
)r��rjr�rr!rxr,r,r-�report_success�szDocTestRunner.report_successcCs&||�||�|j�|||j��dSrl)�_failure_headerr�output_differencerr#r,r,r-�report_failure�s�zDocTestRunner.report_failurecCs$||�||�dtt|���dS)NzException raised:
)r%r_rf�rjr�rr!rdr,r,r-�report_unexpected_exception�s
�
�z)DocTestRunner.report_unexpected_exceptioncCs�|jg}|jrR|jdur4|jdur4|j|jd}nd}|�d|j||jf�n|�d|jd|jf�|�d�|j}|�t|��d�|�S)Nr&�?zFile "%s", line %s, in %szLine %s, in %szFailed example:rF)�DIVIDERrTr�r�r+r�r_r�)rjrr!r�r�r�r,r,r-r%�s�
zDocTestRunner._failure_headerc	Cs�d}}|j}td�\}}}	|jj}
t|j�D�]4\}}|jt@oH|dk}
||_|jr�|j��D],\}}|r||j|O_q`|j|M_q`|jt	@r�q.|d7}|
s�|�
|||�d|j|f}z,tt
|j|d|d�|j�|j��d}Wn2t�y�Ynt��}|j��Yn0|j��}|j�d�|}|du�r^|
|j||j��r�|}n|tj|dd��d}|
�s�|t|�7}|jdu�r�|	}nB|
|j||j��r�|}n*|jt@�r�|
t|j�t|�|j��r�|}||u�r�|
�sP|�||||�nT||u�r&|
�s|� ||||�|d7}n*||	u�rP|
�sF|�!||||�|d7}n|r.|jt"@r.�qfq.||_|�#|||�t$||�S)	Nr"rKr&z<doctest %s[%d]>ZsingleTr4rr)%rrr�check_outputr�r�rr�rrr"r+�execr�r�r1�debuggerr��KeyboardInterruptr>rdrrcrnrwra�format_exception_onlyrfr�rr�r$r'r)r�_DocTestRunner__record_outcomer%)rjr�compileflagsr�rrr�SUCCESS�FAILUREZBOOMZcheck�
examplenumr!�quietZ
optionflagrrTZ	exceptionrxZoutcomer�r,r,r-Z__run�s�
�
��



�




�
zDocTestRunner.__runcCsL|j�|jd�\}}||||f|j|j<|j|7_|j|7_dS)Nr�)rr/r+rr)rjrrW�t�f2�t2r,r,r-Z__record_outcomezszDocTestRunner.__record_outcomez.<doctest (?P<name>.+)\[(?P<examplenum>\d+)\]>$cCsV|j�|�}|rF|�d�|jjkrF|jjt|�d��}|jjdd�S|�	||�SdS)Nr+r5T��keepends)
�%_DocTestRunner__LINECACHE_FILENAME_REr�r�rr+r��intr��
splitlines�save_linecache_getlines)rjrT�module_globalsr�r!r,r,r-Z__patched_linecache_getlines�s
z*DocTestRunner.__patched_linecache_getlinesTc		sD||_|durt|j�}tj�|durV�j��dus@���dkrH�j}n��fdd�}|jt_t�	�}t
j}t��|_
|j
��|j
jt
_tj|_|jt_tj}tjt_zR|�|||�W�t_|t
_t�|�|jt_|t_|r�|j��ddl}d|_SnD�t_|t
_t�|�|jt_|t_|�r>|j��ddl}d|_0dS)N�utf-8cs t|��d���}��|�dS)N�backslashreplace)r:�encode�write)r]�rNr�r,r-r��szDocTestRunner.run.<locals>.outr")rr3r1r>r�rN�lowerrDr�gettracer�r�r�r.�resetr�r�r?�*_DocTestRunner__patched_linecache_getlines�displayhook�__displayhook__�_DocTestRunner__run�settrace�clear�builtins�_)	rjrr2r��clear_globsZ
save_traceZsave_set_traceZsave_displayhookrOr,rEr-�run�sb





��

zDocTestRunner.runc
Cs�|dur|j}g}g}g}d}}|j��D]V}|\}\}	}
||
7}||	7}|
dkr`|�|�q,|	dkrx|�||
f�q,|�|�q,|r�|r�tt|�d�|��|D]}td|�q�|r�tt|�d�|��|D]\}}td||f�q�|�r:t|j�tt|�d�|��|D] \}\}	}
td|	|
|f��q|�rft|dt|j�d	�t||d
|d�|�rztd|d
�n|�r�td�t||�S)Nr"zitems had no tests:z   zitems passed all tests:z %3d tests in %szitems had failures:z %3d of %3d in %sztests inzitems.z
passed andzfailed.z***Test Failed***z	failures.zTest passed.)	r�rrr�rr)r�r+r%)
rjr�ZnotestsZpassedZfailedZtotaltZtotalfr�r+rWr7�thingr�r,r,r-�	summarize�sP
zDocTestRunner.summarizecCsR|j}|j��D]<\}\}}||vr@||\}}||}||}||f||<qdSrl)rr)rjr��dr+rWr7r8r9r,r,r-�mergeszDocTestRunner.merge)NNr")N)NNT)N)r6rprqr+r�r"r$r'r)r%rLr1r[r�r<rIrRrTrVr,r,r,r-rfs:
$
}



I
9rc@s,eZdZdd�Zdd�Zdd�Zdd�Zd	S)
rcCst|�dd�d�S)N�ASCIIrB)r:rC)rjr]r,r,r-�_toAscii&szOutputChecker._toAsciicCs�|�|�}|�|�}||kr dS|t@sH||fdkr8dS||fdkrHdS|t@s�t�dt�t�d|�}t�dd|�}||kr�dS|t@r�d�|�	��}d�|�	��}||kr�dS|t
@r�t||�r�dSdS)	NT)zTrue
z1
)zFalse
z0
z(?m)^%s\s*?$r�z(?m)^[^\S\n]+$rZF)rXrrr[r\�escape�BLANKLINE_MARKERrr�rtrr|�rjrwrxrr,r,r-r,,s2

�
zOutputChecker.check_outputcCs<|ttBtB@sdS|t@r dS|�d�dko:|�d�dkS)NFTrFr4)r	r
rr�r[r,r,r-�_do_a_fancy_diffks��zOutputChecker._do_a_fancy_diffc
Cs(|j}|t@st�dt|�}|�|||�r�|jdd�}|jdd�}|t@rptj	||dd�}t
|�dd�}d}nZ|t@r�tj||dd�}t
|�dd�}d}n,|t
@r�tjtjd�}	t
|	�||��}d	}nd
|td�|��S|r�|r�dt|�t|�fS|�rd
t|�S|�r dt|�SdSdS)Nz(?m)^[ ]*(?=
)Tr:r4)�nz#unified diff with -expected +actualz-context diff with expected followed by actual)Zcharjunkzndiff with -expected +actualzDifferences (%s):
r�zExpected:
%sGot:
%szExpected:
%sGot nothing
zExpected nothing
Got:
%szExpected nothing
Got nothing
)rwrr[r\rZr\r>r	�difflibZunified_diff�listr
Zcontext_diffrZDifferZIS_CHARACTER_JUNKZcomparer_r�)
rjr!rxrrwr�Z	got_linesZdiff�kindZenginer,r,r-r&�s4zOutputChecker.output_differenceN)r6rprqrXr,r\r&r,r,r,r-rs?rc@seZdZdd�Zdd�ZdS)rcCs||_||_||_dSrl)rr!rx)rjrr!rxr,r,r-r��szDocTestFailure.__init__cCs
t|j�Srl�r:rr�r,r,r-�__str__�szDocTestFailure.__str__N�r6rprqr�rbr,r,r,r-r�src@seZdZdd�Zdd�ZdS)rcCs||_||_||_dSrl)rr!rd)rjrr!rdr,r,r-r��szUnexpectedException.__init__cCs
t|j�Srlrar�r,r,r-rb�szUnexpectedException.__str__Nrcr,r,r,r-r�src@s&eZdZd	dd�Zdd�Zdd�ZdS)
rNTcCs$t�||||d�}|r |j��|S)NF)rrRr1rN)rjrr2r�rQ�rr,r,r-rR1s
zDebugRunner.runcCst|||��dSrl)rr(r,r,r-r)7sz'DebugRunner.report_unexpected_exceptioncCst|||��dSrl)rr#r,r,r-r':szDebugRunner.report_failure)NNT)r6rprqrRr)r'r,r,r,r-r�s[
rTFc	Cs�|durtj�d�}t�|�s,td|f��|dur:|j}t|d�}	|rVt||d�}
nt	||d�}
|	j
||||d�D]}|
�|�qt|r�|
��t
dur�|
a
n
t
�|
�t|
j|
j�S)Nr�ztestmod: module required; %r)r��r�r�r1r�)r>r?r/r7r8rBr6rrrrvrRrT�masterrVr%rr)r�r+r1r��reportrr��raise_on_errorr��finder�runnerrr,r,r-rFs$E


rcCs�|r|std��t||||pd�\}}|dur:tj�|�}|durHi}n|��}|durb|�|�d|vrrd|d<|	r�t||d�}
nt||d�}
|
�	||||d�}|
�
|�|r�|
��tdur�|
an
t�
|
�t|
j|
j�S)N�8Package may only be specified for module-relative paths.rAr6r�rer")r�rXr�r��basenamer�r�rrr�rRrTrgrVr%rr)rTrVr+rUr1r�rhrr�rir�rN�textrkrr,r,r-r�s2R�


r�NoNamec	Cs@t|dd�}t||d�}|j|||d�D]}|j||d�q(dS)NF)r�r�re)r1)r2)rrrvrR)	rWr1r�r+r2rrjrkrr,r,r-r)srcCs"|t@|krtd|��t}|a|S)NzOnly reporting flags allowed)r
r��_unittest_reportflags)r2�oldr,r,r-rFs

rc@sleZdZddd�Zdd�Zdd�Zd	d
�Zdd�Zd
d�Zdd�Z	dd�Z
dd�Zdd�Ze
jZdd�ZdS)�DocTestCaser"NcCs:tj�|�||_||_|j��|_||_||_	||_
dSrl)�unittest�TestCaser��_dt_optionflags�_dt_checkerr1r��	_dt_globs�_dt_test�	_dt_setUp�_dt_tearDown)rjrr�setUp�tearDownr r,r,r-r�lszDocTestCase.__init__cCs|j}|jdur|�|�dSrl)rxry�rjrr,r,r-r{ws
zDocTestCase.setUpcCs6|j}|jdur|�|�|j��|j�|j�dSrl)rxrzr1rNr�rwr}r,r,r-r|}s



zDocTestCase.tearDowncCs�|j}tj}t�}|j}|t@s(|tO}t||jdd�}z&d|_	|j
||jdd�\}}W|t_n|t_0|r�|�|�
|�����dS)NF�rr r�zF----------------------------------------------------------------------)r�rQ)rxr>r�r#rur
rprrvr+rRrDZfailureException�format_failurerc)rjrrq�newrrkrrr,r,r-�runTest�s"��zDocTestCase.runTestcCsP|j}|jdurd}n
d|j}d�|j�d�dd��}d|j|j|||fS)Nzunknown line numberz%sr�rrz:Failed doctest test for %s
  File "%s", line %s, in %s

%s)rxr�r�r+rtrT)rj�errrr�Zlnamer,r,r-r�s

�zDocTestCase.format_failurecCs6|��t|j|jdd�}|j|jdd�|��dS)NFr~)rQ)r{rrurvrRrxr|)rjrkr,r,r-r!�sB�zDocTestCase.debugcCs|jjSrl�rxr+r�r,r,r-r��szDocTestCase.idcCsPt|�t|�urtS|j|jkoN|j|jkoN|j|jkoN|j|jkoN|j|jkSrl)r�r�rxruryrzrvr�r,r,r-r��s
�
�
�
�zDocTestCase.__eq__cCst|j|j|j|jf�Srl)r�ruryrzrvr�r,r,r-r�	s�zDocTestCase.__hash__cCs,|jj�d�}d|dd�|dd��fS)Nr�z%s (%s)rr)rxr+rtr�)rjr+r,r,r-r�	szDocTestCase.__repr__cCsd|jjS)Nz	Doctest: r�r�r,r,r-�shortDescription
	szDocTestCase.shortDescription)r"NNN)r6rprqr�r{r|r�rr!r�r�r�r�rrbr�r,r,r,r-rrjs�

H
rrc@s0eZdZdd�Zdd�Zdd�Zdd�ZeZd	S)
�SkipDocTestCasecCs||_t�|d�dSrl)rCrrr�)rjrCr,r,r-r�	szSkipDocTestCase.__init__cCs|�d�dS)Nz-DocTestSuite will not work with -O2 and above)ZskipTestr�r,r,r-r{	szSkipDocTestCase.setUpcCsdSrlr,r�r,r,r-�	test_skip	szSkipDocTestCase.test_skipcCsd|jjS)NzSkipping tests from %s)rCr6r�r,r,r-r�	sz SkipDocTestCase.shortDescriptionN)r6rprqr�r{r�r�rbr,r,r,r-r�
	s
r�c@seZdZdd�ZdS)�
_DocTestSuitecCsdSrlr,)rj�indexr,r,r-�_removeTestAtIndex 	sz _DocTestSuite._removeTestAtIndexN)r6rprqr�r,r,r,r-r�	sr�c	Ks�|durt�}t|�}|j|||d�}|sNtjjdkrNt�}|�t|��|S|�	�t�}|D]X}t
|j�dkrtq`|js�|j
}|dd�dkr�|dd�}||_|�t|fi|���q`|S)Nrfr4r"r
rrr)rrDrvr>r2�optimizer��addTestr�r�r)r�rTr�rr)	rCr1r�Ztest_finderr�r��suiterrTr,r,r-r$	s(%rc@s$eZdZdd�Zdd�Zdd�ZdS)�DocFileCasecCsd�|jj�d��S)NrPr�)r�rxr+rtr�r,r,r-r�f	szDocFileCase.idcCs|jjSrl)rxrTr�r,r,r-r�i	szDocFileCase.__repr__cCsd|jj|jj|fS)Nz2Failed doctest test for %s
  File "%s", line 0

%s)rxr+rT)rjr�r,r,r-rl	s�zDocFileCase.format_failureN)r6rprqr�r�rr,r,r,r-r�d	sr�c
Ksz|duri}n|��}|r&|s&td��t||||p4d�\}}d|vrL||d<tj�|�}|�||||d�}	t|	fi|��S)NrlrAr�r")r�r�rXr�r�rmr�r�)
r�rVrUr1r�rNr��docr+rr,r,r-�DocFileTestq	s�r�cOsHt�}|�dd�r$t|�d��|d<|D]}|�t|fi|���q(|S)NrVTrU)r�r/rDr�r�)�paths�kwr�r�r,r,r-r�	s8rcCs�g}t��|�D]x}t|t�rh|�|jdd��|j}|r�|�d�|dd�|�d�dd�D�7}q|dd�|�d�dd�D�7}q|r�|ddkr�|��q�|r�|ddkr�|�d�q�d�	|�dS)	Nrrz# Expected:cSsg|]}d|�qS)z## r,r�r,r,r-r�
r�z(script_from_examples.<locals>.<listcomp>rFcSsg|]}t|��qSr,)r�r�r,r,r-r�
s�r}r")
rr�r9rr�r�rwrt�popr�)r]r�Zpiecerwr,r,r-r�	s :

"�

rcsJt|�}t��|�}�fdd�|D�}|s4t�d��|d}t|j�}|S)Ncsg|]}|j�kr|�qSr,r*)r�r7r*r,r-r�/
r�ztestsource.<locals>.<listcomp>znot found in testsr")rDrrvr�rr�)rCr+r�r�testsrcr,r*r-r&
s

rcCst|�}t|||�dSrl)r�debug_script)�src�pmr1r�r,r,r-r 6
sr cCs�ddl}|r|��}ni}|rvzt|||�Wq�tt��d�|jdd�}|��|�dt��d�Yq�0n|jdd��	d|||�dS)Nr"r&T)r�r4zexec(%r))
r�r�r-rr>rdr�rHZinteractionrR)r�r�r1r��pr,r,r-r�;
s
r�cCs$t|�}t||�}t|||j�dSrl)rDrr�r�)rCr+r�r�r,r,r-r!O
s
r!c@s$eZdZdd�Zdd�Zdd�ZdS)�
_TestClasscCs
||_dSrl�r)rjrr,r,r-r�k
sz_TestClass.__init__cCs|jd|_|S)Nr4r�r�r,r,r-�squareu
sz_TestClass.squarecCs|jSrlr�r�r,r,r-r/
sz_TestClass.getN)r6rprqr�r�r/r,r,r,r-r�]
s

r�z�
                      Example of a string object, searched as-is.
                      >>> x = 1; y = 2
                      >>> x + y, x * y
                      (3, 2)
                      a�
                                    In 2.2, boolean expressions displayed
                                    0 or 1.  By default, we still accept
                                    them.  This can be disabled by passing
                                    DONT_ACCEPT_TRUE_FOR_1 to the new
                                    optionflags argument.
                                    >>> 4 == 4
                                    1
                                    >>> 4 == 4
                                    True
                                    >>> 4 > 4
                                    0
                                    >>> 4 > 4
                                    False
                                    z�
                Blank lines can be marked with <BLANKLINE>:
                    >>> print('foo\n\nbar\n')
                    foo
                    <BLANKLINE>
                    bar
                    <BLANKLINE>
            z�
                If the ellipsis flag is used, then '...' can be used to
                elide substrings in the desired output:
                    >>> print(list(range(1000))) #doctest: +ELLIPSIS
                    [0, 1, 2, ..., 999]
            a�
                If the whitespace normalization flag is used, then
                differences in whitespace are ignored.
                    >>> print(list(range(30))) #doctest: +NORMALIZE_WHITESPACE
                    [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14,
                     15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26,
                     27, 28, 29]
            )r�r�zbool-int equivalencezblank linesZellipsiszwhitespace normalizationcCs"ddl}|jdd�}|jdddddd	�|jd
ddt��gd
d�|jddddd�|jdddd�|��}|j}|j}d}|jD]}|t|O}q�|j	r�|t
O}|D]v}|�d�r�tj
�|�\}}tj
�d|�t|dd��}	tj
d=t|	||d�\}
}nt|d||d�\}
}|
r�dSq�dS)Nr"zdoctest runner)Zdescriptionrz	--verbose�
store_trueFz'print very verbose output for all tests)�action�default�helpz-oz--optionr�zqspecify a doctest option flag to apply to the test run; may be specified more than once to apply multiple options)r��choicesr�r�z-fz--fail-fastzystop running tests after first failure (this is a shorthand for -o FAIL_FAST, and is in addition to any other -o options))r�r�r`r�z file containing the tests to run)�nargsr�z.py���re)rVr�rr&)�argparse�ArgumentParser�add_argumentr'�keys�
parse_argsr`r�r�Z	fail_fastrrir�r�rtr>�insertr;rr)r�r�r�Z	testfilesr�r�r�rT�dirnamer�rrPr,r,r-�_test�
sH�
�
��

�
r�r�)r4)rY)	NNNNTr"NFF)FroNr")NNNN)FN)FN)F)RZ
__docformat__�__all__r.r^r7r�r�r�r[r>rars�ior#�collectionsr$r%r'rrrrrrrrr	r
rrrr
rZrsr3rDrJrXr_rfrgr|r�r�r�r�rOrrrrrr�	Exceptionrrrrgrrrrprrtrrr�Z	TestSuiter�rr�r�rrrr r�r!r�rr�r6�exitr,r,r,r-�<module>0s�-
���������

1%.DKl:;n�
h�
{�
$$
@
�
IR


,	�3-


?>