o
    rhf                     @  s&  U d Z ddlmZ ddlZddlmZ ddlZddlZddlZddl	m
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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/m0Z0 ddl1m2Z2 ddl3m4Z4 ddl5m6Z6 erddl7Z7ddl8m9Z9 d Z:d!Z;d"Z<d#Z=d$Z>e:e;e<e=e>fZ?da@daAd%eBd&< dd+d,ZCdd-d.ZDdd4d5ZEdd8d9ZFdd<d=ZGdd>d?ZHG d@dA dAeZIG dBdC dCeJZKddEdFZL				GdddPdQZMG dRdS dSe+ZNddUdVZOddWdXZPddYdZZQG d[d\ d\e2ZRdd_d`ZSddcddZTeddfdgZUG dhdi die2ZVddkdlZWddndoZXddpdqZYddrdsZZddtduZ[ddxdyZ\e'dzd{dd}d~Z]dS )z4Discover and run doctests in modules and test files.    )annotationsN)contextmanager)Path)Any)Callable)	Generator)Iterable)Pattern)Sequence)TYPE_CHECKING)outcomes)ExceptionInfo)ReprFileLocation)TerminalRepr)TerminalWritersafe_getattr)Config)Parser)fixture)
TopRequest)	Collector)Item)OutcomeException)skip
fnmatch_ex)Module)approx)PytestWarning)Selfnonecdiffndiffudiffonly_first_failurez"type[doctest.OutputChecker] | NoneCHECKER_CLASSparserr   returnNonec                 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)r.   collectz--doctest-modules
store_trueFzRun doctests in all .py modulesdoctestmodules)actionr.   helpdestz--doctest-reportr$   z9Choose another output format for diffs on doctest failuredoctestreport)r-   r.   r4   choicesr5   z--doctest-globappendpatz2Doctests file matching pattern, default: test*.txtdoctestglob)r3   r.   metavarr4   r5   z--doctest-ignore-import-errorsz Ignore doctest collection errors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 rE   M/var/www/html/alpaca_bot/venv/lib/python3.10/site-packages/_pytest/doctest.pypytest_addoptionF   s^   

rG   c                   C  s   d a d S N)RUNNER_CLASSrE   rE   rE   rF   pytest_unconfigurex   s   rJ   	file_pathr   parentr   &DoctestModule | DoctestTextfile | Nonec                 C  s\   |j }| jdkr|jjrtt| t| fstj|| dS d S t	|| |r,t
j|| dS d S )Nz.pypath)configsuffixoptionr2   any_is_setup_py_is_main_pyDoctestModulefrom_parent_is_doctestDoctestTextfile)rK   rL   rP   rE   rE   rF   pytest_collect_file~   s   

rZ   rO   boolc                 C  s&   | j dkrdS |  }d|v pd|v S )Nzsetup.pyFs
   setuptoolss	   distutils)name
read_bytes)rO   contentsrE   rE   rF   rT      s   
rT   rP   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globrN   rE   rF   	<genexpr>   s    z_is_doctest.<locals>.<genexpr>)rQ   session
isinitpath	getoptionrS   )rP   rO   rL   globsrE   rN   rF   rX      s   rX   c                 C  s
   | j dkS )Nz__main__.py)r\   rN   rE   rE   rF   rU      s   
rU   c                   @  s    e Zd ZdddZdd	d
ZdS )ReprFailDoctestreprlocation_lines0Sequence[tuple[ReprFileLocation, Sequence[str]]]r(   r)   c                 C  s
   || _ d S rH   )rg   )selfrg   rE   rE   rF   __init__   s   
zReprFailDoctest.__init__twr   c                 C  s2   | j D ]\}}|D ]}|| q	|| qd S rH   )rg   line
toterminal)ri   rk   reprlocationlinesrl   rE   rE   rF   rm      s
   zReprFailDoctest.toterminalN)rg   rh   r(   r)   )rk   r   r(   r)   )__name__
__module____qualname__rj   rm   rE   rE   rE   rF   rf      s    
rf   c                      s   e Zd Zd fddZ  ZS )MultipleDoctestFailuresfailures Sequence[doctest.DocTestFailure]r(   r)   c                   s   t    || _d S rH   )superrj   rt   ri   rt   	__class__rE   rF   rj      s   

