o
    #ife                     @   s  U d 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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l0m1Z1 ddl0m2Z2 dd l3m4Z4 dd!l5m6Z6 dd"l7m8Z8 dd#l9m:Z: erddl;Z;dd$lm<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/ZFdtd0d1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				FdudGed* dHeeI dIeQdJeId-dCf
dKdLZRG dMdN dNe/ZSd-eeTeQf fdOdPZUd:e'd-eQfdQdRZVd:e'd-eIfdSdTZWG dUdV dVe6ZXdvdYdZZYd[eZd-eIfd\d]Z[ed-ed^ fd_d`Z\G dadb dbe6Z]d-ed* fdcddZ^dwdedfZ_d-eQfdgdhZ`d-eQfdidjZad-eQfdkdlZbdmeTd-eQfdndoZce+dpdqd-eeTef fdrdsZddS )xz4Discover 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)
TopRequest)	Collector)Item)OutcomeException)skip
fnmatch_ex)Module)approx)PytestWarning)Self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 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 rJ   H/var/www/html/corbot_env/lib/python3.10/site-packages/_pytest/doctest.pypytest_addoptionI   s^   

rL   c                   C   s   d a d S N)RUNNER_CLASSrJ   rJ   rJ   rK   pytest_unconfigure{   s   rO   	file_pathparent)DoctestModuleDoctestTextfilec                 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optionr7   any_is_setup_py_is_main_pyrR   from_parent_is_doctestrS   )rP   rQ   rV   rJ   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)r_   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   )rj   )selfrj   rJ   rJ   rK   __init__   s   
zReprFailDoctest.__init__twc                 C   s2   | j D ]\}}|D ]}|| q	|| qd S rM   )rj   line
toterminal)rk   rm   reprlocationlinesrn   rJ   rJ   rK   ro      s
   zReprFailDoctest.toterminal)
__name__
__module____qualname__r   r   r   rF   rl   r   ro   rJ   rJ   rJ   rK   ri      s    
ri   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   )superrl   rv   rk   rv   	__class__rJ   rK   rl      s   

z MultipleDoctestFailures.__init__)rr   rs   rt   r   rl   __classcell__rJ   rJ   ry   rK   ru      s    "ru   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   )rw   rl   r   )rk   r}   r~   r   r   ry   rJ   rK   rl      s   
z8_init_runner_class.<locals>.PytestDoctestRunner.__init__testdoctest.DocTestexamplezdoctest.Examplegotc                    s&     |||}| jr|| d S |rM   )DocTestFailurer   r=   )rk   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=   )rk   r   r   r   r   r   r   rJ   rK   report_unexpected_exception   s   
zK_init_runner_class.<locals>.PytestDoctestRunner.report_unexpected_exceptionNNr   T)rr   rs   rt   __doc__r
   boolintrl   rF   r   r   r   BaseExceptiontypesTracebackTyper   r{   rJ   r   ry   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edddddddd	f
 fd
dZedddeddddddf
 fddZd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 )DoctestItemr_   rQ   z%Union[DoctestTextfile, DoctestModule]runnerr|   dtestr   r.   Nc                    sR   t  || || _|| _d | _| jj}|j| d d d}|| _|j	| _
