AlkantarClanX12

Your IP : 3.133.144.147


Current Path : /proc/self/root/usr/lib64/python3.6/__pycache__/
Upload File :
Current File : //proc/self/root/usr/lib64/python3.6/__pycache__/doctest.cpython-36.opt-2.pyc

3


 \Ǘ�!@spdZddddddddd	d
ddd
ddddddddddddddddddd d!g!Zd"d#lZd"d#lZd"d#lZd"d#lZd"d#lZd"d#lZd"d#lZd"d#l	Z	d"d#l
Z
d"d#lZd"d#lZd"d$l
mZd"d%lmZed&d'�ZiZd(d�Zed�Zed�Zed�Zed�Zed�Zed�ZeeBeBeBeBeBZed	�Zed
�Zed�Zed�Zed�ZeeBeBeBeBZ d)Z!d*Z"d+d,�Z#dpd.d/�Z$d0d1�Z%dqd3d4�Z&d5d6�Z'Gd7d8�d8e�Z(d9d:�Z)d;d<�Z*d=d>�Z+Gd?d@�d@ej,�Z-dAdB�Z.GdCd�d�Z/GdDd�d�Z0GdEd�d�Z1GdFd�d�Z2GdGd�d�Z3GdHd�d�Z4GdId�de5�Z6GdJd�de5�Z7GdKd�de3�Z8d#a9drdNd�Z:dLd#d#d#d#dLd"d#dMe1�d#fdOd�Z;dsdQd�Z<d"a=dRd�Z>GdSdT�dTej?�Z@GdUdV�dVe@�ZAGdWdX�dXejB�ZCdtdYd�ZDGdZd[�d[e@�ZEdLd#d#e1�d#fd\d]�ZFd^d�ZGd_d�ZHd`d�ZIdudad �ZJdvdbdc�ZKdwddd!�ZLGdedf�df�ZMeMdgdhdidjdkdl�ZNdmdn�ZOePdok�rle
jQeO��d#S)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)�
namedtuple�TestResultszfailed attemptedcCstj|dtt�>�S)N�)�OPTIONFLAGS_BY_NAME�
setdefault�len)�name�r+�/usr/lib64/python3.6/doctest.pyr�sz<BLANKLINE>z...cCs<d}x2tjD](}|j|d�}|tt|�kr||jO}qW|S)Nr")�
__future__Zall_feature_names�get�getattrZ
compiler_flag)�globs�flagsZfnameZfeaturer+r+r,�_extract_future_flags�sr2�cCsVtj|�r|St|t�r,t|t�t�dg�S|dkrJtjtj	|�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


rCc	Cs�|r\t|d�}t||�}t|dd�dk	r\t|jd�r\|jj|�}|j|�}|jtj	d�|fSt
||d��}|j�|fSQRXdS)N��
__loader__�get_data�
)�encoding)rC�_module_relative_pathr/�hasattrrErF�decode�replace�os�linesep�open�read)�filename�package�module_relativerHZ
file_contents�fr+r+r,�_load_testfile�s


