Your IP : 3.141.198.113


Current Path : /opt/alt/python310/lib64/python3.10/__pycache__/
Upload File :
Current File : //opt/alt/python310/lib64/python3.10/__pycache__/doctest.cpython-310.opt-2.pyc

o

6��f���@sF	dZgd�ZddlZddlZddlZddlZddlZddlZddlZddl	Z	ddl
Z
ddlZddlm
Z
mZddlmZedd�ZiZdd	�Zed
�Zed�Zed�Zed
�Zed�Zed�ZeeBeBeBeBeBZed�Zed�Zed�Zed�Zed�ZeeBeBeBeBZ dZ!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�Z0Gd3d4�d4�Z1Gd5d6�d6�Z2Gd7d8�d8�Z3Gd9d:�d:�Z4Gd;d<�d<�Z5Gd=d>�d>e6�Z7Gd?d@�d@e6�Z8GdAdB�dBe4�Z9da:			DdsdEdF�Z;dCdddddCdddDe2�dfdGdH�Z<	I	dtdJdK�Z=da>dLdM�Z?GdNdO�dOej@�ZAGdPdQ�dQeA�ZBGdRdS�dSejC�ZDdudTdU�ZEGdVdW�dWeA�ZFdCdde2�dfdXdY�ZGdZd[�ZHd\d]�ZId^d_�ZJdvd`da�ZKdvdbdc�ZLdwddde�ZMGdfdg�dg�ZNeNdhdidjdkdldm�ZOdndo�ZPeQdpk�r�e	�ReP��dSdS)xzreStructuredText 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�IncrementalNewlineDecoder)�
namedtuple�TestResultszfailed attemptedcCst�|dtt�>�S)N�)�OPTIONFLAGS_BY_NAME�
setdefault�len��name�r-�./opt/alt/python310/lib64/python3.10/doctest.pyr�srrrrrrrr	r
rrrz<BLANKLINE>z...cCs:	d}tjD]}|�|d�}|tt|�ur||jO}q|S)Nr")�
__future__Zall_feature_names�get�getattrZ
compiler_flag)�globs�flagsZfnameZfeaturer-r-r.�_extract_future_flags�s

�r4�cCsT	t�|�r|St|t�rt|t�t�dg�S|dur&tjt�	|�j
dStd��)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
	
rEcCstdd��|d�S�NT)r$�decode)�datar-r-r.�_newline_convert�srIcCs�|r;t|d�}t||�}t|dd�}dur&z|jj}Wn	ty%Ynwt|d�r;|�|�}|�|�}t	|�|fSt
||d��}|��|fWd�S1sRwYdS)N��
__loader__�get_data)�encoding)rE�_module_relative_pathr1�__spec__�loader�AttributeError�hasattrrLrGrI�open�read)�filename�package�module_relativerMrPZ
file_contents�fr-r-r.�_load_testfile�s 

�



$�rY�cCs	t�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

rgc@seZdZdd�Zddd�ZdS)�	_SpoofOutcCs$t�|�}|r|�d�s|d7}|S�N�
)r#rd�endswith)�self�resultr-r-r.rds
z_SpoofOut.getvalueNcCs|�|�t�|�dS�N)�seekr#�truncate)rl�sizer-r-r.rp
s
z_SpoofOut.truncatern)r7�
__module__�__qualname__rdrpr-r-r-r.rhs	rhcCs�	t|vr	||kS|�t�}dt|�}}|d}|r*|�|�r(t|�}|d=ndS|d}|rA|�|�r?|t|�8}|d=ndS||krGdS|D]}|�|||�}|dkrYdS|t|�7}qIdS)Nr"F���T)�ELLIPSIS_MARKER�splitr*�
startswithrk�find)�want�gotZwsZstartpos�endpos�wr-r-r.�_ellipsis_matchs2


r}cCs	|��}|rd|SdS)Nz# �#)�rstrip)�liner-r-r.�
_comment_line@s
r�cCshdt|�}}|�d�}|dkr|}|�dd|�}|dkr|}|�dd|�}|dkr.|d}|||�S)Nr"rj�:�.r')r*rx�rfind)�msg�start�end�ir-r-r.�_strip_exception_detailsHs
r�c@s0eZdZ	dd�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)rl�outr-r-r.r�hs
z_OutputRedirectingPdb.__init__NcCs*d|_|durt��j}tj�||�dSrF)r�r?rA�f_backr�r��	set_trace)rl�framer-r-r.r�ps
z_OutputRedirectingPdb.set_tracecCs|jrtj�|�dSdSrn)r�r�r��set_continue�rlr-r-r.r�vs�z"_OutputRedirectingPdb.set_continuecGs4tj}|jt_ztjj|g|�R�W|t_S|t_wrn)r?r�r�r�r��trace_dispatch)rl�args�save_stdoutr-r-r.r�|s
z$_OutputRedirectingPdb.trace_dispatchrn)r7rrrsr�r�r�r�r-r-r-r.r�bs
r�cCs�t�|�std|��|�d�rtd��tjj|�d��}t	|d�r,tj�|j
�d}nF|jdkrOtt
j�dkrKt
jddkrKtj�t
jd�d}n'tj}n#t	|d�rk|jD]}tj�||�}tj�|�rj|SqWtd	|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__))r8r9rCrw�
ValueError�os�path�joinrvrRr�r7r*r?�argv�curdirr��exists)rDZ	test_pathZbasedirZ	directory�fullpathr-r-r.rN�s*





��rNc@s,eZdZ			d	dd�Zdd�Zdd�ZdS)
rNr"cCsv|�d�s	|d7}|r|�d�s|d7}|dur!|�d�s!|d7}||_||_||_||_|dur3i}||_||_dSri)rk�sourcery�linenor_�options�exc_msg)rlr�ryr�r�r_r�r-r-r.r��s

zExample.__init__cC�\t|�t|�ur
tS|j|jko-|j|jko-|j|jko-|j|jko-|j|jko-|j|jkSrn)�type�NotImplementedr�ryr�r_r�r��rl�otherr-r-r.�__eq__��
�
�
�
�
�zExample.__eq__cCst|j|j|j|j|jf�Srn)�hashr�ryr�r_r�r�r-r-r.�__hash__�s�zExample.__hash__)Nr"r"N)r7rrrsr�r�r�r-r-r-r.r�s"
�rc@s6eZdZ	dd�Zdd�Zdd�Zdd�Zd	d
�ZdS)rcCs.	||_||_|��|_||_||_||_dSrn)�examples�	docstring�copyr2r,rUr�)rlr�r2r,rUr�r�r-r-r.r�s

zDocTest.__init__cCsRt|j�dkr
d}nt|j�dkrd}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__r7r,rUr�)rlr�r-r-r.�__repr__s��zDocTest.__repr__cCr�rn)r�r�r�r�r2r,rUr�r�r-r-r.r�*r�zDocTest.__eq__cC�t|j|j|j|jf�Srn)r�r�r,rUr�r�r-r-r.r�5szDocTest.__hash__cCs:t|t�stS|j|j|jt|�f|j|j|jt|�fkSrn)r:rr�r,rUr��idr�r-r-r.�__lt__9s

�zDocTest.__lt__N)r7rrrsr�r�r�r�r�r-r-r-r.r�src@s�eZdZ	e�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	|��}|�|���dkrd��fdd�|�d�D��}g}d\}}|j�|�D]M}|�|||����||�d||���7}|�	|||�\}}}	}
|�
|�se|�t||	|
|�t|�
d��|d��||�d|��|���7}|��}q)|�||d��|S)Nr"rjc�g|]}|�d��qSrnr-��.0�l�Z
min_indentr-r.�
<listcomp>��z'DocTestParser.parse.<locals>.<listcomp>�r"r"r_)r�r_r�)�
expandtabs�_min_indentr�rv�_EXAMPLE_RE�finditer�appendr��count�_parse_example�_IS_BLANK_OR_COMMENTrr*�groupr�)rl�stringr,�outputZcharnor��mr�r�ryr�r-r�r.�parsets,

�
�
zDocTestParser.parsecCs	t|�||�|||||�Srn)r�get_examples)rlr�r2r,rUr�r-r-r.�get_doctest�s�zDocTestParser.get_doctestcCs	dd�|�||�D�S)NcSsg|]	}t|t�r|�qSr-)r:r)r��xr-r-r.r��s
�z.DocTestParser.get_examples.<locals>.<listcomp>)r�)rlr�r,r-r-r.r��s
zDocTestParser.get_examplesc
s	t|�d���|�d��d�}|�|�||�|�|dd�d�d||�d��fdd�|D��}|�d	�}|�d�}t|�dkrOt�d
|d�rO|d=|�|d�||t|��d��fdd�|D��}|j�|�}|rw|�d
�}nd}|�	|||�}	||	||fS)Nr_r�rjr'r[r�csg|]
}|�dd��qS)rZNr-)r�Zsl�r_r-r.r��sz0DocTestParser._parse_example.<locals>.<listcomp>ryz *$rtcr�rnr-)r�Zwlr�r-r.r��r�r�)
r*r�rv�_check_prompt_blank�
_check_prefixr�r\�match�
_EXCEPTION_RE�
_find_options)
rlr�r,r��source_linesr�ry�
want_linesr�r�r-r�r.r��s( 


�zDocTestParser._parse_examplez#\s*doctest:\s*([^\n\'"]*)$c	Cs�	i}|j�|�D];}|�d��dd���}|D]+}|ddvs(|dd�tvr3td|d||f��t|dd�}|ddk||<qq	|rU|�|�rUtd|||f��|S)	Nr'�,r[r"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��replacervr(r�r�)	rlr�r,r�r�r�Zoption_strings�option�flagr-r-r.r��s$���zDocTestParser._find_optionsz
^([ ]*)(?=\S)cCs0	dd�|j�|�D�}t|�dkrt|�SdS)NcS�g|]}t|��qSr-)r*)r�r_r-r-r.r��z-DocTestParser._min_indent.<locals>.<listcomp>r")�
_INDENT_RE�findallr*�min)rlr^�indentsr-r-r.r�	s
zDocTestParser._min_indentc	Cs`	t|�D](\}}t|�|dkr-||ddkr-td||d||||d�|f��qdS)NrZrJr[z8line %r of the docstring for %s lacks blank after %s: %rr')�	enumerater*r�)rl�linesr_r,r�r�r�r-r-r.r�s ����z!DocTestParser._check_prompt_blankcCs@	t|�D]\}}|r|�|�std||d||f��qdS)NzGline %r of the docstring for %s has inconsistent leading whitespace: %rr')r�rwr�)rlr��prefixr,r�r�r�r-r-r.r�s���zDocTestParser._check_prefixN)r�)r7rrrsr\�compile�	MULTILINE�VERBOSEr��DOTALLr�r�r�r�r�r�r�r�r�r�r�r�r�r-r-r-r.rDs*
��
'
3�rc@sTeZdZ	de�ddfdd�Zddd�Zdd	�Zd
d�Zdd
�Zdd�Z	dd�Z
dS)rFTcCs	||_||_||_||_dSrn)�_parser�_verbose�_recurse�_exclude_empty)rl�verbose�parser�recurse�
exclude_emptyr-r-r.r�8s

