Your IP : 3.146.107.152


Current Path : /opt/alt/python35/lib64/python3.5/__pycache__/
Upload File :
Current File : //opt/alt/python35/lib64/python3.5/__pycache__/doctest.cpython-35.opt-2.pyc



���]d��!@s$dZddddddddd	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#d-d.d/�Z$d0d1�Z%d2d3d4�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#a9d#d#d#d#dLd"d#dMdMdNd�	Z:dLd#d#d#d#dLd"d#dMe1�d#dOd�Z;dMdPd#d"dQd�Z<d"a=dRd�Z>GdSdT�dTej?�Z@GdUdV�dVe@�ZAGdWdX�dXejB�ZCd#d#d#d#dYd�ZDGdZd[�d[e@�ZEdLd#d#e1�d#d\d]�ZFd^d�ZGd_d�ZHd`d�ZIdMd#dad �ZJdMd#dbdc�ZKdMddd!�ZLGdedf�df�ZMdfeMdgdhdidjdkdldmdndodpiZNdqdr�ZOePdskr e
jQeO��d#S)tzreStructuredText 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+�,/opt/alt/python35/lib64/python3.5/doctest.pyr�sz<BLANKLINE>z...cCsRd}xEtjD]:}|j|d�}|tt|�kr||jO}qW|S)Nr")�
__future__Zall_feature_names�get�getattrZ
compiler_flag)�globs�flagsZfnameZfeaturer+r+r,�_extract_future_flags�sr2�cCsutj|�r|St|t�r>t|t�t�dg�S|dkretjtj	|�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)�module�depthr+r+r,�_normalize_module�s
rDc	Cs�|r�t|d�}t||�}t|dd�dk	r�t|jd�r�|jj|�}|j|�}|jtj	d�|fSt
|d|��}|j�|fSWdQRXdS)N��
__loader__�get_data�
�encoding)rD�_module_relative_pathr/�hasattrrFrG�decode�replace�os�linesep�open�read)�filename�package�module_relativerIZ
file_contents�fr+r+r,�_load_testfile�srV�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_type�exc_val�exc_tbr+r+r,�_exception_traceback�s	rfc@s+eZdZdd�Zddd�ZdS)�	_SpoofOutcCs3tj|�}|r/|jd�r/|d7}|S)NrH)r#ra�endswith)�self�resultr+r+r,ra�s
z_SpoofOut.getvalueNcCs|j|�tj|�dS)N)�seekr#�truncate)ri�sizer+r+r,rls
z_SpoofOut.truncate)r5�
__module__�__qualname__rarlr+r+r+r,rg�s	rgcCst|kr||kS|jt�}dt|�}}|d}|rq|j|�rmt|�}|d=ndS|d}|r�|j|�r�|t|�8}|d=ndS||kr�dSxC|D];}|j|||�}|dkr�dS|t|�7}q�WdS)Nr"Fr&T���rp)�ELLIPSIS_MARKER�splitr)�
startswithrh�find)�want�gotZws�startpos�endpos�wr+r+r,�_ellipsis_matchs0





rzcCs"|j�}|rd|SdSdS)Nz# �#)�rstrip)�liner+r+r,�
_comment_line9sr~cCs�dt|�}}|jd�}|dkr4|}|jdd|�}|dkr[|}|jdd|�}|dkr�|d}|||�S)Nr"rH�:�.r&)r)rt�rfind)�msg�start�end�ir+r+r,�_strip_exception_detailsAs
r�c@sCeZdZdd�Zddd�Zdd�Zdd	�ZdS)
�_OutputRedirectingPdbcCs;||_d|_tjj|d|dd�d|_dS)NF�stdout�nosigintTr&)�_OutputRedirectingPdb__out�$_OutputRedirectingPdb__debugger_used�pdb�Pdb�__init__Zuse_rawinput)ri�outr+r+r,r�as		z_OutputRedirectingPdb.__init__NcCs;d|_|dkr$tj�j}tjj||�dS)NT)r�r=r?�f_backr�r��	set_trace)ri�framer+r+r,r�is	z_OutputRedirectingPdb.set_tracecCs|jrtjj|�dS)N)r�r�r��set_continue)rir+r+r,r�os	z"_OutputRedirectingPdb.set_continuecGs=tj}|jt_ztjj||�SWd|t_XdS)N)r=r�r�r�r��trace_dispatch)ri�args�save_stdoutr+r+r,r�us
	z$_OutputRedirectingPdb.trace_dispatch)r5rnror�r�r�r�r+r+r+r,r�[sr�cCs�tj|�std|��|jd�r:td��t|d�retjj|j	�d}nv|j