z MultipleDoctestFailures.__init__)rt   ru   r(   r)   )rp   rq   rr   rj   __classcell__rE   rE   rx   rF   rs      s    rs   type[doctest.DocTestRunner]c                    s"   dd l  G  fddd j} | S )Nr   c                      sH   e Zd ZdZ				dd fddZdfddZd 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checkerdoctest.OutputChecker | Noneverbosebool | Noneoptionflagsintcontinue_on_failurer[   r(   r)   c                   s   t  j|||d || _d S )N)r|   r~   r   )rv   rj   r   )ri   r|   r~   r   r   rx   rE   rF   rj      s   
z8_init_runner_class.<locals>.PytestDoctestRunner.__init__testdoctest.DocTestexampledoctest.ExamplegotrA   c                   s&     |||}| jr|| d S |rH   )DocTestFailurer   r8   )ri   outr   r   r   failuredoctestrE   rF   report_failure   s   z>_init_runner_class.<locals>.PytestDoctestRunner.report_failureexc_info>tuple[type[BaseException], BaseException, types.TracebackType]c                   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   r8   )ri   r   r   r   r   r   r   rE   rF   report_unexpected_exception   s   
zK_init_runner_class.<locals>.PytestDoctestRunner.report_unexpected_exceptionNNr   T)
r|   r}   r~   r   r   r   r   r[   r(   r)   )r   r   r   r   r   rA   r(   r)   )r   r   r   r   r   r   r(   r)   )rp   rq   rr   __doc__rj   r   r   rz   rE   r   rx   rF   PytestDoctestRunner   s    
r   )r   DebugRunner)r   rE   r   rF   _init_runner_class   s   /r   Tr|   r}   r~   r   r   r   r   doctest.DocTestRunnerc                 C  s   t d u rt a t | |||dS )Nr|   r~   r   r   )rI   r   r   rE   rE   rF   _get_runner   s   r   c                      sp   e Zd Zd  fddZed! fddZd"ddZd"ddZd"ddZd"ddZ	d# fddZ
d$ddZ  ZS )%DoctestItemr\   rA   rL   DoctestTextfile | DoctestModulerunnerr   dtestr   r(   r)   c                   sR   t  || || _|| _d | _| jj}|j| d d d}|| _|j	| _
|   d S )N)nodefunccls)rv   rj   r   r   objrb   _fixturemanagergetfixtureinfo_fixtureinfonames_closurefixturenames_initrequest)ri   r\   rL   r   r   fmfixtureinforx   rE   rF   rj      s   zDoctestItem.__init__r    c                  s   t  j||||dS )zThe public named constructor.)r\   rL   r   r   )rv   rW   )r   rL   r\   r   r   rx   rE   rF   rW     s   zDoctestItem.from_parentc                 C  s   i | _ t| dd| _d S )NT)	_ispytest)funcargsr   _requestri   rE   rE   rF   r     s   zDoctestItem._initrequestc                 C  sL   | j   t| j jd}| j d D ]\}}|||< q| jj| d S )N)
getfixturedoctest_namespace)r   _fillfixturesdictgetfixturevalueitemsr   re   update)ri   re   r\   valuerE   rE   rF   setup   s
   

zDoctestItem.setupc                 C  s8   t | j |   g }| jj| j|d |rt|d S )N)r   )_check_all_skippedr   $_disable_output_capturing_for_darwinr   runrs   rw   rE   rE   rF   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systemrP   pluginmanager	getpluginsuspend_global_captureread_global_capturesysstdoutwritestderr)ri   capmanr   errrE   rE   rF   r   1  s   z0DoctestItem._disable_output_capturing_for_darwinexcinfoExceptionInfo[BaseException]str | TerminalReprc                   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|jg7 }|dd t j!|j D 7 }||
|f q-t"|S )Nr   r   r6   Fc                   s&   g | ]\}}d | j  d |f qS )z%03d %sr   )lineno)r_   ixr   rE   rF   
<listcomp>c  s    z,DoctestItem.repr_failure.<locals>.<listcomp>	   z?EXAMPLE LOCATION UNKNOWN, not showing all tests of that examplez>>>z???  z...
zUNEXPECTED EXCEPTION: c                 S  s   g | ]}| d qS )r   )stripr_   r   rE   rE   rF   r   w  s    
)#r   r   r   r   r   rs   rt   rv   repr_failurer   r   filenamer   r-   rp   r   _get_checker_get_report_choicerP   rd   	docstring
splitlines	enumeratemaxsourcer8   output_differencer   splitr   from_exc_infor   	tracebackformat_exceptionrf   )ri   r   r   rt   rg   r   r   r   r   messagern   r|   report_choicero   indentrl   inner_excinforx   r   rF   r   =  sd   



 
zDoctestItem.repr_failure.tuple[os.PathLike[str] | str, int | None, str]c                 C  s   | j | jjd| j fS )Nz
[doctest] )rO   r   r   r\   r   rE   rE   rF   
reportinfo}  s   zDoctestItem.reportinfo)
r\   rA   rL   r   r   r   r   r   r(   r)   )
rL   r   r\   rA   r   r   r   r   r(   r    r(   r)   )r   r   r(   r   )r(   r   )rp   rq   rr   rj   classmethodrW   r   r   r   r   r   r   rz   rE   rE   rx   rF   r      s    