zDocTestFinder.__init__Nc		CsJ	|durt|dd�}|durtdt|�f��|durd}n	|dur(t�|�}zt�|�}Wnty:d}Yn2w|sPt�|�}|d|dd�dksPd}|durWd}n|durct�	||j
�}nt�	|�}|sld}|dur}|durwi}n
|j
��}n|��}|dur�|�|�d|vr�d|d<g}|�
||||||i�|��|S)Nr7zJDocTestFinder.find: name must be given when obj.__name__ doesn't exist: %rFr"���z<]>r�)r1r�r�r8�	getmoduleZ
getsourcefilerCZgetfile�	linecache�getlines�__dict__r��update�_find�sort)	rl�objr,rDr2�
extraglobsrar��testsr-r-r.rxNsN#�
�


zDocTestFinder.findcCs�	|durdSt�|�dur|t�|�uSt�|�r |j|juSt�|�r?t|d�r/|jj}nt|d�r8|j}ndS|j	|kSt�
|�rJ|j	|jkSt|d�rU|j	|jkSt|t�r\dSt
d��)NT�__objclass__rrz"object must be a class or function)r8r��
isfunctionr��__globals__ZismethoddescriptorrRrrrr7�isclassr:�propertyr�)rlrD�objectZobj_modr-r-r.�_from_module�s*