dkr�ttj
�dkr�tj
ddkr�tjjtj
d�d}q�tj}ntd|j
��tjj||jd��S)	NzExpected a module: %r�/z1Module-relative files may not have absolute paths�__file__r"�__main__�zBCan't resolve paths relative to the module %r (it has no __file__))r6r7rArs�
ValueErrorrKrN�pathrrr�r5r)r=�argv�curdir�join)rBr�Zbasedirr+r+r,rJ�s( 
rJc@s@eZdZdddddd�Zdd�Zdd�ZdS)	rNr"cCs�|jd�s|d7}|r9|jd�r9|d7}|dk	r_|jd�r_|d7}||_||_||_||_|dkr�i}||_||_dS)NrH)rh�sourceru�linenor\�options�exc_msg)rir�rur�r�r\r�r+r+r,r��s


					zExample.__init__cCs�t|�t|�k	rtS|j|jko�|j|jko�|j|jko�|j|jko�|j|jko�|j|jkS)N)�type�NotImplementedr�rur�r\r�r�)ri�otherr+r+r,�__eq__�szExample.__eq__cCs(t|j|j|j|j|jf�S)N)�hashr�rur�r\r�)rir+r+r,�__hash__�szExample.__hash__)r5rnror�r�r�r+r+r+r,r�s#	c@sLeZdZdd�Zdd�Zdd�Zdd�Zd	d