|   d S )N)nodefunccls)rw   rl   r   r   objre   _fixturemanagergetfixtureinfo_fixtureinfonames_closurefixturenames_initrequest)rk   r_   rQ   r   r   fmfixtureinfory   rJ   rK   rl      s   zDoctestItem.__init__r%   c                   s   t  j||||dS )zThe public named constructor.)r_   rQ   r   r   )rw   r\   )r   rQ   r_   r   r   ry   rJ   rK   r\     s   zDoctestItem.from_parentc                 C   s   i | _ t| dd| _d S )NT)	_ispytest)funcargsr   _requestrk   rJ   rJ   rK   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   rh   update)rk   rh   r_   valuerJ   rJ   rK   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   runru   rx   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)rk   capmanr   errrJ   rJ   rK   r   4  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)rb   ixr   rJ   rK   
<listcomp>f  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rb   r   rJ   rJ   rK   r   z  s    
)$r   r   r   r   r   ru   rv   rw   repr_failurer   r   filenamer   r2   rr   r   _get_checker_get_report_choicerV   rg   	docstring
splitlines	enumeratemaxsourcer=   output_differencer   splitr   from_exc_infor   repr	tracebackformat_exceptionri   )rk   r   r   rv   rj   r   r   r   r   messagerp   r}   report_choicerq   indentrn   inner_excinfory   r   rK   r   @  sd   



 
zDoctestItem.repr_failurezos.PathLike[str]c                 C   s   | j | jjd| j fS )Nz[doctest] %s)rU   r   r   r_   r   rJ   rJ   rK   
reportinfo  s   zDoctestItem.reportinfor.   N)rr   rs   rt   rF   rl   classmethodr\   r   r   r   r   r   r   r   r   r   r   r
   r   r   r{   rJ   rJ   ry   rK   r      sD    





,@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   s.   |  d}t }d}|D ]}||| O }q|S )Nr/   r   )getinir   )rV   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| j}td|t	 t
| jd}| }	|	||||d}
|
jrLtj| |
j||
dV  d S d S )Nr   r4   rr   __main__Fr~   r   r}   r   r_   r   r   )r   rV   r   rU   	read_textrF   r_   r   r   r   r  DocTestParserget_doctestexamplesr   r\   )rk   r   encodingtextr   r_   rh   r   r   r-   r   rJ   rJ   rK   r5     s*   


zDoctestTextfile.collect)rr   rs   rt   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   rd     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stopr   .r  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 rM   )r  r  _stopr   rJ   rK   <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  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}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  qOd 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"  rw   _find_lineno)rk   r   source_linesry   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#  rw   _find)rk   testsr   r_   moduler*  rh   seenry   rJ   rK   r+    s   "z;DoctestModule.collect.<locals>.MockAwareDocTestFinder._find)      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   rw   _from_module)rk   r-  objectry   rJ   rK   r3  #  s   zBDoctestModule.collect.<locals>.MockAwareDocTestFinder._from_moduler   )
rr   rs   rt   r   r)  r+  r   version_infor3  r{   rJ   rJ   ry   rK   MockAwareDocTestFinder  s    

r6  rA   zunable to import module %rFr  r  )r   DocTestFinderr   r   CollectErrorrV   r  r   rU   re   r   parsefactoriesr   r   r   r  findrr   r
  r   r\   r_   )rk   r   r6  r-  finderr   r   r   rJ   rJ   rK   r5     s6   7


zDoctestModule.collectN)rr   rs   rt   r   r   r5   rJ   rJ   rJ   rK   rR     s    rR   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regextxtr.   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)
rw   check_outputr   r   r   r   rF   _unicode_literal_re_bytes_literal_re_remove_unwanted_precision)rk   r<  r   r   allow_unicodeallow_bytesallow_numberrB  )rz   rA  rJ   rK   rC  q  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)rk   r<  r   wantsgotsoffsetwgrJ  exponent	precisionrJ   rJ   rK   rF    s&   


&.$zM_init_checker_class.<locals>.LiteralsOutputChecker._remove_unwanted_precision)rr   rs   rt   compileUNICODErD  rE  VERBOSErP  rF   r   r   rC  rF  r{   rJ   r@  ry   rK   LiteralsOutputCheckerS  s     ra  )r   rA  OutputChecker)r   ra  rJ   r@  rK   _init_checker_classO  s   Qrc  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,   rc  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   rd  )z)Register and return the ALLOW_BYTES flag.r   Nr   re  r   rJ   rJ   rK   r     rg  r   c                  C   rd  )z$Register and return the NUMBER flag.r   Nr   re  r   rJ   rJ   rK   r     rg  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)rh  r   rJ   rJ   rK   r     s   r   re   )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+   )er   r   
contextlibr   r1  r!  ospathlibr   r   r   r   r   typingr   r   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!   _pytest.pythonr"   _pytest.python_apir#   _pytest.warning_typesr$   r   r%   rq  rk  rm  ri  ro  rH   rN   r,   __annotations__rL   rO   r^   r   rZ   r]   r[   ri   r  ru   r   r   r   r   rF   r   r   r  rS   r   r4  r  r#  rR   rc  r   r   r   r   r   r   rJ   rJ   rJ   rK   <module>   s   	
2

6
 	

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