rU�cCstjd|d|�S)Nz
(?m)^(?!$)� )�re�sub)�s�indentr+r+r,�_indent�sr\cCs*t�}|\}}}tj||||d�|j�S)N)�file)r#�	traceback�print_exception�getvalue)�exc_infoZexcout�exc_typeZexc_valZexc_tbr+r+r,�_exception_traceback�s
rcc@seZdZdd�Zddd�ZdS)�	_SpoofOutcCs&tj|�}|r"|jd�r"|d7}|S)NrG)r#r`�endswith)�self�resultr+r+r,r`�s
z_SpoofOut.getvalueNcCs|j|�tj|�dS)N)�seekr#�truncate)rf�sizer+r+r,ris
z_SpoofOut.truncate)N)r5�
__module__�__qualname__r`rir+r+r+r,rd�s	rdcCs�t|kr||kS|jt�}dt|�}}|d}|rR|j|�rNt|�}|d=ndS|d}|r�|j|�r||t|�8}|d=ndS||kr�dSx2|D]*}|j|||�}|dkr�dS|t|�7}q�WdS)Nr"Fr&T���rm)�ELLIPSIS_MARKER�splitr)�
startswithre�find)�want�gotZws�startpos�endpos�wr+r+r,�_ellipsis_matchs0



rwcCs|j�}|rd|SdSdS)Nz# �#)�rstrip)�liner+r+r,�
_comment_line9sr{cCshdt|�}}|jd�}|dkr$|}|jdd|�}|dkr>|}|jdd|�}|dkr\|d}|||�S)Nr"rG�:�.r&)r)rq�rfind)�msg�start�end�ir+r+r,�_strip_exception_detailsAs
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)rf�outr+r+r,r�asz_OutputRedirectingPdb.__init__NcCs*d|_|dkrtj�j}tjj||�dS)NT)r�r=r?�f_backr�r��	set_trace)rf�framer+r+r,r�is
z_OutputRedirectingPdb.set_tracecCs|jrtjj|�dS)N)r�r�r��set_continue)rfr+r+r,r�osz"_OutputRedirectingPdb.set_continuecGs.tj}|jt_ztjj|f|��S|t_XdS)N)r=r�r�r�r��trace_dispatch)rf�args�save_stdoutr+r+r,r�us
z$_OutputRedirectingPdb.trace_dispatch)N)r5rkrlr�r�r�r�r+r+r+r,r�[s
r�cCs�tj|�std|��|jd�r(td��tjj|jd��}t	|d�rXtjj|j
�d}n�|jdkr�tt
j�dkr�t
jddkr�tjjt
jd�d}q�tj}nFt	|d�r�x,|jD]"}tjj||�}tjj|�r�|Sq�Wtd	|j��tjj||�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__))r6r7rArp�
ValueErrorrM�path�joinrorJr�r5r)r=�argv�curdirr��exists)rBZ	test_pathZbasedirZ	directoryZfullpathr+r+r,rI�s&





rIc@s&eZdZd	dd�Zdd�Zdd�ZdS)
rNr"cCsz|jd�s|d7}|r*|jd�r*|d7}|dk	rF|jd�rF|d7}||_||_||_||_|dkrji}||_||_dS)NrG)re�sourcerr�linenor[�options�exc_msg)rfr�rrr�r�r[r�r+r+r,r��s
zExample.__init__cCs\t|�t|�k	rtS|j|jkoZ|j|jkoZ|j|jkoZ|j|jkoZ|j|jkoZ|j|jkS)N)�type�NotImplementedr�rrr�r[r�r�)rf�otherr+r+r,�__eq__�szExample.__eq__cCst|j|j|j|j|jf�S)N)�hashr�rrr�r[r�)rfr+r+r,�__hash__�szExample.__hash__)Nr"r"N)r5rkrlr�r�r�r+r+r+r,r�s#
c@s4eZdZdd�Zdd�Zdd�Zdd�Zd	d
�ZdS)rcCs,||_||_|j�|_||_||_||_dS)N)�examples�	docstring�copyr0r*rQr�)rfr�r0r*rQr�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__r5r*rQr�)rfr�r+r+r,�__repr__szDocTest.__repr__cCs\t|�t|�k	rtS|j|jkoZ|j|jkoZ|j|jkoZ|j|jkoZ|j|jkoZ|j|jkS)N)r�r�r�r�r0r*rQr�)rfr�r+r+r,r�#szDocTest.__eq__cCst|j|j|j|jf�S)N)r�r�r*rQr�)rfr+r+r,r�.szDocTest.__hash__cCs:t|t�stS|j|j|jt|�f|j|j|jt|�fkS)N)r8rr�r*rQr��id)rfr�r+r+r,�__lt__2s
zDocTest.__lt__N)r5rkrlr�r�r�r�r�r+r+r+r,r�s
c@s�eZdZejdejejB�ZejdejejBejB�Z	ejd�j
Zddd�Zdd�Z
dd	d
�Zdd�Zejd
ej�Zdd�Zejdej�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>cs|j�}|j|���dkr8dj�fdd�|jd�D��}g}d\}}x�|jj|�D]�}|j|||j���||jd||j��7}|j	|||�\}}}	}
|j
|�s�|jt||	|
|�t|j
d��|d��||jd|j�|j��7}|j�}qRW|j||d��|S)Nr"rGcsg|]}|�d��qS)Nr+)�.0�l)�
min_indentr+r,�
<listcomp>ysz'DocTestParser.parse.<locals>.<listcomp>r[)r�r[r�)r"r")�
expandtabs�_min_indentr�ro�_EXAMPLE_RE�finditer�appendr��count�_parse_example�_IS_BLANK_OR_COMMENTrr)�groupr�)rf�stringr*�outputZcharnor��mr�r�rrr�r+)r�r,�parsems&


zDocTestParser.parsecCst|j||�|||||�S)N)r�get_examples)rfr�r0r*rQr�r+r+r,�get_doctest�s	zDocTestParser.get_doctestcCsdd�|j||�D�S)NcSsg|]}t|t�r|�qSr+)r8r)r��xr+r+r,r��sz.DocTestParser.get_examples.<locals>.<listcomp>)r�)rfr�r*r+r+r,r��szDocTestParser.get_examplesc
s
t|jd���|jd�jd�}|j|�||�|j|dd�d�d||�dj�fdd�|D��}|jd	�}|jd�}t|�dkr�tjd
|d
�r�|d=|j|d�||t|��dj�fdd�|D��}|jj|�}|r�|jd�}nd}|j	|||�}	||	||fS)Nr[r�rGr&rWr}csg|]}|�dd��qS)rVNr+)r�Zsl)r[r+r,r��sz0DocTestParser._parse_example.<locals>.<listcomp>rrz *$csg|]}|�d��qS)Nr+)r�Zwl)r[r+r,r��srrmrm)
r)r�ro�_check_prompt_blank�
_check_prefixr�rX�match�
_EXCEPTION_RE�
_find_options)
rfr�r*r��source_linesr�rr�
want_linesr�r�r+)r[r,r��s$ 

zDocTestParser._parse_examplez#\s*doctest:\s*([^\n\'"]*)$c	Cs�i}x�|jj|�D]z}|jd�jdd�j�}x^|D]V}|ddksR|dd�tkrhtd|d||f��t|dd�}|ddk||<q2WqW|r�|j|�r�td|||f��|S)	Nr&�,rWr"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�rLror'r�r�)	rfr�r*r�r�r�Zoption_strings�option�flagr+r+r,r��s
zDocTestParser._find_optionsz
^([ ]*)(?=\S)cCs2dd�|jj|�D�}t|�dkr*t|�SdSdS)NcSsg|]}t|��qSr+)r))r�r[r+r+r,r�sz-DocTestParser._min_indent.<locals>.<listcomp>r")�
_INDENT_RE�findallr)�min)rfrZ�indentsr+r+r,r�szDocTestParser._min_indentc	Csbx\t|�D]P\}}t|�|dkr
||ddkr
td||d||||d�|f��q
WdS)NrVrDrWz8line %r of the docstring for %s lacks blank after %s: %rr&)�	enumerater)r�)rf�linesr[r*r�r�rzr+r+r,r�
s
 z!DocTestParser._check_prompt_blankcCsDx>t|�D]2\}}|r
|j|�r
td||d||f��q
WdS)NzGline %r of the docstring for %s has inconsistent leading whitespace: %rr&)r�rpr�)rfr��prefixr*r�r�rzr+r+r,r�szDocTestParser._check_prefixN)r�)r�)r5rkrlrX�compile�	MULTILINE�VERBOSEr��DOTALLr�r�r�r�r�r�r�r�r�r�r�r�r�r+r+r+r,r=s 	
'
3c@sJeZdZde�ddfdd�Zddd�Zdd	�Zd
d�Zdd
�Zdd�Z	dS)rFTcCs||_||_||_||_dS)N)�_parser�_verbose�_recurse�_exclude_empty)rf�verbose�parser�recurse�
exclude_emptyr+r+r,r�1szDocTestFinder.__init__Nc	CsP|dkr.t|dd�}|dkr.tdt|�f��|dkr<d}n|dkrNtj|�}ytj|�}Wntk
rtd}YndX|s�tj|�}|d|dd�dks�d}|dkr�d}n*|dk	r�tj	||j
�}n
tj	|�}|s�d}|dk�r�|dkr�i}n
|j
j�}n|j�}|dk	�r|j|�d|k�r*d|d<g}|j
||||||i�|j�|S)	Nr5zJDocTestFinder.find: name must be given when obj.__name__ doesn't exist: %rFr"r3z<]>r����)r/r�r�r6�	getmoduleZ
getsourcefilerAZgetfile�	linecache�getlines�__dict__r��update�_find�sort)	rf�objr*rBr0�
extraglobsr]r��testsr+r+r,rqGsJ$







zDocTestFinder.findcCs�|dkrdStj|�dk	r(|tj|�kStj|�r>|j|jkStj|�r|t|d�r\|jj}nt|d�rn|j}ndS|j	|kStj
|�r�|j	|jkSt|d�r�|j	|jkSt|t�r�dSt
d��dS)NT�__objclass__rkz"object must be a class or function)r6r��
isfunctionr��__globals__ZismethoddescriptorrJr�rkr5�isclassr8�propertyr�)rfrB�objectZobj_modr+r+r,�_from_module�s(








zDocTestFinder._from_modulec	Cs(|jrtd|�t|�|kr"dSd|t|�<|j|||||�}|dk	rR|j|�tj|�r�|jr�x^|jj	�D]P\}	}
d||	f}	tj
tj|
��s�tj|
�rn|j
||
�rn|j||
|	||||�qnWtj|�o�|j�rtx�t|di�j	�D]�\}	}
t|	t��stdt|	�f��tj
|
��p8tj|
��p8tj|
��p8t|
t��sNtdt|
�f��d||	f}	|j||
|	||||�q�Wtj|��r$|j�r$x�|jj	�D]�\}	}
t|
t��r�t||	�}
t|
t��r�t||	�j}
tj
|
��s�tj|
��s�t|
t��r�|j
||
��r�d||	f}	|j||
|	||||��q�WdS)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�r6r7r�r��itemsZ	isroutineZunwrapr�r�r�r/r8r9r�r��staticmethod�classmethod�__func__r�)rfr�r�r*rBr�r0�seen�testZvalname�valr+r+r,r��sP


zDocTestFinder._findc	Cs�t|t�r|}nJy,|jdkr"d}n|j}t|t�s:t|�}Wnttfk
rXd}YnX|j||�}|jrv|rvdS|dkr�d}n*t|d|j�}|dd�dkr�|dd�}|j	j
|||||�S)Nr�r�rVz.pycr&���rm)r8r9�__doc__rA�AttributeError�_find_linenor�r/r5r�r�)	rfr�r*rBr0r�r�r�rQr+r+r,r�s(



zDocTestFinder._get_testcCsd}tj|�rd}tj|�rd|dkr(dStjdt|dd��}x$t|�D]\}}|j|�rH|}PqHWtj|�rt|j	}tj
|�r�|j}tj|�r�|j
}tj|�r�|j}tj|�r�t|dd�d}|dk	�r|dkr�|dStjd�}x(t|t|��D]}|j||�r�|Sq�WdS)Nr"z^\s*class\s*%s\br5�-�co_firstlinenor&z(^|.*:)\s*\w*("|\'))r6r7r�rXr�r/r�r�Zismethodr�r��__code__Zistraceback�tb_frameZisframe�f_codeZiscode�ranger))rfr�r�r�Zpatr�rzr+r+r,r-s<









zDocTestFinder._find_lineno)NNNN)
r5rkrlrr�rqr�r�r�rr+r+r+r,r(s	
f?%c@s�eZdZddZddd�Zdd�Zd	d
�Zdd�Zd
d�Zdd�Z	dd�Z
dd�Zej
d�Zd dd�Zd!dd�Zd"dd�Zdd�ZdS)#rr4�FNr"cCsN|pt�|_|dkrdtjk}||_||_||_d|_d|_i|_	t
�|_dS)Nz-vr")r�_checkerr=r�r��optionflags�original_optionflags�tries�failures�_name2ftrd�_fakeout)rf�checkerr�rr+r+r,r��s
zDocTestRunner.__init__cCsH|jrD|jr.|dt|j�dt|j��n|dt|j�d�dS)NzTrying:
zExpecting:
zExpecting nothing
)r�rrr\r�)rfr�r��exampler+r+r,�report_start�s zDocTestRunner.report_startcCs|jr|d�dS)Nzok
)r�)rfr�r�rrsr+r+r,�report_success�szDocTestRunner.report_successcCs&||j||�|jj|||j��dS)N)�_failure_headerr�output_differencer)rfr�r�rrsr+r+r,�report_failure�szDocTestRunner.report_failurecCs$||j||�dtt|���dS)NzException raised:
)rr\rc)rfr�r�rrar+r+r,�report_unexpected_exception�sz)DocTestRunner.report_unexpected_exceptioncCs�|jg}|jrR|jdk	r4|jdk	r4|j|jd}nd}|jd|j||jf�n|jd|jd|jf�|jd�|j}|jt|��dj|�S)Nr&�?zFile "%s", line %s, in %szLine %s, in %szFailed example:rG)�DIVIDERrQr�r�r*r�r\r�)rfr�rr�r�r�r+r+r,r�s
zDocTestRunner._failure_headercCs�d}}|j}td�\}}}	|jj}
�xFt|j�D�]6\}}|jt@oL|dk}
||_|jr�x:|jj�D],\}}|r�|j|O_qf|j|M_qfW|jt	@r�q2|d7}|
s�|j
|||�d|j|f}y,tt
|j|d|d�|j�|jj�d}Wn4tk
�r�Yntj�}|jj�YnX|jj�}|jjd�|}|dk�rh|
|j||j��r�|}n|tj|dd��d}|
�s�|t|�7}|jdk�r�|	}nB|
|j||j��r�|}n*|jt@�r�|
t|j�t|�|j��r�|}||k�r|
�sZ|j||||�nT||k�r0|
�s&|j ||||�|d7}n*||	k�rZ|
�sP|j!||||�|d7}n|r2|jt"@r2Pq2W||_|j#|||�t$||�S)Nr"rDr&z<doctest %s[%d]>Zsingler3rm)%rr	r�check_outputr�r�rr�r�rrr*�execr�r�r0�debuggerr��KeyboardInterruptr=rarr`rirrr^�format_exception_onlyrcr�rr�rrrr�_DocTestRunner__record_outcomer%)rfr��compileflagsr�rrr
�SUCCESS�FAILUREZBOOMZcheck�
examplenumr�quietZ
optionflagr�rQZ	exceptionrsZoutcomer�r+r+r,Z__run�s�












zDocTestRunner.__runcCsL|jj|jd�\}}||||f|j|j<|j|7_|j|7_dS)Nr")r"r")rr.r*rr)rfr�rT�t�f2�t2r+r+r,Z__record_outcomeuszDocTestRunner.__record_outcomez.<doctest (?P<name>.+)\[(?P<examplenum>\d+)\]>$cCsV|jj|�}|rF|jd�|jjkrF|jjt|jd��}|jjdd�S|j	||�SdS)Nr*r%T)�keepends)
�%_DocTestRunner__LINECACHE_FILENAME_REr�r�r�r*r��intr��
splitlines�save_linecache_getlines)rfrQ�module_globalsr�rr+r+r,Z__patched_linecache_getlines�s
z*DocTestRunner.__patched_linecache_getlinesTc	s�||_|dkrt|j�}tj�|dkrV�j��dks@�j�dkrH�j}n��fdd�}|jt_tj	�}t
j}t��|_
|j
j�|j
jt
_tj|_|jt_tj}tjt_z|j|||�S�t_|t
_tj|�|jt_|t_|r�|jj�ddl}d|_XdS)Nzutf-8cs t|j�d���}�j|�dS)N�backslashreplace)r9�encode�write)rZ)rHr�r+r,r��szDocTestRunner.run.<locals>.outr")r�r2r0r=r�rH�lowerr2r�gettracer�r�r�r�resetr�r�r.�*_DocTestRunner__patched_linecache_getlines�displayhook�__displayhook__�_DocTestRunner__run�settrace�clear�builtins�_)	rfr�r"r��clear_globsZ
save_traceZsave_set_traceZsave_displayhookr<r+)rHr�r,�run�s<





