a
    ˆÏ?eÝh  ã                   @   s  U d Z ddlZddlZddlZddlZddlZddlZddlZddlZddl	Z	ddl
mZ ddlmZ ddlmZ ddlmZ ddlmZ ddlmZ dd	lmZ dd
lmZ ddlmZ ddlmZ ddlmZ ddlmZ ddlmZ ddlmZ ddlmZ ddlmZ ddlmZ ddlm Z  ddlm!Z! ddl"m#Z# ddl$m%Z% ddl&m'Z' ddl(m)Z) ddl*m+Z+ ddl*m,Z, ddl-m.Z. ddl-m/Z/ ddl0m1Z1 ddl0m2Z2 dd l3m4Z4 dd!l3m5Z5 dd"l6m7Z7 dd#l8m9Z9 dd$l:m;Z; e�rôddl<Z<d%Z=d&Z>d'Z?d(Z@d)ZAe=e>e?e@eAfZBdaCdaDeed*  eEd+< e)dd,œd-d.„ZFdd/œd0d1„ZGee.eed2  d3œd4d5„ZHeeId6œd7d8„ZJe'ee.eId9œd:d;„ZKeeId6œd<d=„ZLG d>d?„ d?e!ƒZMG d@dA„ dAeNƒZOedB d/œdCdD„ZPdsed* eeI eQeIdBdFœdGdH„ZRG dIdJ„ dJe/ƒZSeeTeQf d/œdKdL„ZUdMdN„ ZVdOdP„ ZWG dQdR„ dRe7ƒZXdSddTœdUdV„ZYeZeIdWœdXdY„Z[eedZ d/œd[d\„ƒZ\G d]d^„ d^e7ƒZ]eSe,d_œd`da„Z^ed* d/œdbdc„Z_d*d/œddde„Z`eQd/œdfdg„ZaeQd/œdhdi„ZbeQd/œdjdk„ZceTeQdlœdmdn„Zde+dodp�eeTef d/œdqdr„ƒZedS )tz4Discover and run doctests in modules and test files.é    N)Úcontextmanager)ÚPath)ÚAny)ÚCallable)ÚDict)Ú	Generator)ÚIterable)ÚList)ÚOptional)ÚPattern)ÚSequence)ÚTuple)ÚType)ÚTYPE_CHECKING)ÚUnion)Úoutcomes)ÚExceptionInfo)ÚReprFileLocation)ÚTerminalRepr)ÚTerminalWriter©Úsafe_getattr)ÚConfig)ÚParser)Úfixture)ÚFixtureRequest)Ú	Collector)ÚItem)ÚOutcomeException)Úskip©Ú
fnmatch_ex)Úimport_path)ÚModule)Úapprox)ÚPytestWarningÚnoneZcdiffZndiffÚudiffZonly_first_failureúdoctest.OutputCheckerÚCHECKER_CLASS)ÚparserÚreturnc                 C   sœ   | j ddddgd� | j dddd	� |  d
¡}|jdddddd� |jdtjddtdd� |jddg dddd� |jdddddd� |jdddd d!d� d S )"NÚdoctest_optionflagszOption flags for doctestsÚargsÚELLIPSIS)ÚtypeÚdefaultÚdoctest_encodingzEncoding used for doctest fileszutf-8)r0   Úcollectz--doctest-modulesÚ
store_trueFzRun doctests in all .py modulesÚdoctestmodules)Úactionr0   ÚhelpÚdestz--doctest-reportr'   z9Choose another output format for diffs on doctest failureÚdoctestreport)r/   r0   r6   Úchoicesr7   z--doctest-globÚappendÚpatz2Doctests file matching pattern, default: test*.txtÚdoctestglob)r5   r0   Úmetavarr6   r7   z--doctest-ignore-import-errorszIgnore doctest ImportErrorsÚdoctest_ignore_import_errorsz--doctest-continue-on-failurez<For a given doctest, continue to run after the first failureÚdoctest_continue_on_failure)ZaddiniZgetgroupZ	addoptionÚstrÚlowerÚDOCTEST_REPORT_CHOICES)r*   Úgroup© rD   úR/home/yuhw/wc/wire-cell-python/wcpy/lib/python3.9/site-packages/_pytest/doctest.pyÚpytest_addoptionF   s^    üÿ
ûúúûûrF   ©r+   c                   C   s   d a d S ©N)ÚRUNNER_CLASSrD   rD   rD   rE   Úpytest_unconfigurex   s    rJ   )ÚDoctestModuleÚDoctestTextfile)Ú	file_pathÚparentr+   c                 C   sb   |j }| jdkr@|jjr^tt| ƒt| ƒfƒs^tj|| d�}|S nt	|| |ƒr^t
j|| d�}|S d S )Nz.py©Úpath)ÚconfigÚsuffixÚoptionr4   ÚanyÚ_is_setup_pyÚ_is_main_pyrK   Úfrom_parentÚ_is_doctestrL   )rM   rN   rQ   ÚmodÚtxtrD   rD   rE   Úpytest_collect_file~   s    

