a
    ø£Beùs  ã                   @   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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/m0Z0 ddl1m2Z2 ddl1m3Z3 ddl4m5Z5 dd l6m7Z7 e�rÌddl8Z8d!Z9d"Z:d#Z;d$Z<d%Z=e9e:e;e<e=fZ>da?da@eed&  eAd'< e*dd(œd)d*„ZBdd+œd,d-„ZCee.eed.  d/œd0d1„ZDeEejF Gd2¡d ƒd3k �r€eDZHe.eed.  d4œd5d1„ZDe3ZId6d7„ Z3eeJd8œd9d:„ZKe(ee.eJd;œd<d=„ZLeeJd8œd>d?„ZMG d@dA„ dAe"ƒZNG dBdC„ dCeOƒZPedD d+œdEdF„ZQdued& eeJ eEeJdDdHœdIdJ„ZRG dKdL„ dLejSƒZTeeUeEf d+œdMdN„ZVdOdP„ ZWdQdR„ ZXG dSdT„ dTejYƒZZdUddVœdWdX„Z[e\eJdYœdZd[„Z]eed\ d+œd]d^„ƒZ^G d_d`„ d`ejYƒZ_eTe,daœdbdc„Z`ed& d+œddde„Zad&d+œdfdg„ZbeEd+œdhdi„ZceEd+œdjdk„ZdeEd+œdldm„ZeeUeEdnœdodp„Zfejgdqdr�eeUef d+œdsdt„ƒZhdS )vz6Discover and run ipdoctests 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)ÚFixtureRequest)Ú	Collector)ÚOutcomeException©Ú
fnmatch_ex)Úimport_path)Úapprox)ÚPytestWarningÚnoneZcdiffZndiffÚudiffZonly_first_failureÚIPDoctestOutputCheckerÚ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Úipdoctest_optionflagszoption flags for ipdoctestsÚargsÚELLIPSIS)ÚtypeÚdefaultÚipdoctest_encodingz!encoding used for ipdoctest fileszutf-8)r,   Úcollectz--ipdoctest-modulesÚ
store_trueFz!run ipdoctests in all .py modulesÚipdoctestmodules)Úactionr,   ÚhelpÚdestz--ipdoctest-reportr#   z;choose another output format for diffs on ipdoctest failureÚipdoctestreport)r+   r,   r2   Úchoicesr3   z--ipdoctest-globÚappendÚpatz4ipdoctests file matching pattern, default: test*.txtÚipdoctestglob)r1   r,   Úmetavarr2   r3   z --ipdoctest-ignore-import-errorszignore ipdoctest ImportErrorsÚipdoctest_ignore_import_errorsz--ipdoctest-continue-on-failurez>for a given ipdoctest, continue to run after the first failureÚipdoctest_continue_on_failure)ZaddiniZgetgroupZ	addoptionÚstrÚlowerÚDOCTEST_REPORT_CHOICES)r&   Úgroup© r@   új/home/yuhw/wc/wire-cell-python/wcpy/lib/python3.9/site-packages/IPython/testing/plugin/pytest_ipdoctest.pyÚpytest_addoptionH   s^    üÿ
ûúúûûrB   ©r'   c                   C   s   d a d S ©N)ÚRUNNER_CLASSr@   r@   r@   rA   Úpytest_unconfigurez   s    rF   )ÚIPDoctestModuleÚIPDoctestTextfile)Ú	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Úoptionr0   ÚanyÚ_is_setup_pyÚ_is_main_pyrG   Úfrom_parentÚ_is_ipdoctestrH   )rI   rJ   rM   ÚmodÚtxtr@   r@   rA   Úpytest_collect_file€   s    

ÿrW   Ú.é   )rJ   r'   c                 C   s   t t| ƒ|ƒS rD   )Ú_collect_filer   )rL   rJ   r@   r@   rA   rW   ”   s    c                 C   s   dd l }t|j | ¡ƒS )Nr   )Úpy.pathÚ_import_pathrL   Úlocal)rL   ÚrootÚpyr@   r@   rA   r   œ   s    r   )rL   r'   c                 C   s&   | j dkrdS |  ¡ }d|v p$d|v S )Nzsetup.pyFs
   setuptoolss	   distutils)ÚnameÚ
read_bytes)rL   Úcontentsr@   r@   rA   rQ   ¢   s    
rQ   )rM   rL   rJ   r'   c                    s@   ˆ j dv r|j ˆ ¡rdS |  d¡p(dg}t‡ fdd„|D ƒƒS )N)z.txtz.rstTr8   z	test*.txtc                 3   s   | ]}t |ˆ ƒV  qd S rD   r   )Ú.0ÚglobrK   r@   rA   Ú	<genexpr>­   ó    z _is_ipdoctest.<locals>.<genexpr>)rN   ÚsessionZ
isinitpathÚ	getoptionrP   )rM   rL   rJ   Úglobsr@   rK   rA   rT   ©   s    rT   c                 C   s
   | j dkS )Nz__main__.py)r`   rK   r@   r@   rA   rR   °   s    rR   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 rD   )rk   )Úselfrk   r@   r@   rA   Ú__init__µ   s    zReprFailDoctest.__init__)Útwr'   c                 C   s2   | j D ]&\}}|D ]}| |¡ q| |¡ qd S rD   )rk   ÚlineÚ
