o
    hh                     @   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rddl<Z<d%Z=d&Z>d'Z?d(Z@d)ZAe=e>e?e@eAfZBdaCdaDeed*  eEd+< d,e)d-dfd.d/ZFdwd0d1ZGd2ed3e.d-eed4  fd5d6ZHd7ed-eIfd8d9ZJd:e'd7ed3e.d-eIfd;d<ZKd7ed-eIfd=d>ZLG d?d@ d@e!ZMG dAdB dBeNZOd-edC fdDdEZP				FdxdGed* dHeeI dIeQdJeId-dCf
dKdLZRG dMdN dNe/ZSd-eeTeQf fdOdPZUdQdR ZVdSdT ZWG dUdV dVe7ZXdydYdZZYd[eZd-eIfd\d]Z[ed-ed^ fd_d`Z\G dadb dbe7Z]dceSd-e,fdddeZ^d-ed* fdfdgZ_dzdhdiZ`d-eQfdjdkZad-eQfdldmZbd-eQfdndoZcdpeTd-eQfdqdrZde+dsdtd-eeTef fdudvZedS ){z4Discover 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nonecdiffndiffudiff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)r3   collectz--doctest-modules
store_trueFzRun doctests in all .py modulesdoctestmodules)actionr3   helpdestz--doctest-reportr)   z9Choose another output format for diffs on doctest failuredoctestreport)r2   r3   r9   choicesr:   z--doctest-globappendpatz2Doctests file matching pattern, default: test*.txtdoctestglob)r8   r3   metavarr9   r:   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)addinigetgroup	addoptionstrlowerDOCTEST_REPORT_CHOICES)r-   group rJ   E/var/www/html/ai/venv/lib/python3.10/site-packages/_pytest/doctest.pypytest_addoptionF   s^   

rL   c                   C   s   d a d S N)RUNNER_CLASSrJ   rJ   rJ   rK   pytest_unconfigurex   s   rO   	file_pathparent)DoctestModuleDoctestTextfilec                 C   sd   |j }| jdkr!|jjrtt| t| fstj|| d}|S d S t	|| |r0t
j|| d}|S d S )Nz.pypath)configsuffixoptionr7   any_is_setup_py_is_main_pyrR   from_parent_is_doctestrS   )rP   rQ   rV   modtxtrJ   rJ   rK   pytest_collect_file~   s   