ÿr[   )rP   r+   c                 C   s&   | j dkrdS |  ¡ }d|v p$d|v S )Nzsetup.pyFs
   setuptoolss	   distutils)ÚnameÚ
read_bytes)rP   ÚcontentsrD   rD   rE   rU   �   s    
rU   )rQ   rP   rN   r+   c                    s@   ˆ j dv r|j ˆ ¡rdS |  d¡p(dg}t‡ fdd„|D ƒƒS )N)z.txtz.rstTr<   z	test*.txtc                 3   s   | ]}t |ˆ ƒV  qd S rH   r    )Ú.0ÚglobrO   rD   rE   Ú	<genexpr>š   ó    z_is_doctest.<locals>.<genexpr>)rR   ÚsessionZ
isinitpathÚ	getoptionrT   )rQ   rP   rN   ÚglobsrD   rO   rE   rX   –   s    rX   c                 C   s
   | j dkS )Nz__main__.py)r\   rO   rD   rD   rE   rV   �   s    rV   c                   @   s<   e Zd Zeeeee f  ddœdd„Zeddœdd„Z	dS )ÚReprFailDoctestN)Úreprlocation_linesr+   c                 C   s
   || _ d S rH   )rg   )Úselfrg   rD   rD   rE   Ú__init__¢   s    zReprFailDoctest.__init__)Útwr+   c                 C   s2   | j D ]&\}}|D ]}| |¡ q| |¡ qd S rH   )rg   ÚlineÚ
toterminal)rh   rj   ÚreprlocationÚlinesrk   rD   rD   rE   rl   §   s    zReprFailDoctest.toterminal)
Ú__name__Ú
__module__Ú__qualname__r   r   r   r@   ri   r   rl   rD   rD   rD   rE   rf   ¡   s   þrf   c                       s(   e Zd Zed ddœ‡ fdd„Z‡  ZS )ÚMultipleDoctestFailureszdoctest.DocTestFailureN)Úfailuresr+   c                    s   t ƒ  ¡  || _d S rH   )Úsuperri   rs   ©rh   rs   ©Ú	__class__rD   rE   ri   ¯   s    
z MultipleDoctestFailures.__init__)ro   rp   rq   r   ri   Ú__classcell__rD   rD   rv   rE   rr   ®   s   rr   údoctest.DocTestRunnerc                     s"   dd l ‰ G ‡ fdd„dˆ jƒ} | S )Nr   c                       sx   e Zd ZdZded ee eeddœ‡ fdd„Zd	d
eddœ‡fdd„Z	d	d
e
ee eejf ddœ‡fdd„Z‡  ZS )z/_init_runner_class.<locals>.PytestDoctestRunnerzˆRunner to collect failures.

        Note that the out variable in this case is a list instead of a
        stdout-like object.
        Nr   Tr(   ©ÚcheckerÚverboseÚoptionflagsÚcontinue_on_failurer+   c                    s   t ƒ j|||d� || _d S )N)r{   r|   r}   )rt   ri   r~   )rh   r{   r|   r}   r~   rv   rD   rE   ri   ¾   s    z8_init_runner_class.<locals>.PytestDoctestRunner.__init__údoctest.DocTestzdoctest.Example)ÚtestÚexampleÚgotr+   c                    s(   ˆ   |||¡}| jr | |¡ n|‚d S rH   )ÚDocTestFailurer~   r:   )rh   Úoutr€   r�   r‚   Úfailure©ÚdoctestrD   rE   Úreport_failureÈ   s    z>_init_runner_class.<locals>.PytestDoctestRunner.report_failure)r€   r�   Úexc_infor+   c                    sX   t |d tƒr|d ‚t |d tjƒr0t d¡ ˆ  |||¡}| jrP| |¡ n|‚d S )Né   zQuitting debugger)	Ú