toterminal)rl   rn   ÚreprlocationÚlinesro   r@   r@   rA   rp   º   s    zReprFailDoctest.toterminal)
Ú__name__Ú
__module__Ú__qualname__r   r   r   r<   rm   r   rp   r@   r@   r@   rA   rj   ´   s   þrj   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 rD   )Úsuperrm   rw   )rl   rw   ©Ú	__class__r@   rA   rm   Â   s    
z MultipleDoctestFailures.__init__)rs   rt   ru   r   rm   Ú__classcell__r@   r@   ry   rA   rv   Á   s   rv   ÚIPDocTestRunnerc                     s,   dd l ‰ ddlm}  G ‡ fdd„d| ƒ}|S )Nr   é   )r|   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�   )rx   rm   r‚   )rl   r   r€   r�   r‚   ry   r@   rA   rm   Ò   s    z8_init_runner_class.<locals>.PytestDoctestRunner.__init__údoctest.DocTestzdoctest.Example)ÚtestÚexampleÚgotr'   c                    s(   ˆ   |||¡}| jr | |¡ n|‚d S rD   )ÚDocTestFailurer‚   r6   )rl   Úoutr„   r…   r†   Úfailure©Údoctestr@   rA   Ú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 )Nr}   zQuitting debugger)	Ú
isinstancer   ÚbdbZBdbQuitr   ÚexitÚUnexpectedExceptionr‚   r6   )rl   rˆ   r„   r…   r�   r‰   rŠ   r@   rA   Úreport_unexpected_exceptioné   s    
zK_init_runner_class.<locals>.PytestDoctestRunner.report_unexpected_exception)NNr   T)rs   rt   ru   Ú__doc__r
   ÚboolÚintrm   r<   rŒ   r   r   ÚBaseExceptionÚtypesÚTracebackTyper’   r{   r@   rŠ   ry   rA   ÚPytestDoctestRunnerË   s,       ûúúúr™   )r‹   Ú	ipdoctestr|   )r|   r™   r@   rŠ   rA   Ú_init_runner_classÇ   s    /r›   Tr~   c                 C   s   t d u rtƒ a t | |||d�S )N©r   r€   r�   r‚   )rE   r›   rœ   r@   r@   rA   Ú_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
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eej d¡d ƒdk rîeedœdd„ƒZ‡  ZS ) ÚIPDoctestItemNz)Union[IPDoctestTextfile, IPDoctestModule]r|   rƒ   )r`   rJ   ÚrunnerÚdtestr'   c                    s*   t ƒ  ||¡ || _|| _d | _d | _d S rD   )rx   rm   rŸ   r    ÚobjÚfixture_request)rl   r`   rJ   rŸ   r    ry   r@   rA   rm     s
    zIPDoctestItem.__init__)rJ   r`   rŸ   r    c                   s   t ƒ j||||d�S )zThe public named constructor.)r`   rJ   rŸ   r    )rx   rS   )ÚclsrJ   r`   rŸ   r    ry   r@   rA   rS     s    zIPDoctestItem.from_parentrC   c                 C   sº   | j d ur¶t| ƒ| _t| jjd�}| j d¡ ¡ D ]\}}|||< q2| j j |¡ ddlm	} t
| j jd |ƒr¶i | _| j tj¡ tj | j j¡ tj dd ¡ ttjd< tj| j _d S )N)Z
getfixtureÚipdoctest_namespacer}   ©Ú	IPExampler   Ú_Ú__builtins__)r    Ú_setup_fixturesr¢   ÚdictZgetfixturevalueÚitemsri   Úupdaterš   r¦   rŽ   ÚexamplesÚ_user_ns_origÚ_ipÚuser_nsÚpopÚbuiltins)rl   ri   r`   Úvaluer¦   r@   r@   rA   Úsetup,  s     