�ZdS)rcCs@||_||_|j�|_||_||_||_dS)N)�examples�	docstring�copyr0r*rRr�)rir�r0r*rRr�r�r+r+r,r�s				zDocTest.__init__cCsut|j�dkrd}n1t|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*rRr�)rir�r+r+r,�__repr__s			zDocTest.__repr__cCs�t|�t|�k	rtS|j|jko�|j|jko�|j|jko�|j|jko�|j|jko�|j|jkS)N)r�r�r�r�r0r*rRr�)rir�r+r+r,r�szDocTest.__eq__cCs"t|j|j|j|jf�S)N)r�r�r*rRr�)rir+r+r,r�%szDocTest.__hash__cCsSt|t�stS|j|j|jt|�f|j|j|jt|�fkS)N)r8rr�r*rRr��id)rir�r+r+r,�__lt__)szDocTest.__lt__N)r5rnror�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^[ ]*(#.*)?$z<string>c
sw|j�}|j|���dkrRdj�fdd�|jd�D��}g}d\}}x�|jj|�D]�}|j|||j���||jd||j��7}|j	|||�\}}}	}
|j
|�s'|jt||	|
d|d�t|j
d��d|��||jd|j�|j��7}|j�}qwW|j||d��|S)	Nr"rHcs g|]}|�d��qS)Nr+)�.0�l)�
min_indentr+r,�
<listcomp>ps	z'DocTestParser.parse.<locals>.<listcomp>r�r\r�)r"r")�
expandtabs�_min_indentr�rr�_EXAMPLE_RE�finditer�appendr��count�_parse_example�_IS_BLANK_OR_COMMENTrr)�groupr�)ri�stringr*�outputZcharnor��mr�r�rur�r+)r�r,�parseds&+!
%zDocTestParser.parsecCs%t|j||�|||||�S)N)r�get_examples)rir�r0r*rRr�r+r+r,�get_doctest�s	zDocTestParser.get_doctestcCsdd�|j||�D�S)NcSs%g|]}t|t�r|�qSr+)r8r)r��xr+r+r,r��s	z.DocTestParser.get_examples.<locals>.<listcomp>)r�)rir�r*r+r+r,r��szDocTestParser.get_examplesc
sut|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|�}|rJ|jd�}nd}|j	|||�}	||	||fS)Nr\r�rHr&rXr�cs$g|]}|�dd��qS)rWNr+)r��sl)r\r+r,r��s	z0DocTestParser._parse_example.<locals>.<listcomp>ruz *$cs g|]}|�d��qS)Nr+)r�Zwl)r\r+r,r��s	r�rprp)
r)r�rr�_check_prompt_blank�
_check_prefixr�rY�match�
_EXCEPTION_RE�
_find_options)
rir�r*r��source_linesr�ru�
want_linesr�r�r+)r\r,r��s$("("zDocTestParser._parse_examplez#\s*doctest:\s*([^\n\'"]*)$c	Cs�i}x�|jj|�D]�}|jd�jdd�j�}xy|D]q}|ddkss|dd�tkr�td|d||f��t|dd�}|ddk||<qGWqW|r�|j|�r�td|||f��|S)	Nr&�,rXr"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�rMrrr'r�r�)	rir�r*r�r�r��option_strings�option�flagr+r+r,r��s!
zDocTestParser._find_optionsz
^([ ]*)(?=\S)cCsCdd�|jj|�D�}t|�dkr;t|�SdSdS)NcSsg|]}t|��qSr+)r))r�r\r+r+r,r��s	z-DocTestParser._min_indent.<locals>.<listcomp>r")�
_INDENT_RE�findallr)�min)rir[�indentsr+r+r,r��s
zDocTestParser._min_indentc	Cs}xvt|�D]h\}}t|�|dkr
||ddkr
td||d||||d�|f��q
WdS)NrWrErXz8line %r of the docstring for %s lacks blank after %s: %rr&)�	enumerater)r�)ri�linesr\r*r�r�r}r+r+r,r�s
*z!DocTestParser._check_prompt_blankcCsXxQt|�D]C\}}|r
|j|�r
td||d||f��q
WdS)NzGline %r of the docstring for %s has inconsistent leading whitespace: %rr&)r�rsr�)rir��prefixr*r�r�r}r+r+r,r�szDocTestParser._check_prefixN)r5rnrorY�compile�	MULTILINE�VERBOSEr��DOTALLr�r�r�r�r�r�r�r�r�r�r�r�r�r+r+r+r,r4s 	'3	c@sseZdZde�dddd�Zdddddd�Zdd	�Zd
d�Zdd
�Zdd�Z	dS)rFTcCs(||_||_||_||_dS)N)�_parser�_verbose�_recurse�_exclude_empty)ri�verbose�parser�recurse�
exclude_emptyr+r+r,r�(s			zDocTestFinder.__init__Nc	Cs�|dkrCt|dd�}|dkrCtdt|�f��|dkrXd}n|dkrstj|�}ytj|�}Wntk
r�d}Yn�X|s�tj|�}|d|dd�dks�d}|dkr�d}n?|dk	rtj	||j
�}ntj	|�}|s.d}|dkra|dkrOi}qm|j
j�}n|j�}|dk	r�|j|�d|kr�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)	ri�objr*rBr0�
extraglobsr^r��testsr+r+r,rt>sJ$	
		