zDocTestFinder._from_modulecCs2	|}zt�|�}Wn	tyYnwt�|�Srn)r8Zunwrapr��	isroutine)rlrZ
maybe_routiner-r-r.�_is_routine�s�
zDocTestFinder._is_routinec
Cs�	|jr
td|�t|�|vrdSd|t|�<|�|||||�}|dur*|�|�t�|�r]|jr]|j�	�D]%\}	}
d||	f}	|�
|
�sKt�|
�r\|�||
�r\|�
||
|	||||�q7t�|�r�|jr�t|di��	�D]@\}	}
t|	t�stdt|	�f��t�|
�s�t�|
�s�t�|
�s�t|
t�s�tdt|
�f��d||	f}	|�
||
|	||||�qmt�|�r�|jr�|j�	�D]8\}	}
t|
ttf�r�|
j}
t�|
�s�t�|
�s�t|
t�r�|�||
�r�d||	f}	|�
||
|	||||�q�dSdSdS)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�r8r9r�r��itemsrrr
r�r1r:r;r�r�r�staticmethod�classmethod�__func__r)rlrrr,rDr�r2�seen�testZvalname�valr-r-r.r��sj

���
������
����zDocTestFinder._findc		Cs�	t|t�r	|}n$z|jdurd}n|j}t|t�st|�}Wn
ttfy,d}Ynw|�||�}|jr:|s:dS|durAd}nt|dd�pI|j}|dd�dkrX|dd�}|j	�
|||||�S)Nr�r�����.pycrt)r:r;�__doc__rCrQ�_find_linenor�r1r7r�r�)	rlrr,rDr2r�r�r�rUr-r-r.rs0