ÿ

zIPDoctestItem.setupc                 C   sR   ddl m} t| jjd |ƒrBi | j_tj ¡  tj 	| j
¡ | `
| jj ¡  d S )Nr}   r¥   r   )rš   r¦   rŽ   r    r­   ri   r¯   r°   Úclearr¬   r®   )rl   r¦   r@   r@   rA   ÚteardownE  s    
zIPDoctestItem.teardownc              
   C   sê   | j d usJ ‚| jd usJ ‚t| j ƒ |  ¡  g }ttdƒ}ttdd ƒ}t ¡ }t 	| j
j¡ zH| jj| j |dd� W t 	|¡ |r’ttd|ƒ qÚttdƒrÚttdƒ n2t 	|¡ |rÄttd|ƒ nttdƒrØttdƒ 0 |ræt|ƒ‚d S )Nr§   F)rˆ   Zclear_globs)r    rŸ   Ú_check_all_skippedÚ$_disable_output_capturing_for_darwinÚhasattrr²   ÚgetattrÚosÚgetcwdÚchdirÚfspathÚdirnameÚrunÚsetattrÚdelattrrv   )rl   rw   Zhad_underscore_valueZunderscore_original_valueÚcurdirr@   r@   rA   ÚruntestQ  s.    



ü

zIPDoctestItem.runtestc                 C   sV   t  ¡ dkrdS | jj d¡}|rR|jdd� | ¡ \}}tj 	|¡ tj
 	|¡ dS )zNDisable output capturing. Otherwise, stdout is lost to ipdoctest (pytest#985).ÚDarwinNZcapturemanagerT)Úin_)ÚplatformÚsystemrM   ÚpluginmanagerZ	getpluginZsuspend_global_captureZread_global_captureÚsysÚstdoutÚwriteÚstderr)rl   Zcapmanrˆ   Úerrr@   r@   rA   r¸   o  s    z2IPDoctestItem._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}   r4   Fc                    s&   g | ]\}}d |ˆ j  d |f ‘qS )z%03d %sr}   )Úlineno)rc   ÚiÚx©r„   r@   rA   Ú
<listcomp>¡  s   z.IPDoctestItem.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©rc   rÒ   r@   r@   rA   rÔ   µ  s   )$r‹   rŽ   r³   r‡   r‘   rv   rw   rx   Úrepr_failurer…   r„   ÚfilenamerÐ   r+   rs   r   Ú_get_checkerÚ_get_report_choicerM   rh   Ú	docstringÚ
splitlinesÚ	enumerateÚmaxÚsourcer6   Zoutput_differencer†   Úsplitr   Zfrom_exc_infor�   ÚreprÚ	tracebackÚformat_exceptionrj   )rl   rÏ   r‹   rw   rk   r‰   r…   rÛ   rÐ   Úmessagerq   r   Zreport_choicerr   Úindentro   Zinner_excinfory   rÓ   rA   rÚ   {  sd    þÿ





ÿ ÿÿþ
ÿzIPDoctestItem.repr_failurezos.PathLike[str]c                 C   s$   | j d usJ ‚| j| j jd| j fS )Nz[ipdoctest] %s)r    rL   rÐ   r`   ©rl   r@   r@   rA   Ú
reportinfo»  s    zIPDoctestItem.reportinforX   r   rY   c                 C   s
   t | jƒS rD   ©r   r¾   ré   r@   r@   rA   rL   Á  s    zIPDoctestItem.path)NN)rs   rt   ru   r<   r
   rm   ÚclassmethodrS   r´   r¶   rÄ   r¸   r   r–   r   r   rÚ   r   r•   rê   ÚpytestÚ__version__rã   Úpropertyr   rL   r{   r@   r@   ry   rA   rž     s4     ûúú
ý@$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Š   r@   r@   rA   Ú_get_flag_lookupÆ  s    ÷rû   c                 C   s0   | j  d¡}tƒ }d}|D ]}||| O }q|S )Nr(   r   )rM   Úgetinirû   )rJ   Zoptionflags_strZflag_lookup_tableZflag_accÚflagr@   r@   rA   Úget_optionflagsÖ  s    rþ   c                 C   s    |   d¡}|r|   d¡rd}|S )Nr;   ZusepdbF)Úgetvalue)rM   r‚   r@   r@   rA   Ú_get_continue_on_failureß  s
    