@r   dict[str, int]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   rE   rE   rF   _get_flag_lookup  s   r   c                 C  s.   |  d}t }d}|D ]}||| O }q|S )Nr*   r   )getinir   )rP   optionflags_strflag_lookup_tableflag_accflagrE   rE   rF   get_optionflags  s   
r  c                 C  s    |  d}|r|  drd}|S )Nr=   usepdbF)getvalue)rP   r   rE   rE   rF   _get_continue_on_failure  s
   

r  c                   @  s   e Zd ZdZdddZdS )rY   Nr(   Iterable[DoctestItem]c                 c  s    dd l }| jd}| j|}t| j}| jj}ddi}t| j}td|t	 t
| jd}| }	|	||||d}
|
jrLtj| |
j||
dV  d S d S )Nr   r/   rp   __main__Fr~   r   r|   r   r\   r   r   )r   rP   r   rO   	read_textrA   r\   r  r   r   r  DocTestParserget_doctestexamplesr   rW   )ri   r   encodingtextr   r\   re   r   r   r'   r   rE   rE   rF   r0     s*   


zDoctestTextfile.collectr(   r  )rp   rq   rr   r   r0   rE   rE   rE   rF   rY     s    rY   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   rE   rF   ra     s    z%_check_all_skipped.<locals>.<genexpr>z!all tests skipped by +SKIP option)r   allr  r   )r   all_skippedrE   r   rF   r     s
   r   r   objectc                 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   rE   rE   rF   
_is_mocked  s   
r  Generator[None]c                  #  s>    t j ddd 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stopr   Callable[..., Any]r  Callable[[Any], Any] | Noner(   r   c             
     sp   z|d u s	|t u rt dW S |  fdddW S  ty7 } ztd|ddt  d }~ww )Nr  c                   s   t | p S rH   )r  r  _stopr   rE   rF   <lambda>  s    zF_patch_unwrap_mock_aware.<locals>._mock_aware_unwrap.<locals>.<lambda>zGot z when unwrapping z.  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!  rF   _mock_aware_unwrap  s   z4_patch_unwrap_mock_aware.<locals>._mock_aware_unwrap)r   r  r  r   r(   r   )inspectunwrap)r*  rE   r(  rF   _patch_unwrap_mock_aware  s   r-  c                   @  s   e Zd ZdddZdS )rV   r(   r  c                 c  s    dd l }G dd d|j}z| j}W n tjy-   | jdr*td| j n Y nw | j	j