zDocTestRunner.runc
Cs�|dkr|j}g}g}g}d}}xd|jj�D]V}|\}\}	}
||
7}||	7}|
dkrb|j|�q.|	dkrz|j||
f�q.|j|�q.W|r�|r�tt|�d�|j�x|D]}td|�q�W|r�tt|�d�|j�x |D]\}}td||f�q�W|�rJt|j�tt|�d�|j�x(|D] \}\}	}
td|	|
|f��q&W|�rvt|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�rr�r�r�r)r�rr%)
rfr�ZnotestsZpassedZfailedZtotaltZtotalfr�r*rTr'�thingr�r+r+r,�	summarize�sP

zDocTestRunner.summarizecCsV|j}xJ|jj�D]<\}\}}||krB||\}}||}||}||f||<qWdS)N)rr�)rfr��dr*rTr'r(r)r+r+r,�mergeszDocTestRunner.merge)NNr")N)NNT)N)r5rkrlrr�rrrrrr9r!rXr�r+r6r?rArCr+r+r+r,ras:
$
}



I
9c@s,eZdZdd�Zdd�Zdd�Zdd�Zd	S)
rcCst|jdd�d�S)N�ASCIIr0)r9r1)rfrZr+r+r,�_toAscii!szOutputChecker._toAsciicCs�|j|�}|j|�}||kr dS|t@sH||fdkr8dS||fdkrHdS|t@s�tjdtjt�d|�}tjdd|�}||kr�dS|t@r�d	j|j	��}d	j|j	��}||kr�dS|t
@r�t||�r�dSd
S)
NT�True
�1
�False
�0
z(?m)^%s\s*?$r�z
(?m)^\s*?$rWF)rFrG)rHrI)rErrrXrY�escape�BLANKLINE_MARKERrr�rorrw)rfrrrsrr+r+r,r's0