r   c                       sr   e Zd ZdZee dœdd„Zeej	 
d¡d ƒdk rjeedœdd	„ƒZeddd
œee dœ‡ fdd„ƒZ‡  ZS )rH   NrC   c                 c   sž   dd l }ddlm} | 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   r}   )ÚIPDocTestParserr-   rs   Ú__main__F©r€   r�   r   r‚   ©r`   rŸ   r    )r‹   rš   r  rM   rü   rL   Ú	read_textr<   r`   rþ   r�   rÜ   r   Zget_doctestr­   rž   rS   )rl   r‹   r  ÚencodingÚtextrÛ   r`   ri   r�   rŸ   r&   r„   r@   r@   rA   r.   ì  s(    
ü
ÿzIPDoctestTextfile.collectrX   r   rY   c                 C   s
   t | jƒS rD   rë   ré   r@   r@   rA   rL   
  s    zIPDoctestTextfile.path©r¾   rL   rK   c                   s4   |d urdd l }|j |¡}tƒ jf ||dœ|¤ŽS ©Nr   )rJ   r¾   ©r[   rL   r]   rx   rS   ©r£   rJ   r¾   rL   Úkwr_   ry   r@   rA   rS     s    	zIPDoctestTextfile.from_parent)rs   rt   ru   r¡   r   rž   r.   r•   rí   rî   rã   rï   r   rL   rì   r
   rS   r{   r@   r@   ry   rA   rH   é  s   ûûrH   rƒ   )r„   r'   c                    s2   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Š   r@   rA   re   #  rf   z%_check_all_skipped.<locals>.<genexpr>z%all docstests skipped by +SKIP option)r‹   Úallr­   rí   Úskip)r„   Zall_skippedr@   rŠ   rA   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¡   r@   r@   rA   Ú
_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 rD   )r  r  ©Ú_stopr  r@   rA   Ú<lambda>>  rf   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  rA   Ú_mock_aware_unwrap7  s    þüz4_patch_unwrap_mock_aware.<locals>._mock_aware_unwrap)ÚinspectÚunwrapr   r   r
   )r  r@   r  rA   Ú_patch_unwrap_mock_aware1  s    ÿþr!  c                       sn   e Zd Zee dœdd„Zeej 	d¡d ƒdk rfe
edœdd„ƒZed	d	d
œee dœ‡ fdd„ƒZ‡  ZS )rG   rC   c           
      c   s:  dd l }ddlm}m} G dd„ d|ƒ}| jjdkrŒttj 	d¡d ƒdk rh| j
j | j| j
 d	¡¡}qÖ| j
jj| j| j
 d	¡| j
jd
�}nJzt| j| j
jd�}W n2 tyÔ   | j
 d¡rÎt d| j ¡ n‚ Y n0 ||ƒ d�}t| ƒ}td|tƒ t| j
ƒd�}| ||j¡D ]$}	|	j�rtj| |	j||	d�V  �qd S )Nr   r}   )ÚDocTestFinderr  c                       s2   e Zd ZdZ‡ fdd„Zddœ‡ fdd„Z‡  ZS )z7IPDoctestModule.collect.<locals>.MockAwareDocTestFinderzÉA hackish ipdoctest 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Ž   rï   rº   r¹   r  r   rx   Ú_find_lineno)rl   r¡   Úsource_linesry   r@   rA   r%  [  s    


þzDIPDoctestModule.collect.<locals>.MockAwareDocTestFinder._find_linenoNrC   c              
      sN   t |ƒrd S tƒ �( tƒ  |||||||¡ W d   ƒ n1 s@0    Y  d S rD   )r  r!  rx   Ú_find)rl   Útestsr¡   r`   Úmoduler&  ri   Úseenry   r@   rA   r'  o  s    ÿz=IPDoctestModule.collect.<locals>.MockAwareDocTestFinder._find)rs   rt   ru   r“   r%  r'  r{   r@   r@   ry   rA   ÚMockAwareDocTestFinderT  s   þr+  zconftest.pyrX   rY   Z
importmode)Úrootpath)r^   r:   zunable to import module %r)r&   Fr  r  )r‹   rš   r"  r  rL   r`   r•   rí   rî   rã   rM   rÉ   Z_importconftestrh   r,  r   ÚImportErrorrÿ   r  rþ   r�   rÜ   r   Úfindrs   r­   rž   rS   )
rl   r‹   r"  r  r+  r)  Úfinderr�   rŸ   r„   r@   r@   rA   r.   P  sB    &
þ
ýü
ÿzIPDoctestModule.collectrX   r   rY   c                 C   s
   t | jƒS rD   rë   ré   r@   r@   rA   rL      s    zIPDoctestModule.pathNr  rK   c                   s4   |d urdd l }|j |¡}tƒ jf ||dœ|¤ŽS r	  r
  r  ry   r@   rA   rS   ¤  s    	zIPDoctestModule.from_parent)rs   rt   ru   r   rž   r.   r•   rí   rî   rã   rï   r   rL   rì   r
   rS   r{   r@   r@   ry   rA   rG   O  s   NûûrG   )Údoctest_itemr'   c                 C   sH   ddœdd„}i | _ | jj}|j| |ddd�| _t| dd�}| ¡  |S )	zIUsed by IPDoctestTextfile and IPDoctestItem to setup fixture information.NrC   c                   S   s   d S rD   r@   r@   r@   r@   rA   r  ·  s    z_setup_fixtures.<locals>.funcF)Únoder  r£   ÚfuncargsT)Z	_ispytest)r2  rg   Z_fixturemanagerZgetfixtureinfoZ_fixtureinfor   Z_fillfixtures)r0  r  Úfmr¢   r@   r@   rA   r©   ´  s    ÿr©   c                     s4   dd l } dd l‰ ddlm} G ‡ fdd„d|ƒ}|S )Nr   r}   )r$   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)ÚregexrV   r'   c                    s   ˆ   | d|¡S )Nz\1\2)Úsub)r5  rV   ©Úrer@   rA   Úremove_prefixesò  s    zX_init_checker_class.<locals>.LiteralsOutputChecker.check_output.<locals>.remove_prefixes)