��
�zDocTestFinder._get_testcCs6	d}t|dd�}t�|�r|durd}t�|�r@|dur@|dur#dSt�dt|dd��}t|�D]
\}}|�|�r?|}nq2t�|�rH|j	}t�
|�rVt|dd�rV|j}t�|�r^|j
}t�|�rf|j}t�|�rst|dd�d}|dur�|dur|dSt�d�}t|t|��D]
}|�||�r�|Sq�dS)	Nrr"z^\s*class\s*%s\br7�-�co_firstlinenor'z(^|.*:)\s*\w*("|\'))r1r8r9rr\r�r�r�Zismethodrr�__code__Zistraceback�tb_frameZisframe�f_codeZiscode�ranger*)rlrr�r�r�Zpatr�r�r-r-r.r>s@
�
�

�zDocTestFinder._find_lineno�NNNN)r7rrrsrr�rxr
rr�rrr-r-r-r.r/s
�
f=&rc@s�eZdZ	dZddd�Zdd�Zdd	�Zd
d�Zdd
�Zdd�Z	dd�Z
dd�Ze�
d�Zddd�Zd dd�Zddd�Zdd�ZdS)!rzF**********************************************************************Nr"cCsP	|pt�|_|durdtjv}||_||_||_d|_d|_i|_	t
�|_dS)N�-vr")r�_checkerr?r�r��optionflags�original_optionflags�tries�failures�_name2ftrh�_fakeout)rl�checkerr�r$r-r-r.r��s
zDocTestRunner.__init__cCsP	|jr&|jr|dt|j�dt|j��dS|dt|j�d�dSdS)NzTrying:
zExpecting:
zExpecting nothing
)r�ryr`r�)rlr�r�exampler-r-r.�report_start�s�
�
��zDocTestRunner.report_startcCs	|jr
|d�dSdS)Nzok
)r��rlr�rr+rzr-r-r.�report_success�s�zDocTestRunner.report_successcCs(	||�||�|j�|||j��dSrn)�_failure_headerr#�output_differencer$r-r-r-r.�report_failure�s
�zDocTestRunner.report_failurecCs&	||�||�dtt|���dS)NzException raised:
)r/r`rg�rlr�rr+rer-r-r.�report_unexpected_exception�s�

�z)DocTestRunner.report_unexpected_exceptioncCs�|jg}|jr)|jdur|jdur|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:rj)�DIVIDERrUr�r�r,r�r`r�)rlrr+r�r�r�r-r-r.r/�s�

zDocTestRunner._failure_headerc	Csj	d}}|j}td�\}}}	|jj}
t|j�D�]\}}|jt@o%|dk}
||_|jrH|j��D]\}}|r?|j|O_q1|j|M_q1|jt	@rNq|d7}|
s[|�
|||�d|j|f}ztt
|j|d|d�|j�|j��d}Wnty��t��}|j��Y|j��}|j�d�|}|dur�|
|j||j�r�|}n9tj|dd��d}|
s�|t|�7}|jdur�|	}n|
|j||j�r�|}n|jt@r�|
t|j�t|�|j�r�|}||ur�|
s�|�||||�n)||u�r|
�s|� ||||�|d7}n||	u�r|
�s|�!||||�|d7}|�r%|jt"@�r%nq||_|�#|||�t$||�S)	Nr"rJr'z<doctest %s[%d]>ZsingleTr5rt)%r$r r#�check_outputr�r�rr�rrr,r,�execr�r�r2�debuggerr��KeyboardInterruptr?rer)rdrpryrb�format_exception_onlyrgr�rr�r.r1r3r�_DocTestRunner__record_outcomer&)rlr�compileflagsr�r'r&r%�SUCCESS�FAILUREZBOOMZcheck�
examplenumr+�quietZ
optionflagrrUZ	exceptionrzZoutcomer�r-r-r.Z__run
s�

�
��

�


��



��
zDocTestRunner.__runcCsN	|j�|jd�\}}||||f|j|j<|j|7_|j|7_dS)Nr�)r(r0r,r'r&)rlrrX�t�f2�t2r-r-r.Z__record_outcome�s
zDocTestRunner.__record_outcomez.<doctest (?P<name>.+)\[(?P<examplenum>\d+)\]>$cCsR|j�|�}|r#|�d�|jjkr#|jjt|�d��}|jjdd�S|�	||�S)Nr,r?T��keepends)
�%_DocTestRunner__LINECACHE_FILENAME_REr�r�rr,r��intr��
splitlines�save_linecache_getlines)rlrU�module_globalsr�r+r-r-r.Z__patched_linecache_getlines�s
z*DocTestRunner.__patched_linecache_getlinesTc		s@	||_|dur
t|j�}tj�|dur,�j��dus!���dkr%�j}n��fdd�}|jt_t�	�}t
j}t��|_
|j
��|j
jt
_tj|_|jt_tj}tjt_z)|�|||�W�t_|t
_t�|�|jt_|t_|r~|j��ddl}d|_SS�t_|t
_t�|�|jt_|t_|r�|j��ddl}d|_w)N�utf-8cs t|��d���}��|�dS)N�backslashreplace)r;�encode�write)r^�rMr�r-r.r��szDocTestRunner.run.<locals>.outr")rr4r2r?r�rM�lowerrNr)�gettracer�r�r�r8�resetr�r�rI�*_DocTestRunner__patched_linecache_getlines�displayhook�__displayhook__�_DocTestRunner__run�settrace�clear�builtins�_)	rlrr<r��clear_globsZ
save_traceZsave_set_traceZsave_displayhookrYr-rOr.�run�sR





��

zDocTestRunner.runc
Cs�	|dur|j}g}g}g}d}}|j��D]+}|\}\}	}
||
7}||	7}|
dkr1|�|�q|	dkr=|�||
f�q|�|�q|rx|r\tt|�d�|��|D]}td|�qT|rxtt|�d�|��|D]\}}td||f�qk|r�t|j�tt|�d�|��|D]\}\}	}
td|	|
|f�q�|r�t|dt|j�d	�t||d
|d�|r�td|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�r(rr�rr*rr5r&)
rlr�ZnotestsZpassedZfailedZtotaltZtotalfr�r,rXrA�thingr�r-r-r.�	summarize�sR


zDocTestRunner.summarizecCsR|j}|j��D]\}\}}||vr ||\}}||}||}||f||<qdSrn)r(r)rlr��dr,rXrArBrCr-r-r.�merge!s�zDocTestRunner.merge)NNr"rn�NNT)r7rrrsr5r�r,r.r1r3r/rVr;r\r�rFrSr\r^r`r-r-r-r.rvs 9
$
}