zOutputChecker.check_outputcCs<|ttBtB@sdS|t@r dS|jd�dko:|jd�dkS)NFTrGr3)r	r
rr�)rfrrrsrr+r+r,�_do_a_fancy_difffszOutputChecker._do_a_fancy_diffc
Cs8|j}|t@stjdt|�}|j|||�r�|jdd�}|jdd�}|t@rptj	||dd�}t
|�dd�}d}nZ|t@r�tj||dd�}t
|�dd�}d}n,|t
@r�tjtjd�}	t
|	j||��}d	}nd
d�|D�}d|td
j|��S|o�|�rdt|�t|�fS|�rdt|�S|�r0dt|�SdSdS)Nz(?m)^[ ]*(?=
)T)r*r3)�nz#unified diff with -expected +actualz-context diff with expected followed by actual)Zcharjunkzndiff with -expected +actualcSsg|]}|j�d�qS)rG)ry)r�rzr+r+r,r��sz3OutputChecker.output_difference.<locals>.<listcomp>zDifferences (%s):
r�zExpected:
%sGot:
%szExpected:
%sGot nothing
zExpected nothing
Got:
%szExpected nothing
Got nothing
)rrrrXrYrKrLr-r	�difflibZunified_diff�listr
Zcontext_diffrZDifferZIS_CHARACTER_JUNKZcomparer\r�)
rfrrsrrrr�Z	got_linesZdiffZkindZenginer+r+r,r}s6
zOutputChecker.output_differenceN)r5rkrlrErrLrr+r+r+r,rs?c@seZdZdd�Zdd�ZdS)rcCs||_||_||_dS)N)r�rrs)rfr�rrsr+r+r,r��szDocTestFailure.__init__cCs
t|j�S)N)r9r�)rfr+r+r,�__str__�szDocTestFailure.__str__N)r5rkrlr�rPr+r+r+r,r�sc@seZdZdd�Zdd�ZdS)rcCs||_||_||_dS)N)r�rra)rfr�rrar+r+r,r��szUnexpectedException.__init__cCs
t|j�S)N)r9r�)rfr+r+r,rP�szUnexpectedException.__str__N)r5rkrlr�rPr+r+r+r,r�sc@s&eZdZd	dd�Zdd�Zdd�ZdS)
rNTcCs$tj||||d�}|r |jj�|S)NF)rr?r0r;)rfr�r"r�r>�rr+r+r,r?.s
zDebugRunner.runcCst|||��dS)N)r)rfr�r�rrar+r+r,r4sz'DebugRunner.report_unexpected_exceptioncCst|||��dS)N)r)rfr�r�rrsr+r+r,r7szDebugRunner.report_failure)NNT)r5rkrlr?rrr+r+r+r,r�s[
TFc	Cs�|dkrtjjd�}tj|�s,td|f��|dkr:|j}t|d�}	|rVt||d�}
nt	||d�}
x$|	j
||||d�D]}|
j|�qvW|r�|
j�t
dkr�|
a
n
t
j|
�t|
j|
j�S)Nr�ztestmod: module required; %r)r�)r�r)r0r�)r=r>r.r6r7rAr5rrrrqr?rA�masterrCr%rr)r�r*r0r��reportrr��raise_on_errorr��finder�runnerr�r+r+r,rCs$E