isinstancer   ÚbdbZBdbQuitr   ÚexitÚUnexpectedExceptionr~   r:   )rh   r„   r€   r�   r‰   r…   r†   rD   rE   Úreport_unexpected_exceptionÕ   s    
zK_init_runner_class.<locals>.PytestDoctestRunner.report_unexpected_exception)NNr   T)ro   rp   rq   Ú__doc__r
   ÚboolÚintri   r@   rˆ   r   r   ÚBaseExceptionÚtypesÚTracebackTyper�   rx   rD   r†   rv   rE   ÚPytestDoctestRunner·   s,       ûúúúr–   )r‡   ZDebugRunner)r–   rD   r†   rE   Ú_init_runner_class´   s    /r—   Trz   c                 C   s   t d u rtƒ a t | |||d�S )N©r{   r|   r}   r~   )rI   r—   r˜   rD   rD   rE   Ú_get_runneré   s    ür™   c                       s¾   e Zd Zdeded ed ddœ‡ fdd„Zededddœ‡ fd	d
„ƒZddœdd„Zddœdd„Z	ddœdd„Z
ee eeef dœ‡ fdd„Zeedef ee ef dœdd„Z‡  ZS )ÚDoctestItemNz%Union[DoctestTextfile, DoctestModule]ry   r   )r\   rN   ÚrunnerÚdtestr+   c                    s*   t ƒ  ||¡ || _|| _d | _d | _d S rH   )rt   ri   r›   rœ   ÚobjÚfixture_request)rh   r\   rN   r›   rœ   rv   rD   rE   ri   þ   s
    zDoctestItem.__init__)rN   r\   r›   rœ   c                   s   t ƒ j||||d�S )zThe public named constructor.)r\   rN   r›   rœ   )rt   rW   )ÚclsrN   r\   r›   rœ   rv   rD   rE   rW     s    zDoctestItem.from_parentrG   c                 C   sV   | j d urRt| ƒ| _t| jjd�}| j d¡ ¡ D ]\}}|||< q2| j j |¡ d S )N)Z
getfixtureÚdoctest_namespace)rœ   Ú_setup_fixturesrž   ÚdictZgetfixturevalueÚitemsre   Úupdate)rh   re   r\   ÚvaluerD   rD   rE   Úsetup  s    