I9rc@s.eZdZ	dd�Zdd�Zdd�Zdd�Zd	S)
rcCs	t|�dd�d�S)N�ASCIIrL)r;rM)rlr^r-r-r.�_toAscii6szOutputChecker._toAsciicCs�	|�|�}|�|�}||krdS|t@s%||fdkrdS||fdkr%dS|t@sBt�dt�t�d|�}t�dd|�}||krBdS|t@rZd�|�	��}d�|�	��}||krZdS|t
@ret||�redSdS)	NT)zTrue
z1
)zFalse
z0
z(?m)^%s\s*?$r�z(?m)^[^\S\n]+$r[F)rcrrr\r]�escape�BLANKLINE_MARKERrr�rvrr}�rlryrzr$r-r-r.r6<s4

�
zOutputChecker.check_outputcCs<|ttBtB@s
dS|t@rdS|�d�dko|�d�dkS)NFTrjr5)r	r
rr�rfr-r-r.�_do_a_fancy_diff{s��zOutputChecker._do_a_fancy_diffc
Cs 	|j}|t@st�dt|�}|�|||�rp|jdd�}|jdd�}|t@r9tj	||dd�}t
|�dd�}d}n,|t@rPtj||dd�}t
|�dd�}d}n|t
@retjtjd�}	t
|	�||��}d	}d
|td�|��S|r~|r~dt|�t|�fS|r�d
t|�S|r�dt|�SdS)Nz(?m)^[ ]*(?=
)TrDr5)�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
)ryrr\r]rergrHr	�difflibZunified_diff�listr
Zcontext_diffrZDifferZIS_CHARACTER_JUNKZcomparer`r�)
rlr+rzr$ryr�Z	got_linesZdiff�kindZenginer-r-r.r0�s6zOutputChecker.output_differenceN)r7rrrsrcr6rgr0r-r-r-r.r.s?rc@�eZdZ	dd�Zdd�ZdS)rcC�||_||_||_dSrn)rr+rz)rlrr+rzr-r-r.r���
zDocTestFailure.__init__cC�
t|j�Srn�r;rr�r-r-r.�__str__��
zDocTestFailure.__str__N�r7rrrsr�rqr-r-r-r.r��
rc@rl)rcCrmrn)rr+re)rlrr+rer-r-r.r��rnzUnexpectedException.__init__cCrornrpr�r-r-r.rq�rrzUnexpectedException.__str__Nrsr-r-r-r.r�rtrc@s(eZdZ	d	dd�Zdd�Zdd�ZdS)
rNTcCs$t�||||d�}|r|j��|S)NF)rr\r2rX)rlrr<r�r[�rr-r-r.r\As
zDebugRunner.runcC�t|||��rn)rr2r-r-r.r3G�z'DebugRunner.report_unexpected_exceptioncCrvrn)rr-r-r-r.r1JrwzDebugRunner.report_failurera)r7rrrsr\r3r1r-r-r-r.r�s

ZrTFc	Cs�	|durtj�d�}t�|�std|f��|dur|j}t|d�}	|r,t||d�}
nt	||d�}
|	j
||||d�D]}|
�|�q;|rI|
��t
durP|
a
nt
�|
�t|
j|
j�S)Nr�ztestmod: module required; %r)r��r�r$�r2r)r?r@r0r8r9rCr7rrrrxr\r^�masterr`r&r'r&)r�r,r2r��reportr$r�raise_on_errorr��finder�runnerrr-r-r.rVs&B


rcCs�	|r	|s	td��t||||pd�\}}|durtj�|�}|dur%i}n|��}|dur2|�|�d|vr:d|d<|	rCt||d�}
nt||d�}
|
�	||||d�}|
�
|�|r]|
��tdurd|
ant�
|
�t|
j|
j�S)N�8Package may only be specified for module-relative paths.rKr7r�rxr")r�rYr�r��basenamer�r�rrr�r\r^rzr`r&r'r&)rUrWr,rVr2r�r{r$rr|r�rM�textr~rr-r-r.r�s4N�


r�NoNamec	CsB	t|dd�}t||d�}|j|||d�D]	}|j||d�qdS)NF)r�r�rx)r2)r<)rrrxr\)	rXr2r�r,r<r$r}r~rr-r-r.r9s�rcCs$	|t@|krtd|��t}|a|S)NzOnly reporting flags allowed)r
r��_unittest_reportflags)r3�oldr-r-r.rVs
rc@speZdZ		ddd�Zdd�Zdd�Zd	d
�Zdd�Zd
d�Zdd�Z	dd�Z
dd�Zdd�Ze
jZdd�ZdS)�DocTestCaser"NcCs:tj�|�||_||_|j��|_||_||_	||_
dSrn)�unittest�TestCaser��_dt_optionflags�_dt_checkerr2r��	_dt_globs�_dt_test�	_dt_setUp�_dt_tearDown)rlrr$�setUp�tearDownr*r-r-r.r�|s
zDocTestCase.__init__cCs"|j}|jdur|�|�dSdSrn)r�r��rlrr-r-r.r��s
�zDocTestCase.setUpcCs6|j}|jdur
|�|�|j��|j�|j�dSrn)r�r�r2rXr�r�r�r-r-r.r��s



zDocTestCase.tearDowncCs�|j}tj}t�}|j}|t@s|tO}t||jdd�}zd|_	|j
||jdd�\}}W|t_n|t_w|r@|�|�
|�����dS)NF�r$r*r�zF----------------------------------------------------------------------)r�r[)r�r?r�r#r�r
r�rr�r5r\rNZfailureException�format_failurerd)rlrr��newr$r~r'r&r-r-r.�runTest�s$���zDocTestCase.runTestcCsP|j}|jdurd}nd|j}d�|j�d�dd��}d|j|j|||fS)Nzunknown line numberz%sr�rtz:Failed doctest test for %s
  File "%s", line %s, in %s

%s)r�r�r�r,rvrU)rl�errrr�Zlnamer-r-r.r��s

�zDocTestCase.format_failurecCs8	|��t|j|jdd�}|j|jdd�|��dS)NFr�)r[)r�rr�r�r\r�r�)rlr~r-r-r.r!�sA�zDocTestCase.debugcC�|jjSrn�r�r,r�r-r-r.r�	�zDocTestCase.idcCsPt|�t|�ur
tS|j|jko'|j|jko'|j|jko'|j|jko'|j|jkSrn)r�r�r�r�r�r�r�r�r-r-r.r�	s
�
�
�
�zDocTestCase.__eq__cCr�rn)r�r�r�r�r�r�r-r-r.r�	s�zDocTestCase.__hash__cCs,|jj�d�}d|dd�|dd��fS)Nr�z%s (%s)rt)r�r,rvr�)rlr,r-r-r.r�	szDocTestCase.__repr__cCsd|jjS)Nz	Doctest: r�r�r-r-r.�shortDescription	rwzDocTestCase.shortDescription)r"NNN)r7rrrsr�r�r�r�r�r!r�r�r�r�r	rqr�r-r-r-r.r�zs
�
H
r�c@s0eZdZdd�Zdd�Zdd�Zdd�ZeZd	S)
�SkipDocTestCasecCs||_t�|d�dSrn)rDr�r�)rlrDr-r-r.r�	szSkipDocTestCase.__init__cCs|�d�dS)Nz-DocTestSuite will not work with -O2 and above)ZskipTestr�r-r-r.r�"	szSkipDocTestCase.setUpcC�dSrnr-r�r-r-r.�	test_skip%	�zSkipDocTestCase.test_skipcCsd|jjS)NzSkipping tests from %s)rDr7r�r-r-r.r�(	rwz SkipDocTestCase.shortDescriptionN)r7rrrsr�r�r�r�rqr-r-r-r.r�	sr�c@seZdZdd�ZdS)�
_DocTestSuitecCr�rnr-)rl�indexr-r-r.�_removeTestAtIndex0	r�z _DocTestSuite._removeTestAtIndexN)r7rrrsr�r-r-r-r.r�.	sr�c	Ks�	|durt�}t|�}|j|||d�}|s(tjjdkr(t�}|�t|��|S|�	�t�}|D],}t
|j�dkr;q1|jsR|j
}|dd�dkrO|dd�}||_|�t|fi|���q1|S)Nryr5r"rrrt)rrErxr?r3�optimizer��addTestr�rr*r�rUr�r�)	rDr2rZtest_finderr�r�suiterrUr-r-r.r4	s*#rc@s$eZdZdd�Zdd�Zdd�ZdS)�DocFileCasecCsd�|jj�d��S)NrZr�)r�r�r,rvr�r-r-r.r�v	szDocFileCase.idcCr�rn)r�rUr�r-r-r.r�y	r�zDocFileCase.__repr__cCsd|jj|jj|fS)Nz2Failed doctest test for %s
  File "%s", line 0