cCs�|r|rtd��t||||p d�\}}|dkr<tjj|�}|dkrJi}n|j�}|dk	rd|j|�d|krtd|d<|	r�t||d�}
nt||d�}
|
j	||||d�}|
j
|�|r�|
j�tdkr�|
an
tj
|
�t|
j|
j�S)Nz8Package may only be specified for module-relative paths.zutf-8r5r�)r�rr")r�rUrMr��basenamer�r�rrr�r?rArRrCr%rr)rQrSr*rRr0r�rSrr�rTr�rH�textrVr�r+r+r,r�s0R



�NoNamec	CsDt|dd�}t||d�}x&|j|||d�D]}|j||d�q*WdS)NF)r�r�)r�r)r0)r")rrrqr?)	rTr0r�r*r"rrUrVr�r+r+r,r&scCs"|t@|krtd|��t}|a|S)NzOnly reporting flags allowed)r
r��_unittest_reportflags)r1�oldr+r+r,rCs

c@sjeZdZddd�Zdd�Zdd�Zd	d
�Zdd�Zd
d�Zdd�Z	dd�Z
dd�Zdd�ZeZ
dd�ZdS)�DocTestCaser"NcCs.tjj|�||_||_||_||_||_dS)N)�unittest�TestCaser��_dt_optionflags�_dt_checker�_dt_test�	_dt_setUp�_dt_tearDown)rfr�r�setUp�tearDownrr+r+r,r�iszDocTestCase.__init__cCs|j}|jdk	r|j|�dS)N)rarb)rfr�r+r+r,rdss
zDocTestCase.setUpcCs(|j}|jdk	r|j|�|jj�dS)N)rarcr0r;)rfr�r+r+r,reys