ÿ
zDoctestItem.setupc                 C   sT   | j d usJ ‚| jd usJ ‚t| j ƒ |  ¡  g }| jj| j |d� |rPt|ƒ‚d S )N)r„   )rœ   r›   Ú_check_all_skippedÚ$_disable_output_capturing_for_darwinÚrunrr   ru   rD   rD   rE   Úruntest"  s    
zDoctestItem.runtestc                 C   sV   t  ¡ dkrdS | jj d¡}|rR|jdd� | ¡ \}}tj 	|¡ tj
 	|¡ dS )zFDisable output capturing. Otherwise, stdout is lost to doctest (#985).ÚDarwinNZcapturemanagerT)Zin_)ÚplatformÚsystemrQ   ÚpluginmanagerZ	getpluginZsuspend_global_captureZread_global_captureÚsysÚstdoutÚwriteÚstderr)rh   Zcapmanr„   ÚerrrD   rD   rE   r¨   .  s    z0DoctestItem._disable_output_capturing_for_darwin)Úexcinfor+   c                    sÜ  dd l }d }t|j|j|jfƒr*|jg}nt|jtƒr>|jj}|d u rRtƒ  |¡S g }|D �]v}|j	}|j
‰ ˆ j}ˆ jd u r‚d }nˆ j|j d }t|ƒj}	t|||	ƒ}
tƒ }t| j d¡ƒ}|d u�r*|j
jd usØJ ‚|j
j d¡}ˆ jd usôJ ‚‡ fdd„t|ƒD ƒ}|t|jd dƒ|jd … }n6dg}d	}|j ¡ D ] }| d
|› d|› �¡ d}�q>t||jƒ�rŠ|| ||j|¡ d¡7 }n:t |j¡}|dt |jƒ g7 }|dd„ t!j"|jŽ D ƒ7 }| |
|f¡ qZt#|ƒS )Nr   rŠ   r8   Fc                    s&   g | ]\}}d |ˆ j  d |f ‘qS )z%03d %srŠ   )Úlineno)r_   ÚiÚx©r€   rD   rE   Ú
<listcomp>`  s   z,DoctestItem.repr_failure.<locals>.<listcomp>é	   z?EXAMPLE LOCATION UNKNOWN, not showing all tests of that examplez>>>z??? ú z...Ú
zUNEXPECTED EXCEPTION: %sc                 S   s   g | ]}|  d ¡‘qS )r¼   )Ústrip©r_   r·   rD   rD   rE   r¹   t  s   )$r‡   r‹   r¥   rƒ   rŽ   rr   rs   rt   Úrepr_failurer�   r€   Úfilenamerµ   r/   ro   r   Ú_get_checkerÚ_get_report_choicerQ   rd   Ú	docstringÚ
splitlinesÚ	enumerateÚmaxÚsourcer:   Zoutput_differencer‚   Úsplitr   Zfrom_exc_infor‰   ÚreprÚ	tracebackÚformat_exceptionrf   )rh   r´   r‡   rs   rg   r…   r�   rÀ   rµ   Úmessagerm   r{   Zreport_choicern   Úindentrk   Zinner_excinforv   r¸   rE   r¿   :  sd    þÿ





ÿ ÿÿþ
ÿzDoctestItem.repr_failurezos.PathLike[str]c                 C   s$   | j d usJ ‚| j| j jd| j fS )Nz[doctest] %s)rœ   rP   rµ   r\   )rh   rD   rD   rE   Ú
reportinfoz  s    zDoctestItem.reportinfo)NN)ro   rp   rq   r@   r
   ri   ÚclassmethodrW   r¦   rª   r¨   r   r“   r   r   r¿   r   r’   rÎ   rx   rD   rD   rv   rE   rš   ý   s,     ûúú

ý@rš   c                  C   s4   dd l } t| j| j| j| j| j| jtƒ t	ƒ t
ƒ d�	S )Nr   )	ÚDONT_ACCEPT_TRUE_FOR_1ÚDONT_ACCEPT_BLANKLINEÚNORMALIZE_WHITESPACEr.   ÚIGNORE_EXCEPTION_DETAILÚCOMPARISON_FLAGSÚALLOW_UNICODEÚALLOW_BYTESÚNUMBER)r‡   r¢   rÐ   rÑ   rÒ   r.   rÓ   rÔ   Ú_get_allow_unicode_flagÚ_get_allow_bytes_flagÚ_get_number_flagr†   rD   rD   rE   Ú_get_flag_lookup  s    ÷rÛ   c                 C   s0   | j  d¡}tƒ }d}|D ]}||| O }q|S )Nr,   r   )rQ   ÚgetinirÛ   )rN   Zoptionflags_strZflag_lookup_tableZflag_accÚflagrD   rD   rE   Úget_optionflags�  s    rÞ   c                 C   s    |   d¡}|r|   d¡rd}|S )Nr?   ZusepdbF)Úgetvalue)rQ   r~   rD   rD   rE   Ú_get_continue_on_failure˜  s
    

rà   c                   @   s"   e Zd ZdZee dœdd„ZdS )rL   NrG   c                 c   s”   dd l }| j d¡}| j |¡}t| jƒ}| jj}ddi}t| ƒ}td|t	ƒ t
| jƒd�}| ¡ }	|	 ||||d¡}
|
jr�tj| |
j||
d�V  d S )Nr   r1   ro   Ú__main__F©r|   r}   r{   r~   ©r\   r›   rœ   )r‡   rQ   rÜ   rP   Ú	read_textr@   r\   rÞ   r™   rÁ   rà   ZDocTestParserZget_doctestÚexamplesrš   rW   )rh   r‡   ÚencodingÚtextrÀ   r\   re   r}   r›   r*   r€   rD   rD   rE   r2   ¥  s&    
ü
ÿzDoctestTextfile.collect)ro   rp   rq   r�   r   rš   r2   rD   rD   rD   rE   rL   ¢  s   rL   r   )r€   r+   c                    s0   ddl ‰ t‡ fdd„| jD ƒƒ}|r,tdƒ dS )zVRaise pytest.skip() if all examples in the given DocTest have the SKIP
    option set.r   Nc                 3   s   | ]}|j  ˆ jd ¡V  qdS )FN)ÚoptionsÚgetZSKIPr¾   r†   rD   rE   ra   Æ  rb   z%_check_all_skipped.<locals>.<genexpr>z!all tests skipped by +SKIP option)r‡   Úallrå   r   )r€   Zall_skippedrD   r†   rE   r§   Á  s    r§   )r�   r+   c                 C   s   t | ddƒduS )zmReturn if an object is possibly a mock object by checking the
    existence of a highly improbable attribute.Z1pytest_mock_example_attribute_that_shouldnt_existNr   ©r�   rD   rD   rE   Ú
_is_mockedË  s    
ÿÿrì   )NNNc                  #   s\   t j‰ ddœtdtf tttgtf  tdœ‡ fdd„} | t _zdV  W ˆ t _nˆ t _0 dS )z€Context manager which replaces ``inspect.unwrap`` with a version
    that's aware of mock objects and doesn't recurse into them.N©Ústop.)Úfuncrî   r+   c             
      sz   z:|d u s|t u r ˆˆt d�W S |‰ ˆˆ‡ ‡fdd„d�W S  tyt } z"t d|ˆf t¡ ‚ W Y d }~n
d }~0 0 d S )Nrí   c                    s   t | ƒpˆ ˆƒS rH   )rì   rë   ©Ú_stoprï   rD   rE   Ú<lambda>á  rb   zF_patch_unwrap_mock_aware.<locals>._mock_aware_unwrap.<locals>.<lambda>z˜Got %r when unwrapping %r.  This is usually caused by a violation of Python's object protocol; see e.g. https://github.com/pytest-dev/pytest/issues/5080)rì   Ú	ExceptionÚwarningsÚwarnr%   )rï   rî   Úe©Zreal_unwraprð   rE   Ú_mock_aware_unwrapÚ  s    þüz4_patch_unwrap_mock_aware.<locals>._mock_aware_unwrap)ÚinspectÚunwrapr   r   r
   )rø   rD   r÷   rE   Ú_patch_unwrap_mock_awareÔ  s    ÿþrû   c                   @   s   e Zd Zee dœdd„ZdS )rK   rG   c                 c   sö   dd l }G dd„ d|jƒ}| jjdkrJ| jjj| j| j d¡| jjd�}nRz t	| j| jj| j d¡d�}W n0 t
yš   | j d¡r”td	| j ƒ n‚ Y n0 |ƒ }t| ƒ}td
|tƒ t| jƒd�}| ||j¡D ] }|jrÐtj| |j||d�V  qÐd S )Nr   c                       sJ   e Zd ZdZ‡ fdd„Zddœ‡ fdd„Zejdk rB‡ fd	d
„Zn ‡  Z	S )z5DoctestModule.collect.<locals>.MockAwareDocTestFinderzÇA hackish doctest finder that overrides stdlib internals to fix a stdlib bug.

            https://github.com/pytest-dev/pytest/issues/3456
            https://bugs.python.org/issue25532
            c                    s8   t |tƒrt|d|ƒ}t|dƒr*t |¡}tƒ  ||¡S )a3  Doctest code does not take into account `@property`, this
                is a hackish way to fix it. https://bugs.python.org/issue17446

                Wrapped Doctests will need to be unwrapped so the correct
                line number is returned. This will be reported upstream. #8796
                ÚfgetÚ__wrapped__)r‹   ÚpropertyÚgetattrÚhasattrrù   rú   rt   Ú_find_lineno)rh   r�   Úsource_linesrv   rD   rE   r  ý  s    


þzBDoctestModule.collect.<locals>.MockAwareDocTestFinder._find_linenoNrG   c              
      sN   t |ƒrd S tƒ �( tƒ  |||||||¡ W d   ƒ n1 s@0    Y  d S rH   )rì   rû   rt   Ú_find)rh   Útestsr�   r\   Úmoduler  re   Úseenrv   rD   rE   r    s    ÿz;DoctestModule.collect.<locals>.MockAwareDocTestFinder._find)é   é   c                    s*   t tdƒrt|tjƒr|j}tƒ  ||¡S )a>  `cached_property` objects are never considered a part
                    of the 'current module'. As such they are skipped by doctest.
                    Here we override `_from_module` to check the underlying
                    function instead. https://github.com/python/cpython/issues/107995
                    Úcached_property)r   Ú	functoolsr‹   r	  rï   rt   Ú_from_module)rh   r  Úobjectrv   rD   rE   r    s
    ÿzBDoctestModule.collect.<locals>.MockAwareDocTestFinder._from_module)
ro   rp   rq   r�   r  r  r¯   Úversion_infor  rx   rD   rD   rv   rE   ÚMockAwareDocTestFinderö  s   þ
r  zconftest.pyZ
importmode)Úrootpath)ÚrootÚmoder>   zunable to import module %rFrâ   rã   )r‡   ZDocTestFinderrP   r\   rQ   r®   Z_importconftestrd   r  r"   ÚImportErrorrß   r   rÞ   r™   rÁ   rà   Úfindro   rå   rš   rW   )rh   r‡   r  r  Úfinderr}   r›   r€   rD   rD   rE   r2   ó  s>    9
ý
ý
ü
ÿzDoctestModule.collectN)ro   rp   rq   r   rš   r2   rD   rD   rD   rE   rK   ò  s   rK   )Údoctest_itemr+   c                 C   sH   ddœdd„}i | _ | jj}|j| |ddd�| _t| dd�}| ¡  |S )	zEUsed by DoctestTextfile and DoctestItem to setup fixture information.NrG   c                   S   s   d S rH   rD   rD   rD   rD   rE   rï   U  s    z_setup_fixtures.<locals>.funcF)Únoderï   rŸ   ÚfuncargsT)Z	_ispytest)r  rc   Z_fixturemanagerZgetfixtureinfoZ_fixtureinfor   Z_fillfixtures)r  rï   Zfmrž   rD   rD   rE   r¡   R  s    ÿr¡   c                     s*   dd l } dd l‰ G ‡ fdd„d| jƒ}|S )Nr   c                       sf   e Zd Z” d”j¡Z” d”j¡Z” d”j¡Ze	e	e
edœ‡ ‡fdd„Ze	e	e	dœdd	„Z‡  ZS )
z2_init_checker_class.<locals>.LiteralsOutputCheckerz(\W|^)[uU]([rR]?[\'\"])z(\W|^)[bB]([rR]?[\'\"])aÍ  
            (?P<number>
              (?P<mantissa>
                (?P<integer1> [+-]?\d*)\.(?P<fraction>\d+)
                |
                (?P<integer2> [+-]?\d+)\.
              )
              (?:
                [Ee]
                (?P<exponent1> [+-]?\d+)
              )?
              |
              (?P<integer3> [+-]?\d+)
              (?:
                [Ee]
                (?P<exponent2> [+-]?\d+)
              )
            )
            )Úwantr‚   r}   r+   c                    s´   t ƒ  |||¡rdS |tƒ @ }|tƒ @ }|tƒ @ }|sB|sB|sBdS tt ttdœ‡fdd„}|rx|| j|ƒ}|| j|ƒ}|r”|| j|ƒ}|| j|ƒ}|r¤|  	||¡}t ƒ  |||¡S )NTF)ÚregexrZ   r+   c                    s   ˆ   | d|¡S )Nz\1\2)Úsub)r  rZ   ©ÚrerD   rE   Úremove_prefixes�  s    zX_init_checker_class.<locals>.LiteralsOutputChecker.check_output.<locals>.remove_prefixes)
rt   Úcheck_outputrØ   rÙ   rÚ   r   r@   Ú_unicode_literal_reÚ_bytes_literal_reÚ_remove_unwanted_precision)rh   r  r‚   r}   Zallow_unicodeZallow_bytesZallow_numberr  )rw   r  rD   rE   r  „  s"    


z?_init_checker_class.<locals>.LiteralsOutputChecker.check_output)r  r‚   r+   c                 S   s  t | j |¡ƒ}t | j |¡ƒ}t|ƒt|ƒkr4|S d}t||ƒD ]Ð\}}| d¡}| d¡}	|	d u rp| d¡}	|d u r|dnt|ƒ}
|	d ur˜|
t|	ƒ8 }
t| ¡ ƒtt| ¡ ƒd|
  d�krB|d | 	¡ | … | ¡  || 
¡ | d …  }|| 
¡ | 	¡  | 
¡ | 	¡   7 }qB|S )Nr   ÚfractionZ	exponent1Z	exponent2é
   )Úabs)ÚlistÚ
_number_reÚfinditerÚlenÚziprC   r’   Úfloatr$   ÚstartÚend)rh   r  r‚   ZwantsÚgotsÚoffsetÚwÚgr"  ÚexponentZ	precisionrD   rD   rE   r!  Ÿ  s$    


&.ÿ&zM_init_checker_class.<locals>.LiteralsOutputChecker._remove_unwanted_precision)ro   rp   rq   ÚcompileÚUNICODEr  r   ÚVERBOSEr&  r@   r’   r‘   r  r!  rx   rD   r  rv   rE   ÚLiteralsOutputCheckerf  s   ìr5  )r‡   r  ZOutputChecker)r‡   r5  rD   r  rE   Ú_init_checker_classb  s    Qr6  c                   C   s   t du rtƒ a t ƒ S )aà  Return a doctest.OutputChecker subclass that supports some
    additional options:

    * ALLOW_UNICODE and ALLOW_BYTES options to ignore u'' and b''
      prefixes (respectively) in string literals. Useful when the same
      doctest should run in Python 2 and Python 3.

    * NUMBER to ignore floating-point differences smaller than the
      precision of the literal number in the doctest.

    An inner class is used to avoid importing "doctest" at the module
    level.
    N)r)   r6  rD   rD   rD   rE   rÁ   º  s    rÁ   c                  C   s   ddl } |  d¡S )z+Register and return the ALLOW_UNICODE flag.r   NrÕ   ©r‡   Zregister_optionflagr†   rD   rD   rE   rØ   Î  s    rØ   c                  C   s   ddl } |  d¡S )z)Register and return the ALLOW_BYTES flag.r   NrÖ   r7  r†   rD   rD   rE   rÙ   Õ  s    rÙ   c                  C   s   ddl } |  d¡S )z$Register and return the NUMBER flag.r   Nr×   r7  r†   rD   rD   rE   rÚ   Ü  s    rÚ   )Úkeyr+   c              
   C   s,   ddl }t|jt|jt|jt|jt	di|  S )zÓReturn the actual `doctest` module flag value.

    We want to do it as late as possible to avoid importing `doctest` and all
    its dependencies when parsing options, as it adds overhead and breaks tests.
    r   N)
r‡   ÚDOCTEST_REPORT_CHOICE_UDIFFZREPORT_UDIFFÚDOCTEST_REPORT_CHOICE_CDIFFZREPORT_CDIFFÚDOCTEST_REPORT_CHOICE_NDIFFZREPORT_NDIFFÚ(DOCTEST_REPORT_CHOICE_ONLY_FIRST_FAILUREZREPORT_ONLY_FIRST_FAILUREÚDOCTEST_REPORT_CHOICE_NONE)r8  r‡   rD   rD   rE   rÂ   ã  s    ûúrÂ   rc   )Zscopec                   C   s   t ƒ S )a€  Fixture that returns a :py:class:`dict` that will be injected into the
    namespace of doctests.

    Usually this fixture is used in conjunction with another ``autouse`` fixture:

    .. code-block:: python

        @pytest.fixture(autouse=True)
        def add_np(doctest_namespace):
            doctest_namespace["np"] = numpy

    For more details: :ref:`doctest_namespace`.
    )r¢   rD   rD   rD   rE   r    ô  s    r    )NNr   T)fr�   rŒ   r
  rù   Úosr¬   r¯   rÊ   r”   rô   Ú
contextlibr   Úpathlibr   Útypingr   r   r   r   r   r	   r
   r   r   r   r   r   r   Z_pytestr   Z_pytest._code.coder   r   r   Z_pytest._ior   Z_pytest.compatr   Z_pytest.configr   Z_pytest.config.argparsingr   Z_pytest.fixturesr   r   Z_pytest.nodesr   r   Z_pytest.outcomesr   r   Z_pytest.pathlibr!   r"   Z_pytest.pythonr#   Z_pytest.python_apir$   Z_pytest.warning_typesr%   r‡   r=  r:  r;  r9  r<  rB   rI   r)   Ú__annotations__rF   rJ   r[   r‘   rU   rX   rV   rf   ró   rr   r—   r’   r™   rš   r@   rÛ   rÞ   rà   rL   r§   r  rì   rû   rK   r¡   r6  rÁ   rØ   rÙ   rÚ   rÂ   r    rD   rD   rD   rE   Ú<module>   sÊ   û	2
ý6    üû 	

	`X