r`   rU   c                 C   s&   | j dkrdS |  }d|v pd|v S )Nzsetup.pyFs
   setuptoolss	   distutils)name
read_bytes)rU   contentsrJ   rJ   rK   rZ      s   
rZ   rV   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 rM   r    ).0globrT   rJ   rK   	<genexpr>   s    z_is_doctest.<locals>.<genexpr>)rW   session
isinitpath	getoptionrY   )rV   rU   rQ   globsrJ   rT   rK   r]      s   r]   c                 C   s
   | j dkS )Nz__main__.py)ra   rT   rJ   rJ   rK   r[      s   
r[   c                   @   s@   e Zd Zdeeeee f  ddfddZdeddfddZ	dS )	ReprFailDoctestreprlocation_linesr.   Nc                 C   s
   || _ d S rM   )rl   )selfrl   rJ   rJ   rK   __init__   s   
zReprFailDoctest.__init__twc                 C   s2   | j D ]\}}|D ]}|| q	|| qd S rM   )rl   line
toterminal)rm   ro   reprlocationlinesrp   rJ   rJ   rK   rq      s
   zReprFailDoctest.toterminal)
__name__
__module____qualname__r   r   r   rF   rn   r   rq   rJ   rJ   rJ   rK   rk      s    
rk   c                       s*   e Zd Zded ddf fddZ  ZS )MultipleDoctestFailuresfailureszdoctest.DocTestFailurer.   Nc                    s   t    || _d S rM   )superrn   rx   rm   rx   	__class__rJ   rK   rn      s   

z MultipleDoctestFailures.__init__)rt   ru   rv   r   rn   __classcell__rJ   rJ   r{   rK   rw      s    "rw   doctest.DocTestRunnerc                     s"   dd l  G  fddd j} | S )Nr   c                       s   e Zd ZdZ				dded dee ded	ed
df
 fddZddddded
dffddZ	ddddde
ee eejf d
dffddZ  ZS )z/_init_runner_class.<locals>.PytestDoctestRunnerzRunner to collect failures.

        Note that the out variable in this case is a list instead of a
        stdout-like object.
        Nr   Tcheckerr+   verboseoptionflagscontinue_on_failurer.   c                    s   t  j|||d || _d S )N)r   r   r   )ry   rn   r   )rm   r   r   r   r   r{   rJ   rK   rn      s   
z8_init_runner_class.<locals>.PytestDoctestRunner.__init__testdoctest.DocTestexamplezdoctest.Examplegotc                    s&     |||}| jr|| d S |rM   )DocTestFailurer   r=   )rm   outr   r   r   failuredoctestrJ   rK   report_failure   s   z>_init_runner_class.<locals>.PytestDoctestRunner.report_failureexc_infoc                    sV   t |d tr|d t |d tjrtd  |||}| jr)|| d S |)N   zQuitting debugger)	
isinstancer   bdbBdbQuitr   exitUnexpectedExceptionr   r=   )rm   r   r   r   r   r   r   rJ   rK   report_unexpected_exception   s   
zK_init_runner_class.<locals>.PytestDoctestRunner.report_unexpected_exceptionNNr   T)rt   ru   rv   __doc__r
   boolintrn   rF   r   r   r   BaseExceptiontypesTracebackTyper   r}   rJ   r   r{   rK   PytestDoctestRunner   sF    
r   )r   DebugRunner)r   rJ   r   rK   _init_runner_class   s   /r   Tr   r   r   r   c                 C   s   t d u rt a t | |||dS )Nr   r   r   r   )rN   r   r   rJ   rJ   rK   _get_runner   s   r   c                       s   e Zd Z		ddeddded ded d	df
 fd
dZedddeddddf fddZdddZdddZ	dddZ
dee d	eeef f fddZd	eedef ee ef fddZ  ZS )DoctestItemNra   rQ   z%Union[DoctestTextfile, DoctestModule]runnerr~   dtestr   r.   c                    s*   t  || || _|| _d | _d | _d S rM   )ry   rn   r   r   objfixture_request)rm   ra   rQ   r   r   r{   rJ   rK   rn      s
   
zDoctestItem.__init__c                   s   t  j||||dS )zThe public named constructor.)ra   rQ   r   r   )ry   r\   )clsrQ   ra   r   r   r{   rJ   rK   r\     s   zDoctestItem.from_parentc                 C   sZ   | j d ur+t| | _t| jjd}| jd D ]\}}|||< q| j j| d S d S )N)
getfixturedoctest_namespace)r   _setup_fixturesr   dictgetfixturevalueitemsrj   update)rm   rj   ra   valuerJ   rJ   rK   setup  s   



zDoctestItem.setupc                 C   sT   | j d usJ | jd usJ t| j  |   g }| jj| j |d |r(t|d S )N)r   )r   r   _check_all_skipped$_disable_output_capturing_for_darwinrunrw   rz   rJ   rJ   rK   runtest"  s   
zDoctestItem.runtestc                 C   sZ   t  dkrdS | jjd}|r+|jdd | \}}tj	| tj
	| dS dS )zFDisable output capturing. Otherwise, stdout is lost to doctest (#985).DarwinNcapturemanagerT)in_)platformsystemrV   pluginmanager	getpluginsuspend_global_captureread_global_capturesysstdoutwritestderr)rm   capmanr   errrJ   rJ   rK   r   .  s   z0DoctestItem._disable_output_capturing_for_darwinexcinfoc                    s  dd l }d }t|j|j|jfr|jg}n
t|jtr|jj}|d u r)t |S g }|D ]}|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sjJ |j
jd} jd usxJ  fddt|D }|t|jd d|jd  }ndg}d	}|j D ]}|d
| d|  d}qt||jr||||j|d7 }nt|j}|dt |j g7 }|dd t!j"|j D 7 }||
|f q-t#|S )Nr   r   r;   Fc                    s&   g | ]\}}d | j  d |f qS )z%03d %sr   )lineno)rd   ixr   rJ   rK   
<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rd   r   rJ   rJ   rK   r   t  s    
)$r   r   r   r   r   rw   rx   ry   repr_failurer   r   filenamer   r2   rt   r   _get_checker_get_report_choicerV   ri   	docstring
splitlines	enumeratemaxsourcer=   output_differencer   splitr   from_exc_infor   repr	tracebackformat_exceptionrk   )rm   r   r   rx   rl   r   r   r   r   messagerr   r   report_choicers   indentrp   inner_excinfor{   r   rK   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   rU   r   ra   )rm   rJ   rJ   rK   
reportinfoz  s   zDoctestItem.reportinfo)NNr.   N)rt   ru   rv   rF   r
   rn   classmethodr\   r   r   r   r   r   r   r   r   r   r   r   r}   rJ   rJ   r{   rK   r      sB    




,@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_WHITESPACEr1   IGNORE_EXCEPTION_DETAILCOMPARISON_FLAGSALLOW_UNICODEALLOW_BYTESNUMBER)r   r   r   r   r   r1   r   r   _get_allow_unicode_flag_get_allow_bytes_flag_get_number_flagr   rJ   rJ   rK   _get_flag_lookup  s   r   c                 C   s0   | j d}t }d}|D ]}||| O }q|S )Nr/   r   )rV   getinir   )rQ   optionflags_strflag_lookup_tableflag_accflagrJ   rJ   rK   get_optionflags  s   r   c                 C   s    |  d}|r|  drd}|S )NrB   usepdbF)getvalue)rV   r   rJ   rJ   rK   _get_continue_on_failure  s
   

r   c                   @   s"   e Zd ZdZdee fddZdS )rS   Nr.   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rKtj| |
j||
dV  d S d S )Nr   r4   rt   __main__Fr   r   r   r   ra   r   r   )r   rV   r   rU   	read_textrF   ra   r   r   r   r   DocTestParserget_doctestexamplesr   r\   )rm   r   encodingtextr   ra   rj   r   r   r-   r   rJ   rJ   rK   r5     s*   

zDoctestTextfile.collect)rt   ru   rv   r   r   r   r5   rJ   rJ   rJ   rK   rS     s    rS   r   r   c                    s4   ddl  t fdd| jD }|rtd dS 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getSKIPr   r   rJ   rK   rf     s    z%_check_all_skipped.<locals>.<genexpr>z!all tests skipped by +SKIP option)r   allr   r   )r   all_skippedrJ   r   rK   r     s
   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.1pytest_mock_example_attribute_that_shouldnt_existNr   r   rJ   rJ   rK   
_is_mocked  s   
r	  )NNNc                  #   s`    t j dddtdtf dtttgtf  dtf fdd} | t _z	dV  W  t _dS  t _w )	zContext manager which replaces ``inspect.unwrap`` with a version
    that's aware of mock objects and doesn't recurse into them.Nstopfunc.r  r.   c             
      sj   z|d u s	|t u rt dW S |  fdddW S  ty4 } ztd|f t  d }~ww )Nr
  c                    s   t | p S rM   )r	  r  _stopr  rJ   rK   <lambda>  s    zF_patch_unwrap_mock_aware.<locals>._mock_aware_unwrap.<locals>.<lambda>zGot %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real_unwrapr  rK   _mock_aware_unwrap  s   z4_patch_unwrap_mock_aware.<locals>._mock_aware_unwrap)inspectunwrapr   r   r
   )r  rJ   r  rK   _patch_unwrap_mock_aware  s   