zDocTestFinder.findcCs|dkrdStj|�dk	r8|tj|�kStj|�rW|j|jkStj|�r�t|d�r�|jj}nt|d�r�|j}ndS|j	|kStj
|�r�|j	|jkSt|d�r�|j	|jkSt|t�rdSt
d��dS)NT�__objclass__rnz"object must be a class or function)r6r��
isfunctionr��__globals__ZismethoddescriptorrKr�rnr5�isclassr8�propertyr�)rirB�objectZobj_modr+r+r,�_from_module�s(
zDocTestFinder._from_modulec	Cs�|jrtd|�t|�|kr-dSd|t|�<|j|||||�}|dk	rq|j|�tj|�r|jrx�|jj	�D]t\}	}
d||	f}	tj
tj|
��s�tj|
�r�|j
||
�r�|j||
|	||||�q�Wtj|�r�|jr�x�t|di�j	�D]�\}	}
t|	t�svtdt|	�f��tj
|
�p�tj|
�p�tj|
�p�t|
t�s�tdt|
�f��d||	f}	|j||
|	||||�qBWtj|�r�|jr�x�|jj	�D]�\}	}
t|
t�rPt||	�}
t|
t�rqt||	�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�)rir�r�r*rBr�r0�seen�testZvalname�valr+r+r,r��sP	
%zDocTestFinder._findc	Cst|t�r|}nay@|jdkr3d}n$|j}t|t�sWt|�}Wnttfk
rxd}YnX|j||�}|jr�|r�dS|dkr�d}n;t|d|j�}|dd�dkr�|dd�}|j	j
|||||�S)Nr�r�rWz.pycr&���rp)r8r9�__doc__rA�AttributeError�_find_linenor�r/r5r�r�)	rir�r*rBr0r�r�r�rRr+r+r,r��s(				zDocTestFinder._get_testcCs{d}tj|�rd}tj|�r�|dkr:dStjdt|dd��}x0t|�D]"\}}|j|�rf|}PqfWtj|�r�|j	}tj
|�r�|j}tj|�r�|j
}tj|�r�|j}tj|�rt|dd�d}|dk	rw|dkr1|dStjd�}x4t|t|��D]}|j||�rV|SqVWdS)Nr"z^\s*class\s*%s\br5�-�co_firstlinenor&z(^|.*:)\s*\w*("|'))r6r7r�rYr�r/r�r�Zismethodr�r��__code__Zistraceback�tb_frameZisframe�f_codeZiscode�ranger))rir�r�r��patr�r}r+r+r,r$s<					zDocTestFinder._find_lineno)
r5rnrorr�rtr�r�r�rr+r+r+r,rs		f?%c@s�eZdZddZddddd�Zdd�Zd	d
�Zdd�Zd
d�Zdd�Z	dd�Z
dd�Zej
d�Zddd�Zddddd�Zddd�Zdd�ZdS)rr4�FNr"cCss|pt�|_|dkr-dtjk}||_||_||_d|_d|_i|_	t
�|_dS)Nz-vr")r�_checkerr=r�r��optionflags�original_optionflags�tries�failures�_name2ftrg�_fakeout)ri�checkerr�rr+r+r,r��s						zDocTestRunner.__init__cCs\|jrX|jr=|dt|j�dt|j��n|dt|j�d�dS)NzTrying:
zExpecting:
zExpecting nothing
)r�rur]r�)rir�r�exampler+r+r,�report_start�s		(zDocTestRunner.report_startcCs|jr|d�dS)Nzok
)r�)rir�rrrvr+r+r,�report_success�s	zDocTestRunner.report_successcCs3||j||�|jj|||j��dS)N)�_failure_headerr�output_differencer)rir�rrrvr+r+r,�report_failure�szDocTestRunner.report_failurecCs.||j||�dtt|���dS)NzException raised:
)rr]rf)rir�rrrbr+r+r,�report_unexpected_exception�sz)DocTestRunner.report_unexpected_exceptioncCs�|jg}|jrs|jdk	rJ|jdk	rJ|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:rH)�DIVIDERrRr�r�r*r�r]r�)rirrr�r�r�r+r+r,r�s		!
	zDocTestRunner._failure_headercCsHd}}|j}td�\}}}	|jj}
x�t|j�D]�\}}|jt@of|dk}
||_|jr�xE|jj�D]4\}}|r�|j|O_q�|j|M_q�W|jt	@r�qD|d7}|
s�|j
|||�d|j|f}y<tt
|j|d|d�|j�|jj�d}Wn5tk
r\�Yn!tj�}|jj�YnX|jj�}|jjd�|}|dkr�|
|j||j�rr|}n�tj|dd��d}|
s|t|�7}|jdkr|	}nX|
|j||j�r;|}n7|jt@rr|
t|j�t|�|j�rr|}||kr�|
s|j||||�nj||kr�|
s�|j ||||�|d7}n5||	kr|
s�|j!||||�|d7}n|rD|jt"@rDPqDW||_|j#|||�t$||�S)Nr"rEr&z<doctest %s[%d]>Zsingler3rp)%rrr�check_outputr�r�rr�r�rrr*�execr�r�r0�debuggerr��KeyboardInterruptr=rbrrarlrur_�format_exception_onlyrfr�rr�rrrr�_DocTestRunner__record_outcomer%)rir�compileflagsr�rrr�SUCCESS�FAILUREZBOOM�check�
examplenumr�quietZ
optionflagrrR�	exceptionrvZoutcomer�r+r+r,Z__run�s�
	
		




			
	

	zDocTestRunner.__runcCs^|jj|jd�\}}||||f|j|j<|j|7_|j|7_dS)Nr")r"r")rr.r*rr)rirrU�t�f2�t2r+r+r,Z__record_outcomelszDocTestRunner.__record_outcomez.<doctest (?P<name>.+)\[(?P<examplenum>\d+)\]>$cCsy|jj|�}|re|jd�|jjkre|jjt|jd��}|jjdd�S|j	||�SdS)Nr*r)�keependsT)