zDocTestCase.tearDowncCs�|j}tj}t�}|j}|t@s(|tO}t||jdd�}z$dd|_	|j
||jdd�\}}Wd|t_X|r~|j|j
|j����dS)NF)rrr�rr
)r�r>)rar=r�r#r_r
rZrr`rr?r2ZfailureException�format_failurer`)rfr�r[�newrrVrrr+r+r,�runTest�s
zDocTestCase.runTestcCsP|j}|jdkrd}n
d|j}dj|jjd�dd��}d|j|j|||fS)Nzunknown line numberz%sr}r&z:Failed doctest test for %s
  File "%s", line %s, in %s

%srm)rar�r�r*rorQ)rf�errr�r�Zlnamer+r+r,rf�s

zDocTestCase.format_failurecCs6|j�t|j|jdd�}|j|jdd�|j�dS)NF)rrr�)r>)rdrr_r`r?rare)rfrVr+r+r,r!�s
BzDocTestCase.debugcCs|jjS)N)rar*)rfr+r+r,r��szDocTestCase.idcCsPt|�t|�k	rtS|j|jkoN|j|jkoN|j|jkoN|j|jkoN|j|jkS)N)r�r�rar_rbrcr`)rfr�r+r+r,r��szDocTestCase.__eq__cCst|j|j|j|jf�S)N)r�r_rbrcr`)rfr+r+r,r��szDocTestCase.__hash__cCs,|jjjd�}d|ddj|dd��fS)Nr}z%s (%s)r&rmrm)rar*ror�)rfr*r+r+r,r��szDocTestCase.__repr__cCsd|jjS)Nz	Doctest: )rar*)rfr+r+r,�shortDescription	szDocTestCase.shortDescription)r"NNN)r5rkrlr�rdrerhrfr!r�r�r�r�rPrjr+r+r+r,r\gs
	H
r\c@s0eZdZdd�Zdd�Zdd�Zdd�ZeZd	S)
�SkipDocTestCasecCs||_tj|d�dS)N)rBr\r�)rfrBr+r+r,r�	szSkipDocTestCase.__init__cCs|jd�dS)Nz-DocTestSuite will not work with -O2 and above)ZskipTest)rfr+r+r,rd	szSkipDocTestCase.setUpcCsdS)Nr+)rfr+r+r,�	test_skip	szSkipDocTestCase.test_skipcCsd|jjS)NzSkipping tests from %s)rBr5)rfr+r+r,rj	sz SkipDocTestCase.shortDescriptionN)r5rkrlr�rdrlrjrPr+r+r+r,rk	s
rkc@seZdZdd�ZdS)�
_DocTestSuitecCsdS)Nr+)rf�indexr+r+r,�_removeTestAtIndex	sz _DocTestSuite._removeTestAtIndexN)r5rkrlror+r+r+r,rm	srmc	Ks�|dkrt�}t|�}|j|||d�}|rPtjjdkrPt�}|jt|��|S|j	�t�}x\|D]T}t
|j�dkrxqd|js�|j
}|dd�dkr�|dd�}||_|jt|f|��qdW|S)	N)r0r�r3r"rVz.pycr&rrm)rrCrqr=r1�optimizerm�addTestrkr�r)r�rQr�r\)	rBr0r�Ztest_finderr�r��suiter�rQr+r+r,r	s(%
c@s(eZdZdd�Zdd�ZeZdd�ZdS)�DocFileCasecCsdj|jjjd��S)Nr=r})r�rar*ro)rfr+r+r,r�`	szDocFileCase.idcCs|jjS)N)rarQ)rfr+r+r,r�c	szDocFileCase.__repr__cCsd|jj|jj|fS)Nz2Failed doctest test for %s
  File "%s", line 0