|  | }t| j}td|t t| jd}|||jD ]}|jr`tj| |j||dV  qPd S )	Nr   c                      s   e Zd Zejdd Zedk p"edkoejjdk p"edko"ejjdk Zer+ fddZejd	k r7d fddZ	ejdk rF fddZ
  ZS   ZS )z5DoctestModule.collect.<locals>.MockAwareDocTestFinderN   )      r   )r/     r/  c                   s8   t |trt|d|}t|drt|}t ||S )a%  On older Pythons, doctest code does not take into account
                    `@property`. https://github.com/python/cpython/issues/61648

                    Moreover, wrapped Doctests need to be unwrapped so the correct
                    line number is returned. #8796
                    fget__wrapped__)r   propertygetattrhasattrr+  r,  rv   _find_lineno)ri   r   source_linesrx   rE   rF   r7    s   


zBDoctestModule.collect.<locals>.MockAwareDocTestFinder._find_lineno)r/  
   r(   r)   c              
     sP   t |rdS t  t ||||||| W d   dS 1 s!w   Y  dS )zOverride _find to work around issue in stdlib.

                    https://github.com/pytest-dev/pytest/issues/3456
                    https://github.com/python/cpython/issues/69718
                    N)r  r-  rv   _find)ri   testsr   r\   moduler8  re   seenrx   rE   rF   r:    s   "z;DoctestModule.collect.<locals>.MockAwareDocTestFinder._find)r/     c                   s    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
                    )r   	functoolscached_propertyr   rv   _from_module)ri   r<  r  rx   rE   rF   rA  )  s   zBDoctestModule.collect.<locals>.MockAwareDocTestFinder._from_moduler   )rp   rq   rr   r   version_infopy_ver_info_minormicrois_find_lineno_brokenr7  r:  rA  rz   rE   rE   rx   rF   MockAwareDocTestFinder  s    

rF  r<   zunable to import module Fr
  r  )r   DocTestFinderr   r   CollectErrorrP   r  r   rO   rb   r   parsefactoriesr  r   r   r  findrp   r  r   rW   r\   )ri   r   rF  r<  finderr   r   r   rE   rE   rF   r0     s6   =


zDoctestModule.collectNr  )rp   rq   rr   r0   rE   rE   rE   rF   rV     s    rV   type[doctest.OutputChecker]c                    s*   dd l } dd l G  fddd| j}|S )Nr   c                      sT   e Zd ZdjZdjZdjZd fddZ	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+)
              )
            )
            wantrA   r   r   r   r(   r[   c                   s   t  |||r
dS |t @ }|t @ }|t @ }|s!|s!|s!dS d
fdd	}|r6|| j|}|| j|}|rD|| j|}|| j|}|rL| ||}t  |||S )NTFregexPattern[str]txtrA   r(   c                   s     | d|S )Nz\1\2)sub)rN  rP  rerE   rF   remove_prefixes  s   zX_init_checker_class.<locals>.LiteralsOutputChecker.check_output.<locals>.remove_prefixes)rN  rO  rP  rA   r(   rA   )rv   check_outputr   r   r   _unicode_literal_re_bytes_literal_re_remove_unwanted_precision)ri   rM  r   r   allow_unicodeallow_bytesallow_numberrT  )ry   rS  rE   rF   rU  t  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	exponent2r9  )abs)list
_number_refinditerlenziprD   r   floatr   startend)ri   rM  r   wantsgotsoffsetwgr\  exponent	precisionrE   rE   rF   rX    s&   


&.$zM_init_checker_class.<locals>.LiteralsOutputChecker._remove_unwanted_precision)rM  rA   r   rA   r   r   r(   r[   )rM  rA   r   rA   r(   rA   )rp   rq   rr   compileUNICODErV  rW  VERBOSEra  rU  rX  rz   rE   rR  rx   rF   LiteralsOutputCheckerV  s    rr  )r   rS  OutputChecker)r   rr  rE   rR  rF   _init_checker_classR  s   Qrt  doctest.OutputCheckerc                   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&   rt  rE   rE   rE   rF   r     s   r   c                  C     ddl } | dS )z+Register and return the ALLOW_UNICODE flag.r   Nr   r   register_optionflagr   rE   rE   rF   r        
r   c                  C  rv  )z)Register and return the ALLOW_BYTES flag.r   Nr   rw  r   rE   rE   rF   r     ry  r   c                  C  rv  )z$Register and return the NUMBER flag.r   Nr   rw  r   rE   rE   rF   r     ry  r   keyrA   c              
   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)rz  r   rE   rE   rF   r     s   r   rb   )scopedict[str, Any]c                   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   rE   rE   rE   rF   r     s   r   )r'   r   r(   r)   r   )rK   r   rL   r   r(   rM   )rO   r   r(   r[   )rP   r   rO   r   rL   r   r(   r[   )r(   r{   r   )
r|   r}   r~   r   r   r   r   r[   r(   r   )r(   r   )rP   r   r(   r   )rP   r   r(   r[   )r   r   r(   r)   )r   r  r(   r[   )r(   r  )r(   rL  )r(   ru  )r(   r   )rz  rA   r(   r   )r(   r  )^r   
__future__r   r   
contextlibr   r?  r+  ospathlibr   r   r   r   typestypingr   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   _pytest.pythonr   _pytest.python_apir   _pytest.warning_typesr   r   typing_extensionsr    r  r}  r  r{  r  rC   rI   r&   __annotations__rG   rJ   rZ   rT   rX   rU   rf   r$  rs   r   r   r   r   r  r  rY   r   r  r-  rV   rt  r   r   r   r   r   r   rE   rE   rE   rF   <module>   s   	

2




6 


	



	
^
X