rx   Úcheck_outputrø   rù   rú   r   r<   Ú_unicode_literal_reÚ_bytes_literal_reÚ_remove_unwanted_precision)rl   r4  r†   r�   Zallow_unicodeZallow_bytesZallow_numberr9  )rz   r8  r@   rA   r:  ç  s"    


z?_init_checker_class.<locals>.LiteralsOutputChecker.check_output)r4  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Úzipr?   r•   Úfloatr    ÚstartÚend)rl   r4  r†   ZwantsÚgotsÚoffsetÚwÚgr>  ÚexponentÚ	precisionr@   r@   rA   r=    s$    


&.ÿ&zM_init_checker_class.<locals>.LiteralsOutputChecker._remove_unwanted_precision)rs   rt   ru   ÚcompileÚUNICODEr;  r<  ÚVERBOSErB  r<   r•   r”   r:  r=  r{   r@   r7  ry   rA   ÚLiteralsOutputCheckerÉ  s   ìrR  )r‹   r8  rš   r$   )r‹   r$   rR  r@   r7  rA   Ú_init_checker_classÄ  s
    QrS  c                   C   s   t du rtƒ a t ƒ S )aç  Return a IPDoctestOutputChecker 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
      ipdoctest should run in Python 2 and Python 3.

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

    An inner class is used to avoid importing "ipdoctest" at the module
    level.
    N)r%   rS  r@   r@   r@   rA   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Š   r@   r@   rA   rø   1  s    rø   c                  C   s   ddl } |  d¡S )z)Register and return the ALLOW_BYTES flag.r   Nrö   rT  rŠ   r@   r@   rA   rù   8  s    rù   c                  C   s   ddl } |  d¡S )z$Register and return the NUMBER flag.r   Nr÷   rT  rŠ   r@   r@   rA   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 `ipdoctest` module flag value.

    We want to do it as late as possible to avoid importing `ipdoctest` 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)rU  r‹   r@   r@   rA   rÝ   F  s    ûúrÝ   rg   )Úscopec                   C   s   t ƒ S )zcFixture that returns a :py:class:`dict` that will be injected into the
    namespace of ipdoctests.)rª   r@   r@   r@   rA   r¤   W  s    r¤   )NNr   T)ir“   r²   r�   r  r»   rÇ   rÊ   rå   r—   r  Ú
contextlibr   Úpathlibr   Útypingr   r   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   Z_pytest.nodesr   Z_pytest.outcomesr   Z_pytest.pathlibr   r   Z_pytest.python_apir    Z_pytest.warning_typesr!   r‹   rZ  rW  rX  rV  rY  r>   rE   r%   Ú__annotations__rB   rF   rW   r•   rî   rã   rZ   r\   r”   rQ   rT   rR   rj   r  rv   r›   r�   ZItemrž   r<   rû   rþ   r   ÚModulerH   r·   Úobjectr  r!  rG   r©   rS  rÜ   rø   rù   rú   rÝ   Zfixturer¤   r@   r@   r@   rA   Ú<module>   sÒ   û	2
ý
ý7    üû 6	
5
	eY
