a �DOgx�� @s2dZgd�ZddlZddlZddlZddlZddlZddlZddlZddl Z ddl Z ddl Z ddl 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�df dGdH�Z;dtdJdK�ZGdNdO�dOe j?�Z@GdPdQ�dQe@�ZAGdRdS�dSe jB�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,�/usr/lib64/python3.9/doctest.pyr�srrrrrrrr r r r rz z...cCs8d}tjD](}|�|d�}|tt|�ur ||jO}q |S)Nr")� __future__Zall_feature_names�get�getattrZ compiler_flag)�globs�flags�fnameZfeaturer,r,r-�_extract_future_flags�s    r4�cCsVt�|�r|St|t�r,t|t�t�dg�S|durJtjt� |�j dSt d��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  rFcCsdD]}|�|d�}q|S)N)z � � )�replace)�data�newliner,r,r-�_newline_convert�srLcCs�|rVt|d�}t||�}t|dd�durVt|jd�rV|j�|�}|�|�}t|�|fSt||d��}|� �|fWd�S1s�0YdS)N�� __loader__�get_data)�encoding) rF�_module_relative_pathr0�hasattrrNrO�decoderL�open�read)�filename�package�module_relativerPZ file_contents�fr,r,r-�_load_testfile�s      rZ�cCst�d|d|�S)Nz (?m)^(?!$)� )�re�sub)�s�indentr,r,r-�_indent�sracCs*t�}|\}}}tj||||d�|��S)N)�file)r#� traceback�print_exception�getvalue)�exc_infoZexcout�exc_type�exc_val�exc_tbr,r,r-�_exception_traceback�s rjc@seZdZdd�Zddd�ZdS)� _SpoofOutcCs$t�|�}|r |�d�s |d7}|S�NrH)r#re�endswith)�self�resultr,r,r-res z_SpoofOut.getvalueNcCs|�|�t�|�dS�N)�seekr#�truncate)rn�sizer,r,r-rr s z_SpoofOut.truncate)N)r7� __module__� __qualname__rerrr,r,r,r-rk�s rkcCs�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)� startswithrm�find)�want�got�ws�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"rH�:�.r&)r)rz�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)rn�outr,r,r-r�gsz_OutputRedirectingPdb.__init__NcCs*d|_|durt��j}tj�||�dS)NT)r�r?rA�f_backr�r�� set_trace)rn�framer,r,r-r�os z_OutputRedirectingPdb.set_tracecCs|jrtj�|�dSrp)r�r�r�� set_continue�rnr,r,r-r�usz"_OutputRedirectingPdb.set_continuecGs8tj}|jt_ztjj|g|�R�W|t_S|t_0dSrp)r?r�r�r�r��trace_dispatch)rn�args� save_stdoutr,r,r-r�{s�z$_OutputRedirectingPdb.trace_dispatch)N)r7rtrur�r�r�r�r,r,r,r-r�as r�cCs�t�|�std|��|�d�r(td��tjj|�d��}t |d�rXtj�|j �d}n�|j dkr�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__))r8r9rCry� ValueError�os�path�joinrxrRr�r7r)r?�argv�curdirr��exists)rDZ test_pathZbasedirZ directory�fullpathr,r,r-rQ�s(         �rQc@s&eZdZd dd�Zdd�Zdd�ZdS) rNr"cCsv|�d�s|d7}|r(|�d�s(|d7}|durB|�d�sB|d7}||_||_||_||_|durfi}||_||_dSrl)rm�sourcer{�linenor`�options�exc_msg)rnr�r{r�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|jkSrp)�type�NotImplementedr�r{r�r`r�r��rn�otherr,r,r-�__eq__�s  � � � � �zExample.__eq__cCst|j|j|j|j|jf�Srp)�hashr�r{r�r`r�r�r,r,r-�__hash__�s�zExample.__hash__)Nr"r"N)r7rtrur�r�r�r,r,r,r-r�s #�  rc@s4eZdZdd�Zdd�Zdd�Zdd�Zd d �Zd S) rcCs,||_||_|��|_||_||_||_dSrp)�examples� docstring�copyr1r+rVr�)rnr�r1r+rVr�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"z no examplesr&z 1 examplez %d examplesz<%s %s from %s:%s (%s)>)r)r�� __class__r7r+rVr�)rnr�r,r,r-�__repr__s��zDocTest.__repr__cCs\t|�t|�urtS|j|jkoZ|j|jkoZ|j|jkoZ|j|jkoZ|j|jkoZ|j|jkSrp)r�r�r�r�r1r+rVr�r�r,r,r-r�)s  � � � � �zDocTest.__eq__cCst|j|j|j|jf�Srp)r�r�r+rVr�r�r,r,r-r�4szDocTest.__hash__cCs:t|t�stS|j|j|jt|�f|j|j|jt|�fkSrp)r:rr�r+rVr��idr�r,r,r-�__lt__8s  �zDocTest.__lt__N)r7rtrur�r�r�r�r�r,r,r,r-r�s   rc@s�eZdZe�dejejB�Ze�dejejBejB�Z e�d�j Z ddd�Z dd�Z dd d �Zd d �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 (?:^(?P [ ]*) >>> .*) # PS1 line (?:\n [ ]* \.\.\. .*)*) # PS2 lines \n? # Want consists of any non-blank lines that do not start with PS1. (?P (?:(?![ ]*$) # 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 Traceback\ \( (?: most\ recent\ call\ last | innermost\ last ) \) : ) \s* $ # toss trailing whitespace on the header. (?P .*?) # don't blink: absorb stuff until... ^ (?P \w+ .*) # a line *starts* with alphanum. z ^[ ]*(#.*)?$�c s|��}|�|���dkr8d��fdd�|�d�D��}g}d\}}|j�|�D]�}|�|||����||�d||���7}|� |||�\}}} } |� |�s�|�t || | |�t |� d��|d��||�d|��|���7}|��}qP|�||d��|S)Nr"rHcsg|]}|�d��qSrpr,��.0�l�Z min_indentr,r-� �z'DocTestParser.parse..�r"r"r`)r�r`r�)� expandtabs� _min_indentr�rx� _EXAMPLE_RE�finditer�appendr��count�_parse_example�_IS_BLANK_OR_COMMENTrr)�groupr�) rn�stringr+�outputZcharnor��mr�r�r{r�r,r�r-�parsess*  �   � zDocTestParser.parsecCst|�||�|||||�Srp)r� get_examples)rnr�r1r+rVr�r,r,r-� get_doctest�s �zDocTestParser.get_doctestcCsdd�|�||�D�S)NcSsg|]}t|t�r|�qSr,)r:r)r��xr,r,r-r��s �z.DocTestParser.get_examples..)r�)rnr�r+r,r,r-r��s zDocTestParser.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�rHr&r\r�csg|]}|�dd��qS)r[Nr,)r��sl�r`r,r-r��r�z0DocTestParser._parse_example..r{z *$rvcsg|]}|�d��qSrpr,)r�Zwlr�r,r-r��r�r�) r)r�rx�_check_prompt_blank� _check_prefixr�r]�match� _EXCEPTION_RE� _find_options) rnr�r+r�� source_linesr�r{� 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&�,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�rIrxr'r�r�) rnr�r+r�r�r��option_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..r")� _INDENT_RE�findallr)�min)rnr_�indentsr,r,r-r�s zDocTestParser._min_indentc Cs^t|�D]P\}}t|�|dkr||ddkrtd||d||||d�|f��qdS)Nr[rMr\z8line %r of the docstring for %s lacks blank after %s: %rr&)� enumerater)r�)rn�linesr`r+r�r�r�r,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�ryr�)rnr��prefixr+r�r�r�r,r,r-r�s �zDocTestParser._check_prefixN)r�)r�)r7rtrur]�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||_||_||_||_dSrp)�_parser�_verbose�_recurse�_exclude_empty)rn�verbose�parser�recurse� exclude_emptyr,r,r-r�7szDocTestFinder.__init__Nc CsL|dur.t|dd�}|dur.tdt|�f��|durr�)r0r�r�r8� getmoduleZ getsourcefilerCZgetfile� linecache�getlines�__dict__r��update�_find�sort) rn�objr+rDr1� extraglobsrbr��testsr,r,r-rzMsJ$ �         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__rtz"object must be a class or function)r8r�� isfunctionr�� __globals__ZismethoddescriptorrRrrtr7�isclassr:�propertyr�)rnrD�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�r8r9r�r��itemsZ isroutine�unwraprr r�r0r:r;r�r�� staticmethod� classmethod�__func__r) rnrrr+rDr�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�������.pycrv) r:r;�__doc__rC�AttributeError� _find_linenor�r0r7r�r�) rnrr+rDr1r�r�r�rVr,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\br7�-�co_firstlinenor&z(^|.*:)\s*\w*("|\'))r8r9rr]r�r0r�r�Zismethodrr�__code__Z istraceback�tb_frameZisframe�f_codeZiscode�ranger))rnrr�r��patr�r�r,r,r-r2s6   �     zDocTestFinder._find_lineno)NNNN) r7rtrurr�rzr r�r rr,r,r,r-r.s �  f=&rc@s�eZdZdZddd�Zdd�Zdd �Zd d �Zd d �Zdd�Z dd�Z dd�Z e � 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�_name2ftrk�_fakeout)rn�checkerr�r#r,r,r-r��s  zDocTestRunner.__init__cCsH|jrD|jr.|dt|j�dt|j��n|dt|j�d�dS)NzTrying: z Expecting: zExpecting nothing )r�r{rar�)rnr�r�exampler,r,r-� report_start�s���zDocTestRunner.report_startcCs|jr|d�dS)Nzok )r��rnr�rr*r|r,r,r-�report_success�szDocTestRunner.report_successcCs&||�||�|j�|||j��dSrp)�_failure_headerr"�output_differencer#r,r,r,r-�report_failure�s �zDocTestRunner.report_failurecCs$||�||�dtt|���dS)NzException raised: )r.rarj�rnr�rr*rfr,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:rH)�DIVIDERrVr�r�r+r�rar�)rnrr*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"rMr&zZsingleTr5rv)%r#rr"� check_outputr�r�r r�r rr+r+�execr�r�r1�debuggerr��KeyboardInterruptr?rfr(rerrr{rc�format_exception_onlyrjr�rr�r-r0r2r�_DocTestRunner__record_outcomer%)rnr� compileflagsr�r&r%r$�SUCCESS�FAILUREZBOOM�check� examplenumr*�quietZ optionflagrrV� exceptionr|�outcomer�r,r,r-Z__run�s�  �  ��        �     � zDocTestRunner.__runcCsL|j�|jd�\}}||||f|j|j<|j|7_|j|7_dS)Nr�)r'r/r+r&r%)rnrrY�t�f2�t2r,r,r-Z__record_outcomezszDocTestRunner.__record_outcomez..+)\[(?P\d+)\]>$cCsV|j�|�}|rF|�d�|jjkrF|jjt|�d��}|jjdd�S|� ||�SdS)Nr+r?T��keepends) �%_DocTestRunner__LINECACHE_FILENAME_REr�r�rr+r��intr�� splitlines�save_linecache_getlines)rnrV�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 j t _ 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_�rPr�r,r-r��szDocTestRunner.run..outr")rr4r1r?r�rP�lowerrPr(�gettracer�r�r�r7�resetr�r�rK�*_DocTestRunner__patched_linecache_getlines� displayhook�__displayhook__�_DocTestRunner__run�settrace�clear�builtins�_) rnrr;r�� clear_globsZ save_traceZsave_set_traceZsave_displayhookr[r,rQr-�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�r'r r�r r)r�r4r%) rnr�ZnotestsZpassedZfailedZtotaltZtotalfr�r+rYrC�thingr�r,r,r-� summarize�sP       zDocTestRunner.summarizecCsR|j}|j��D]<\}\}}||vr@||\}}||}||}||f||<qdSrp)r'r )rnr��dr+rYrCrDrEr,r,r-�merges zDocTestRunner.merge)NNr")N)NNT)N)r7rtrur4r�r+r-r0r2r.rXr:r]r�rHrUr^r`rbr,r,r,r-rfs: $ }   I 9rc@s,eZdZdd�Zdd�Zdd�Zdd�Zd S) rcCst|�dd�d�S)N�ASCIIrN)r;rO)rnr_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]+$r\F) rdrrr]r^�escape�BLANKLINE_MARKERrr�rxrr��rnr{r|r#r,r,r-r5,s2    � zOutputChecker.check_outputcCs<|ttBtB@sdS|t@r dS|�d�dko:|�d�dkS)NFTrHr5)r r r r�rgr,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)^[ ]*(?= )TrFr5)�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 )r{rr]r^rfrhrJr �difflibZ unified_diff�listr Z context_diffr ZDifferZIS_CHARACTER_JUNKZcomparerar�) rnr*r|r#r{r�Z got_lines�diff�kindZenginer,r,r-r/�s4    zOutputChecker.output_differenceN)r7rtrurdr5rhr/r,r,r,r-rs?rc@seZdZdd�Zdd�ZdS)rcCs||_||_||_dSrp)rr*r|)rnrr*r|r,r,r-r��szDocTestFailure.__init__cCs t|j�Srp�r;rr�r,r,r-�__str__�szDocTestFailure.__str__N�r7rtrur�ror,r,r,r-r�s rc@seZdZdd�Zdd�ZdS)rcCs||_||_||_dSrp)rr*rf)rnrr*rfr,r,r-r��szUnexpectedException.__init__cCs t|j�Srprnr�r,r,r-ro�szUnexpectedException.__str__Nrpr,r,r,r-r�s rc@s&eZdZd dd�Zdd�Zdd�ZdS) rNTcCs$t�||||d�}|r |j��|S)NF)rr^r1rZ)rnrr;r�r]�rr,r,r-r^1s zDebugRunner.runcCst|||��dSrp)rr1r,r,r-r27sz'DebugRunner.report_unexpected_exceptioncCst|||��dSrp)rr,r,r,r-r0:szDebugRunner.report_failure)NNT)r7rtrur^r2r0r,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/r8r9rCr7rrrrzr^r`�masterrbr%r&r%) r�r+r1r��reportr#r�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.rMr7r�rrr")r�rZr�r��basenamer�r�rrr�r^r`rtrbr%r&r%)rVrXr+rWr1r�rur#rrvr�rP�textrxrr,r,r-r�s2R�     r�NoNamec Cs@t|dd�}t||d�}|j|||d�D]}|j||d�q(dS)NF)r�r�rr)r1)r;)rrrzr^) rYr1r�r+r;r#rwrxrr,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 �Zd d �Zd d�Zdd�Z dd�Z dd�Z dd�Z e jZdd�ZdS)� DocTestCaser"NcCs:tj�|�||_||_|j��|_||_||_ ||_ dSrp) �unittest�TestCaser��_dt_optionflags� _dt_checkerr1r�� _dt_globs�_dt_test� _dt_setUp� _dt_tearDown)rnrr#�setUp�tearDownr)r,r,r-r�ls  zDocTestCase.__init__cCs|j}|jdur|�|�dSrp)r�r��rnrr,r,r-r�ws zDocTestCase.setUpcCs6|j}|jdur|�|�|j��|j�|j�dSrp)r�r�r1rZr�r�r�r,r,r-r�}s    zDocTestCase.tearDowncCs�|j}tj}t�}|j}|t@s(|tO}t||jdd�}z&d|_ |j ||j dd�\}}W|t_n|t_0|r�|� |� |�����dS)NF�r#r)r�zF----------------------------------------------------------------------)r�r])r�r?r�r#r�r r}rr�r4r^rPZfailureException�format_failurere)rnrr~�newr#rxr&r%r,r,r-�runTest�s"�� zDocTestCase.runTestcCsP|j}|jdurd}n d|j}d�|j�d�dd��}d|j|j|||fS)Nzunknown line numberz%sr�rvz:Failed doctest test for %s File "%s", line %s, in %s %s)r�r�r�r+rxrV)rn�errrr�Zlnamer,r,r-r��s  �zDocTestCase.format_failurecCs6|��t|j|jdd�}|j|jdd�|��dS)NFr�)r])r�rr�r�r^r�r�)rnrxr,r,r-r!�s B�zDocTestCase.debugcCs|jjSrp�r�r+r�r,r,r-r��szDocTestCase.idcCsPt|�t|�urtS|j|jkoN|j|jkoN|j|jkoN|j|jkoN|j|jkSrp)r�r�r�r�r�r�r�r�r,r,r-r��s  � � � �zDocTestCase.__eq__cCst|j|j|j|jf�Srp)r�r�r�r�r�r�r,r,r-r� s�zDocTestCase.__hash__cCs,|jj�d�}d|dd�|dd��fS)Nr�z%s (%s)rv)r�r+rxr�)rnr+r,r,r-r� szDocTestCase.__repr__cCs d|jjS)Nz Doctest: r�r�r,r,r-�shortDescription szDocTestCase.shortDescription)r"NNN)r7rtrur�r�r�r�r�r!r�r�r�r�rror�r,r,r,r-rjs�   H rc@s0eZdZdd�Zdd�Zdd�Zdd�ZeZd S) �SkipDocTestCasecCs||_t�|d�dSrp)rDrr�)rnrDr,r,r-r� szSkipDocTestCase.__init__cCs|�d�dS)Nz-DocTestSuite will not work with -O2 and above)ZskipTestr�r,r,r-r� szSkipDocTestCase.setUpcCsdSrpr,r�r,r,r-� test_skip szSkipDocTestCase.test_skipcCs d|jjS)NzSkipping tests from %s)rDr7r�r,r,r-r� sz SkipDocTestCase.shortDescriptionN)r7rtrur�r�r�r�ror,r,r,r-r� s r�c@seZdZdd�ZdS)� _DocTestSuitecCsdSrpr,)rn�indexr,r,r-�_removeTestAtIndex sz _DocTestSuite._removeTestAtIndexN)r7rtrur�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)Nrsr5r"rrrv)rrFrzr?r2�optimizer��addTestr�r�r)r�rVr�r) rDr1rZ test_finderr�r�suiterrVr,r,r-r$ s(% rc@s$eZdZdd�Zdd�Zdd�ZdS)� DocFileCasecCsd�|jj�d��S)Nr\r�)r�r�r+rxr�r,r,r-r�f szDocFileCase.idcCs|jjSrp)r�rVr�r,r,r-r�i szDocFileCase.__repr__cCsd|jj|jj|fS)Nz2Failed doctest test for %s File "%s", line 0 %s)r�r+rV)rnr�r,r,r-r�l s�zDocFileCase.format_failureN)r7rtrur�r�r�r,r,r,r-r�d sr�c Ksz|duri}n|��}|r&|s&td��t||||p4d�\}}d|vrL||d<tj�|�}|�||||d�} t| fi|��S)NryrMr�r")r�r�rZr�r�rzr�r�) r�rXrWr1r�rPr��docr+rr,r,r-� DocFileTestq s� r�cOsHt�}|�dd�r$t|�d��|d<|D]}|�t|fi|���q(|S)NrXTrW)r�r/rFr�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) Nrvz # Expected:cSsg|] }d|�qS)z## r,r�r,r,r-r� r�z(script_from_examples..rHcSsg|] }t|��qSr,)r�r�r,r,r-r� s�r�r") rr�r:rr�r�r{rx�popr�)r_r�Zpiecer{r,r,r-r� s :  "�   rcsJt|�}t��|�}�fdd�|D�}|s4t�d��|d}t|j�}|S)Ncsg|]}|j�kr|�qSr,r*)r�rCr*r,r-r�/ r�ztestsource..znot found in testsr")rFrrzr�rr�)rDr+rr�testsrcr,r*r-r& s   rcCst|�}t|||�dSrp)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�r5zexec(%r)) r�r�r6r r?rfr�rTZ interactionr^)r�r�r1r��pr,r,r-r�; s  r�cCs$t|�}t||�}t|||j�dSrp)rFrr�r�)rDr+r�r�r,r,r-r!O s r!c@s$eZdZdd�Zdd�Zdd�ZdS)� _TestClasscCs ||_dSrp�r)rnrr,r,r-r�k sz_TestClass.__init__cCs|jd|_|S)Nr5r�r�r,r,r-�squareu s z_TestClass.squarecCs|jSrpr�r�r,r,r-r/ sz_TestClass.getN)r7rtrur�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 : >>> print('foo\n\nbar\n') foo bar 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 equivalencez blank linesZellipsiszwhitespace normalizationc Cs"ddl}|jdd�}|jdddddd �|jd d d 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)� 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�rbr�z file containing the tests to run)�nargsr�z.py�����rr)rXr�r#r&)�argparse�ArgumentParser� add_argumentr'�keys� parse_argsrbr�r�Z fail_fastrrmr�r�rxr?�insertr<rr) r�r�r�Z testfilesr�r�r�rV�dirnamer�r&r\r,r,r-�_test� sH  � � ��  � r�r�)r5)r[) NNNNTr"NFF)Fr|Nr")NNNN)FN)FN)F)RZ __docformat__�__all__r.rjr8r�r�r�r]r?rcr��ior#� collectionsr$r%r'rrrrrrrrr r r r rr rfrwr4rFrLrZrarjrkr�r�r�r�r�rQrrrrrr� Exceptionrrrrtrrrr}rr�rr�Z TestSuiter�rr�r�rrrr r�r!r�r r�r7�exitr,r,r,r-�0s�-   ���������   1%.DKl:;n� h� {� $$ @ � IR   , �3-