�%_DocTestRunner__LINECACHE_FILENAME_REr�r�rr*r��intr��
splitlines�save_linecache_getlines)rirR�module_globalsr�rr+r+r,Z__patched_linecache_getlinesys
!z*DocTestRunner.__patched_linecache_getlinesTc	su||_|dkr$t|j�}tj�|dkr��j��dks`�j�dkrl�j}n��fdd�}|jt_tj	�}t
j}t��|_
|j
j�|j
jt
_tj|_|jt_tj}tjt_z|j|||�SWd�t_|t
_tj|�|jt_|t_|rp|jj�ddl}d|_XdS)Nzutf-8cs,t|j�d���}�j|�dS)N�backslashreplace)r9�encode�write)r[)rIr�r+r,r��szDocTestRunner.run.<locals>.outr")rr2r0r=r�rI�lowerr7r�gettracer�r�r�r!�resetr�r�r3�*_DocTestRunner__patched_linecache_getlines�displayhook�__displayhook__�_DocTestRunner__run�settrace�clear�builtins�_)	rirr%r��clear_globsZ
save_traceZsave_set_traceZsave_displayhookrAr+)rIr�r,�run�s<				
			
	
zDocTestRunner.runc
Cs$|dkr|j}g}g}g}d}}x�|jj�D]w}|\}\}	}
||
7}||	7}|
dkr�|j|�qA|	dkr�|j||
f�qA|j|�qAW|rQ|rtt|�d�|j�x|D]}td|�q�W|rQtt|�d�|j�x(|D] \}}td||f�q-W|r�t|j�tt|�d�|j�x1|D])\}\}	}
td|	|
|f�q�W|r�t|dt|j�d	�t||d
|d�|rtd|d
�n|rtd�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%)
rir�ZnotestsZpassedZfailedZtotaltZtotalfr�r*rUr,�thingr�r+r+r,�	summarize�sP	








zDocTestRunner.summarizecCss|j}xc|jj�D]R\}\}}||kr[||\}}||}||}||f||<qWdS)N)rr�)rir��dr*rUr,r-r.r+r+r,�merges	"

zDocTestRunner.merge)r5rnrorr�rrrrrr>r$rYr�r0r;rDrFrHr+r+r+r,rXs:
$
}
I9c@s@eZdZdd�Zdd�Zdd�Zdd�Zd	S)
rcCst|jdd�d�S)N�ASCIIr5)r9r6)rir[r+r+r,�_toAsciiszOutputChecker._toAsciicCs|j|�}|j|�}||kr.dS|t@sd||fdkrNdS||fdkrddS|t@s�tjdtjt�d|�}tjdd|�}||kr�dS|t@r�d	j|j	��}d	j|j	��}||kr�dS|t
@rt||�rdSd
S)
NT�True
�1
�False
�0
z(?m)^%s\s*?$r�z
(?m)^\s*?$rXF)rKrL)rMrN)rJrrrYrZ�escape�BLANKLINE_MARKERrr�rrrrz)rirurvrr+r+r,rs0



zOutputChecker.check_outputcCsL|ttBtB@sdS|t@r$dS|jd�dkoK|jd�dkS)NFTrHr3)r	r
rr�)rirurvrr+r+r,�_do_a_fancy_diff]s
zOutputChecker._do_a_fancy_diffc
Cs�|j}|t@s(tjdt|�}|j|||�rQ|jdd�}|jdd�}|t@r�tj	||dd�}t
|�dd�}d}n�|t@r�tj||dd�}t
|�dd�}d}n@|t
@r#tjdtj�}	t
|	j||��}d	}nd
d�|D�}d|td
j|��S|rw|rwdt|�t|�fS|r�dt|�S|r�dt|�SdSdS)Nz(?m)^[ ]*(?=
)r/T�nr3z#unified diff with -expected +actualz-context diff with expected followed by actualZcharjunkzndiff with -expected +actualcSs g|]}|j�d�qS)rH)r|)r�r}r+r+r,r��s	z3OutputChecker.output_difference.<locals>.<listcomp>zDifferences (%s):
r�zExpected:
%sGot:
%szExpected:
%sGot nothing
zExpected nothing
Got:
%szExpected nothing
Got nothing
)rurrYrZrPrQr2r	�difflibZunified_diff�listr
Zcontext_diffrZDifferZIS_CHARACTER_JUNKZcomparer]r�)
rirrvrrur�Z	got_linesZdiff�kindZenginer+r+r,rts6	

	
	
	zOutputChecker.output_differenceN)r5rnrorJrrQrr+r+r+r,rs?c@s(eZdZdd�Zdd�ZdS)rcCs||_||_||_dS)N)rrrv)rirrrvr+r+r,r��s		zDocTestFailure.__init__cCs
t|j�S)N)r9r)rir+r+r,�__str__�szDocTestFailure.__str__N)r5rnror�rVr+r+r+r,r�sc@s(eZdZdd�Zdd�ZdS)rcCs||_||_||_dS)N)rrrb)rirrrbr+r+r,r��s		zUnexpectedException.__init__cCs
t|j�S)N)r9r)rir+r+r,rV�szUnexpectedException.__str__N)r5rnror�rVr+r+r+r,r�sc@s=eZdZddddd�Zdd�Zdd�ZdS)	rNTcCs2tj||||d�}|r.|jj�|S)NF)rrDr0r@)rirr%r�rC�rr+r+r,rD%s
zDebugRunner.runcCst|||��dS)N)r)rir�rrrbr+r+r,r+sz'DebugRunner.report_unexpected_exceptioncCst|||��dS)N)r)rir�rrrvr+r+r,r.szDebugRunner.report_failure)r5rnrorDrrr+r+r+r,r�s[TFc	Cs|dkrtjjd�}tj|�s@td|f��|dkrU|j}td|�}	|r�td|d|�}
nt	d|d|�}
x3|	j
||d|d|�D]}|
j|�q�W|r�|
j�t
dkr�|
a
n
t
j|
�t|
j|
j�S)Nr�ztestmod: module required; %rr�r�rr0r�)r=r>r.r6r7rAr5rrrrtrDrF�masterrHr%rr)r�r*r0r��reportrr��raise_on_errorr��finder�runnerrr+r+r,r:s$E	%
	
cCsH|r|rtd��t||||p.d�\}}|dkrXtjj|�}|dkrmi}n|j�}|dk	r�|j|�d|kr�d|d<|	r�td|d|�}
ntd|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�rr")r�rVrNr��basenamer�r�rrr�rDrFrXrHr%rr)rRrTr*rSr0r�rYrr�rZr�rI�textr\rr+r+r,r�s0R
	



	
ZNoNamec	Csdtd|dd�}td|d|�}x3|j||d|�D]}|j|d|�qCWdS)Nr�r�Frr0r%)rrrtrD)	rUr0r�r*r%rr[r\rr+r+r,rscCs/|t@|krtd|��t}|a|S)NzOnly reporting flags allowed)r
r��_unittest_reportflags)r1�oldr+r+r,r:s
c@s�eZdZdddddd�Zdd�Zdd�Zd	d
�Zdd�Zd
d�Zdd�Z	dd�Z
dd�Zdd�ZeZ
dd�ZdS)�DocTestCaser"NcCsAtjj|�||_||_||_||_||_dS)N)�unittest�TestCaser��_dt_optionflags�_dt_checker�_dt_test�	_dt_setUp�_dt_tearDown)rirr�setUp�tearDownrr+r+r,r�`s				zDocTestCase.__init__cCs)|j}|jdk	r%|j|�dS)N)rfrg)rirr+r+r,rijs	zDocTestCase.setUpcCs6|j}|jdk	r%|j|�|jj�dS)N)rfrhr0r@)rirr+r+r,rjps	
zDocTestCase.tearDowncCs�|j}tj}t�}|j}|t@s8|tO}td|d|jdd�}z5dd|_	|j
|d|jdd�\}}Wd|t_X|r�|j|j
|j����dS)	Nrrr�Frr
r�rC)rfr=r�r#rdr
r_rrerrDr7ZfailureException�format_failurera)rirr`�newrr\rrr+r+r,�runTestxs				


"
zDocTestCase.runTestcCsp|j}|jdkr!d}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

%srp)rfr�r�r*rrrR)ri�errrr�Zlnamer+r+r,rk�s		
%zDocTestCase.format_failurecCsO|j�td|jd|jdd�}|j|jdd�|j�dS)Nrrr�FrC)rirrdrerDrfrj)rir\r+r+r,r!�s
B
zDocTestCase.debugcCs
|jjS)N)rfr*)rir+r+r,r��szDocTestCase.idcCstt|�t|�k	rtS|j|jkos|j|jkos|j|jkos|j|jkos|j|jkS)N)r�r�rfrdrgrhre)rir�r+r+r,r��szDocTestCase.__eq__cCs"t|j|j|j|jf�S)N)r�rdrgrhre)rir+r+r,r��szDocTestCase.__hash__cCs:|jjjd�}d|ddj|dd��fS)Nr�z%s (%s)r&rprp)rfr*rrr�)rir*r+r+r,r��szDocTestCase.__repr__cCsd|jjS)Nz	Doctest: )rfr*)rir+r+r,�shortDescription�szDocTestCase.shortDescription)r5rnror�rirjrmrkr!r�r�r�r�rVror+r+r+r,ra^s		H
rac@sFeZdZdd�Zdd�Zdd�Zdd�ZeZd	S)
�SkipDocTestCasecCs||_tj|d�dS)N)rBrar�)rirBr+r+r,r��s	zSkipDocTestCase.__init__cCs|jd�dS)Nz-DocTestSuite will not work with -O2 and above)ZskipTest)rir+r+r,ri	szSkipDocTestCase.setUpcCsdS)Nr+)rir+r+r,�	test_skip	szSkipDocTestCase.test_skipcCsd|jjS)NzSkipping tests from %s)rBr5)rir+r+r,ro		sz SkipDocTestCase.shortDescriptionN)r5rnror�rirqrorVr+r+r+r,rp�s
rpc@seZdZdd�ZdS)�
_DocTestSuitecCsdS)Nr+)ri�indexr+r+r,�_removeTestAtIndex	sz _DocTestSuite._removeTestAtIndexN)r5rnrortr+r+r+r,rr	srrc	Ks|dkrt�}t|�}|j|d|d|�}|rutjjdkrut�}|jt|��|S|j	�t�}x}|D]u}t
|j�dkr�q�|js�|j
}|dd�dkr�|dd	�}||_|jt||��q�W|S)
Nr0r�r3r"rWz.pycr&rrp)rrDrtr=r1�optimizerr�addTestrpr�r)r�rRr�ra)	rBr0r�Ztest_finderr�r��suiterrRr+r+r,r	s(%		
	
			c@s:eZdZdd�Zdd�ZeZdd�ZdS)�DocFileCasecCsdj|jjjd��S)NrBr�)r�rfr*rr)rir+r+r,r�W	szDocFileCase.idcCs
|jjS)N)rfrR)rir+r+r,r�Z	szDocFileCase.__repr__cCsd|jj|jj|fS)Nz2Failed doctest test for %s
  File "%s", line 0

%s)rfr*rR)rirnr+r+r,rk^	szDocFileCase.format_failureN)r5rnror�r�rVrkr+r+r+r,rxU	srxc
Ks�|dkri}n|j�}|r:|r:td��t||||pOd�\}}d|krq||d<tjj|�}|j||||d�}	t|	|�S)Nz8Package may only be specified for module-relative paths.zutf-8r�r")r�r�rVrNr�r]r�rx)
r�rTrSr0r�rIr��docr*rr+r+r,�DocFileTestc	s	

rzcOs_t�}|jdd�r4t|jd��|d<x$|D]}|jt||��q;W|S)NrTTrS)rrr.rDrvrz)�paths�kwrwr�r+r+r,r}	s8	
cCs!g}x�t�j|�D]�}t|t�r�|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�	
s	z(script_from_examples.<locals>.<listcomp>rHcSsg|]}t|��qSr+)r~)r�r�r+r+r,r�
s	r{r"rprprprp)
rr�r8rr�r�rurr�popr�)r[r�Zpiecerur+r+r,r�	s:	
-"csit|�}t�j|�}�fdd�|D�}|sLt�d��|d}t|j�}|S)Ncs%g|]}|j�kr|�qSr+)r*)r�r,)r*r+r,r�!
s	ztestsource.<locals>.<listcomp>znot found in testsr")rDrrtr�rr�)rBr*r�r�testsrcr+)r*r,r
s
cCs t|�}t|||�dS)N)r�debug_script)�src�pmr0r~r+r+r,r (
sc
Cs�ddl}|r!|j�}ni}|r�yt|||�Wq�ttj�d�|jdd�}|j�|jdtj�d�Yq�Xn#|jdd�j	d|||�dS)Nr"r&r�Tr3zexec(%r))
r�r�r r�r=rbr�r:ZinteractionrD)r�r�r0r��pr+r+r,r-
s
"rcCs2t|�}t||�}t|||j�dS)N)rDrrr�)rBr*r�r~r+r+r,r!A
sc@s4eZdZdd�Zdd�Zdd�ZdS)�
_TestClasscCs
||_dS)N)r)rirr+r+r,r�]
sz_TestClass.__init__cCs|jd|_|S)Nr3)r)rir+r+r,�squareg
sz_TestClass.squarecCs|jS)N)r)rir+r+r,r.q
sz_TestClass.getN)r5rnror�r�r.r+r+r+r,r�O
s

r�r�z�
                      Example of a string object, searched as-is.
                      >>> x = 1; y = 2
                      >>> x + y, x * y
                      (3, 2)
                      zbool-int equivalencea�
                                    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
                                    zblank linesz�
                Blank lines can be marked with <BLANKLINE>:
                    >>> print('foo\n\nbar\n')
                    foo
                    <BLANKLINE>
                    bar
                    <BLANKLINE>
            Zellipsisz�
                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]
            zwhitespace normalizationa�
                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]
            cCs�tjdd�}|jddddddd	d
�|jdddd
dtj�dgd	d�|jddddd	d�|jdddd	d�|j�}|j}|j}d}x|jD]}|t|O}q�W|j	r�|t
O}x�|D]�}|jd�rxtj
j|�\}}tj
jd|�t|dd��}tj
d=t|d|d|�\}	}
n$t|ddd|d|�\}	}
|	r�dSq�WdS)N�descriptionzdoctest runnerz-vz	--verbose�action�
store_true�defaultF�helpz'print very verbose output for all testsz-oz--optionr��choiceszqspecify a doctest option flag to apply to the test run; may be specified more than once to apply multiple optionsz-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^�nargsr�z file containing the tests to runr"z.pyrEr�rrTr&���)�argparse�ArgumentParser�add_argumentr'�keys�
parse_argsr^r�r�Z	fail_fastrrhrNr�rrr=�insertr:rr)r�r�Z	testfilesr�r�r�rR�dirnamer�rrBr+r+r,�_test�
s<			


!r�r�)RZ
__docformat__�__all__r-r�rSr6r�rNr�rYr=r_rb�ior#�collectionsr$r%r'rrrrrrrrr	r
rrrr
rPrqr2rDrVr]rfrgrzr~r�r�r�rJrrrrrr�	ExceptionrrrrXrrrr_rrcrarpZ	TestSuiterrrrxrzrrrr rr!r�r�r�r5�exitr+r+r+r,�<module>0s	1%%DK��:���n	f	x$�@	IR,	+

?>