%s)r�r,rU)rlr�r-r-r.r�|	s�zDocFileCase.format_failureN)r7rrrsr�r�r�r-r-r-r.r�t	sr�c
Ksz|duri}n|��}|r|std��t||||pd�\}}d|vr&||d<tj�|�}|�||||d�}	t|	fi|��S)NrrKr�r")r�r�rYr�r�r�r�r�)
r�rWrVr2r�rMr��docr,rr-r-r.�DocFileTest�	s�r�cOsJ	t�}|�dd�rt|�d��|d<|D]
}|�t|fi|���q|S)NrWTrV)r�r0rEr�r�)�paths�kwr�r�r-r-r.r�	s7rcCs�	g}t��|�D]<}t|t�r5|�|jdd��|j}|r4|�d�|dd�|�d�dd�D�7}q	|dd�|�d�dd�D�7}q	|rZ|ddkrZ|��|rZ|ddksN|ro|ddkro|�d�|ro|ddksbd�	|�dS)	Nrtz# Expected:cSsg|]}d|�qS)z## r-r�r-r-r.r�'
r�z(script_from_examples.<locals>.<listcomp>rjcSr�r-)r�r�r-r-r.r�*
s�r~r")
rr�r:rr�r�ryrv�popr�)r^r�Zpieceryr-r-r.r�	s(9

 �
��
�rcsL	t|�}t��|�}�fdd�|D�}|st�d��|d}t|j�}|S)Ncsg|]	}|j�kr|�qSr-r+)r�rAr+r-r.r�?
sztestsource.<locals>.<listcomp>znot found in testsr")rErrxr�rr�)rDr,rr�testsrcr-r+r.r6
s

rcCs	t|�}t|||�dSrn)r�debug_script)�src�pmr2r�r-r-r.r F
sr cCs�	ddl}|r|��}ni}|r<z	t|||�WdStt��d�|jdd�}|��|�dt��d�YdS|jdd��	d|||�dS)Nr"r'T)r�r5zexec(%r))
r�r�r7rr?rer�rRZinteractionr\)r�r�r2r��pr-r-r.r�K
s
r�cCs&	t|�}t||�}t|||j�dSrn)rErr�r�)rDr,r�r�r-r-r.r!_
s
r!c@s&eZdZ	dd�Zdd�Zdd�ZdS)�
_TestClasscCs	||_dSrn�r)rlrr-r-r.r�{
s
z_TestClass.__init__cCs	|jd|_|S)Nr5r�r�r-r-r.�square�
sz_TestClass.squarecCs	|jSrnr�r�r-r-r.r0�
sz_TestClass.getN)r7rrrsr�r�r0r-r-r-r.r�m
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}qA|j	rQ|t
O}|D];}|�d�rtj
�|�\}}tj
�d|�t|dd��}	tj
d=t|	||d�\}
}n
t|d||d�\}
}|
r�dSqSdS)Nr"zdoctest runner)�descriptionr"z	--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�rar�z file containing the tests to run)�nargsr�z.py���rx)rWr�r$r')�argparse�ArgumentParser�add_argumentr(�keys�
parse_argsrar�r�Z	fail_fastrrkr�r�rvr?�insertr<rr)r�r�r�Z	testfilesr�r�r�rU�dirnamer�r'rZr-r-r.�_test�
sJ�
�
��


��r�r�)r5)rZ)	NNNNTr"NFF)Fr�Nr"r!)FN)F)SZ
__docformat__�__all__r/rir8r�r�r�r\r?rbr��ior#r$�collectionsr%r&r(rrrrrrrrr	r
rrrr
rerur4rErIrYr`rgrhr}r�r�r�r�rNrrrrrr�	Exceptionrrrrzrrrr�rr�r�r�Z	TestSuiter�rr�r�rrrr r�r!r�r
r�r7�exitr-r-r-r.�<module>s�'-
���������

1%.DKlI;n
�h
�{
�$$
@

�IR


,	�3
-�

?>