r  c                   @   s   e Zd Zdee fddZdS )rR   r.   c                 c   s    dd l }G dd d|j}| jjdkr&| jjj| j| jd| jjd}n)zt	| j| jj| jdd}W n t
yN   | jdrKtd	| j  n Y nw | }t| }td
|t t| jd}|||jD ]}|jrytj| |j||dV  qid S )Nr   c                       sR   e Zd ZdZ fddZ		d fddZejdk r$ fd	d
Z  Z	S 	   Z	S )z5DoctestModule.collect.<locals>.MockAwareDocTestFinderzA 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  ry   _find_lineno)rm   r   source_linesr{   rJ   rK   r    s   


zBDoctestModule.collect.<locals>.MockAwareDocTestFinder._find_linenor.   Nc              
      sP   t |rd S t  t ||||||| W d    d S 1 s!w   Y  d S rM   )r	  r  ry   _find)rm   testsr   ra   moduler   rj   seenr{   rJ   rK   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  ry   _from_module)rm   r#  objectr{   rJ   rK   r)    s
   zBDoctestModule.collect.<locals>.MockAwareDocTestFinder._from_moduler   )
rt   ru   rv   r   r  r!  r   version_infor)  r}   rJ   rJ   r{   rK   MockAwareDocTestFinder  s    

r,  zconftest.py
importmode)rootpath)rootmoderA   zunable to import module %rFr   r   )r   DocTestFinderrU   ra   rV   r   _importconftestri   r.  r"   ImportErrorr   r   r   r   r   r   findrt   r   r   r\   )rm   r   r,  r#  finderr   r   r   rJ   rJ   rK   r5     sH   9