%s)rar*rQ)rfrir+r+r,rfg	szDocFileCase.format_failureN)r5rkrlr�r�rPrfr+r+r+r,rs^	srsc
Ksx|dkri}n|j�}|r(|r(td��t||||p6d�\}}d|krN||d<tjj|�}|j||||d�}	t|	f|�S)Nz8Package may only be specified for module-relative paths.zutf-8r�r")r�r�rUrMr�rWr�rs)
r�rSrRr0r�rHr��docr*r�r+r+r,�DocFileTestl	s
rucOsHt�}|jdd�r$t|jd��|d<x|D]}|jt|f|��q*W|S)NrSTrR)rmr.rCrqru)�paths�kwrrr�r+r+r,r�	s8
cCs�g}x�t�j|�D]x}t|t�rj|j|jdd	��|j}|r�|jd�|dd�|jd�dd
�D�7}q|dd�|jd�dd�D�7}qWx|r�|ddkr�|j�q�Wx|r�|ddkr�|jd�q�Wdj	|�dS)
Nr&z# Expected:cSsg|]}d|�qS)z## r+)r�r�r+r+r,r�
sz(script_from_examples.<locals>.<listcomp>rGcSsg|]}t|��qSr+)r{)r�r�r+r+r,r�
srxr"rmrmrmrm)
rr�r8rr�r�rrro�popr�)rZr�Zpiecerrr+r+r,r�	s:

"csJt|�}t�j|�}�fdd�|D�}|s4t�d��|d}t|j�}|S)Ncsg|]}|j�kr|�qSr+)r*)r�r')r*r+r,r�*
sztestsource.<locals>.<listcomp>znot found in testsr")rCrrqr�rr�)rBr*r�r��testsrcr+)r*r,r!
s

cCst|�}t|||�dS)N)r�debug_script)�src�pmr0ryr+r+r,r 1
sc
Cs�ddl}|r|j�}ni}|rvyt|||�Wq�ttj�d�|jdd�}|j�|jdtj�d�Yq�Xn|jdd�j	d|||�dS)Nr"r&T)r�r3zexec(%r))
r�r�rr�r=rar�r5Zinteractionr?)r{r|r0r��pr+r+r,rz6
s
rzcCs$t|�}t||�}t|||j�dS)N)rCrrzr�)rBr*r|ryr+r+r,r!J
s
c@s$eZdZdd�Zdd�Zdd�ZdS)�
_TestClasscCs
||_dS)N)r�)rfr�r+r+r,r�f
sz_TestClass.__init__cCs|jd|_|S)Nr3)r�)rfr+r+r,�squarep
sz_TestClass.squarecCs|jS)N)r�)rfr+r+r,r.z
sz_TestClass.getN)r5rkrlr�rr.r+r+r+r,r~X
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 normalizationcCs tjdd�}|jdddddd�|jd	d
dtj�gdd
�|jddddd�|jdddd�|j�}|j}|j}d}x|jD]}|t|O}q|W|j	r�|t
O}x||D]t}|jd�r�tj
j|�\}}tj
jd|�t|dd��}tj
d=t|||d�\}	}
nt|d||d�\}	}
|	r�dSq�WdS)Nzdoctest runner)Zdescriptionz-vz	--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�r"z.pyrD)r�r)rSr�rr&���)�argparse�ArgumentParser�add_argumentr'�keys�
parse_argsr]r�r�Z	fail_fastrrerMr�ror=�insertr:rr)r�r�Z	testfilesr�r�r�rQ�dirnamer�rr=r+r+r,�_test�
s<



r�r�)r3)rV)	NNNNTr"NFF)FrYNr")NNNN)FN)FN)F)RZ
__docformat__�__all__r-r�rNr6r�rMr�rXr=r^r]�ior#�collectionsr$r%r'rrrrrrrrr	r
rrrr
rKrnr2rCrUr\rcrdrwr{r�r�r�rIrrrrrr�	ExceptionrrrrRrrrrZrr^r\rkZ	TestSuitermrrsrurrrr rzr!r~r�r�r5�exitr+r+r+r,�<module>0s


1%.DKl;;n
fx
$!
@IR


,		+