zDoctestModule.collectN)rt   ru   rv   r   r   r5   rJ   rJ   rJ   rK   rR     s    rR   doctest_itemc                 C   sD   d	dd}i | _ | jj}|j| |ddd| _t| dd}|  |S )
zEUsed by DoctestTextfile and DoctestItem to setup fixture information.r.   Nc                   S   s   d S rM   rJ   rJ   rJ   rJ   rK   r  U  s   z_setup_fixtures.<locals>.funcF)noder  r   funcargsT)	_ispytestr   )r8  rg   _fixturemanagergetfixtureinfo_fixtureinfor   _fillfixtures)r6  r  fmr   rJ   rJ   rK   r   R  s   
r   c                     s*   dd l } dd l G  fddd| j}|S )Nr   c                       sp   e Zd ZdjZdjZdjZde	de	de
def fdd	Zde	de	de	f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 @ }|s!|s!|s!dS dtt dtdtffdd}|r>|| j|}|| j|}|rL|| j|}|| j|}|rT| 	||}t  |||S )NTFregexr_   r.   c                    s     | d|S )Nz\1\2)sub)r@  r_   rerJ   rK   remove_prefixes  s   zX_init_checker_class.<locals>.LiteralsOutputChecker.check_output.<locals>.remove_prefixes)
ry   check_outputr   r   r   r   rF   _unicode_literal_re_bytes_literal_re_remove_unwanted_precision)rm   r?  r   r   allow_unicodeallow_bytesallow_numberrD  )r|   rC  rJ   rK   rE    s"   


z?_init_checker_class.<locals>.LiteralsOutputChecker.check_outputc                 S   s  t | j|}t | j|}t|t|kr|S d}t||D ]h\}}|d}|d}	|	d u r8|d}	|d u r>dnt|}
|	d urL|
t|	8 }
t| tt| d|
  dkr|d |	 |  |  ||
 | d   }||
 |	  |
 |	   7 }q!|S )Nr   fraction	exponent1	exponent2
   )abs)list
_number_refinditerlenziprI   r   floatr$   startend)rm   r?  r   wantsgotsoffsetwgrL  exponent	precisionrJ   rJ   rK   rH    s&   


&.$zM_init_checker_class.<locals>.LiteralsOutputChecker._remove_unwanted_precision)rt   ru   rv   compileUNICODErF  rG  VERBOSErR  rF   r   r   rE  rH  r}   rJ   rB  r{   rK   LiteralsOutputCheckerf  s     rc  )r   rC  OutputChecker)r   rc  rJ   rB  rK   _init_checker_classb  s   Qre  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,   re  rJ   rJ   rJ   rK   r     s   r   c                  C      ddl } | dS )z+Register and return the ALLOW_UNICODE flag.r   Nr   r   register_optionflagr   rJ   rJ   rK   r        
r   c                  C   rf  )z)Register and return the ALLOW_BYTES flag.r   Nr   rg  r   rJ   rJ   rK   r     ri  r   c                  C   rf  )z$Register and return the NUMBER flag.r   Nr   rg  r   rJ   rJ   rK   r     ri  r   keyc              
   C   s,   ddl }t|jt|jt|jt|jt	di|  S )zReturn 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_UDIFFREPORT_UDIFFDOCTEST_REPORT_CHOICE_CDIFFREPORT_CDIFFDOCTEST_REPORT_CHOICE_NDIFFREPORT_NDIFF(DOCTEST_REPORT_CHOICE_ONLY_FIRST_FAILUREREPORT_ONLY_FIRST_FAILUREDOCTEST_REPORT_CHOICE_NONE)rj  r   rJ   rJ   rK   r     s   r   rg   )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   rJ   rJ   rJ   rK   r     s   r   r   r   )r   r   r.   N)r.   r+   )fr   r   r(  r  osr   r   r   r   r  
contextlibr   pathlibr   typingr   r   r   r   r   r	   r
   r   r   r   r   r   r   _pytestr   _pytest._code.coder   r   r   _pytest._ior   _pytest.compatr   _pytest.configr   _pytest.config.argparsingr   _pytest.fixturesr   r   _pytest.nodesr   r   _pytest.outcomesr   r   _pytest.pathlibr!   r"   _pytest.pythonr#   _pytest.python_apir$   _pytest.warning_typesr%   r   rs  rm  ro  rk  rq  rH   rN   r,   __annotations__rL   rO   r`   r   rZ   r]   r[   rk   r  rw   r   r   r   r   rF   r   r   r   rS   r   r*  r	  r  rR   r   re  r   r   r   r   r   r   rJ   rJ   rJ   rK   <module>   s    	
2

6
 	


	`
X