o
    hf                     @  s"  U d 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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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l0m1Z1 ddl2m3Z3 ddl4m5Z5 ddl6m7Z7 erddl8Z8ddl9m:Z: dZ;d Z<d!Z=d"Z>d#Z?e;e<e=e>e?fZ@daAdaBd$eCd%< d~d*d+ZDdd,d-ZEdd3d4ZFdd7d8ZGdd;d<ZHdd=d>ZIG d?d@ d@eZJG dAdB dBeKZLddDdEZM				FdddOdPZNG dQdR dRe,ZOddTdUZPddVdWZQddXdYZRG dZd[ d[e3ZSdd^d_ZTddbdcZUe
ddedfZVG dgdh dhe3ZWddjdkZXddmdnZYddodpZZddqdrZ[ddsdtZ\ddwdxZ]e(dydzdd|d}Z^dS )z4Discover and run doctests in modules and test files.    )annotationsN)Callable)	Generator)Iterable)Sequence)contextmanager)Path)Any)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-   r3   choicesr4   z--doctest-globappendpatz2Doctests file matching pattern, default: test*.txtdoctestglob)r2   r-   metavarr3   r4   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 rD   P/var/www/html/openai_agents/venv/lib/python3.10/site-packages/_pytest/doctest.pypytest_addoptionF   s^   

rF   c                   C  s   d a d S N)RUNNER_CLASSrD   rD   rD   rE   pytest_unconfigurex   s   rI   	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optionr1   any_is_setup_py_is_main_pyDoctestModulefrom_parent_is_doctestDoctestTextfile)rJ   rK   rO   rD   rD   rE   pytest_collect_file~   s   

rY   rN   boolc                 C  s&   | j dkrdS |  }d|v pd|v S )Nzsetup.pyFs
   setuptoolss	   distutils)name
read_bytes)rN   contentsrD   rD   rE   rS      s   
rS   rO   r   c                   s@    j dv r|j rdS | dpdg}t fdd|D S )N)z.txtz.rstTr9   z	test*.txtc                 3  s    | ]}t | V  qd S rG   r   ).0globrM   rD   rE   	<genexpr>   s    z_is_doctest.<locals>.<genexpr>)rP   session
isinitpath	getoptionrR   )rO   rN   rK   globsrD   rM   rE   rW      s   rW   c                 C  s
   | j dkS )Nz__main__.py)r[   rM   rD   rD   rE   rT      s   
rT   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 rG   )rf   )selfrf   rD   rD   rE   __init__   s   
zReprFailDoctest.__init__twr   c                 C  s2   | j D ]\}}|D ]}|| q	|| qd S rG   )rf   line
toterminal)rh   rj   reprlocationlinesrk   rD   rD   rE   rl      s
   zReprFailDoctest.toterminalN)rf   rg   r'   r(   )rj   r   r'   r(   )__name__
__module____qualname__ri   rl   rD   rD   rD   rE   re      s    
re   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 rG   )superri   rs   rh   rs   	__class__rD   rE   ri      s   

z MultipleDoctestFailures.__init__)rs   rt   r'   r(   )ro   rp   rq   ri   __classcell__rD   rD   rw   rE   rr      s    rr   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_failurerZ   r'   r(   c                   s   t  j|||d || _d S )N)r{   r}   r   )ru   ri   r   )rh   r{   r}   r   r   rw   rD   rE   ri      s   
z8_init_runner_class.<locals>.PytestDoctestRunner.__init__testdoctest.DocTestexampledoctest.Examplegotr@   c                   s&     |||}| jr|| d S |rG   )DocTestFailurer   r7   )rh   outr   r   r   failuredoctestrD   rE   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   r7   )rh   r   r   r   r   r   r   rD   rE   report_unexpected_exception   s   
zK_init_runner_class.<locals>.PytestDoctestRunner.report_unexpected_exceptionNNr   T)
r{   r|   r}   r~   r   r   r   rZ   r'   r(   )r   r   r   r   r   r@   r'   r(   )r   r   r   r   r   r   r'   r(   )ro   rp   rq   __doc__ri   r   r   ry   rD   r   rw   rE   PytestDoctestRunner   s    
r   )r   DebugRunner)r   rD   r   rE   _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   )rH   r   r   rD   rD   rE   _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[   r@   rK   DoctestTextfile | DoctestModulerunnerr   dtestr   r'   r(   c                   sR   t  || || _|| _d | _| jj}|j| d d d}|| _|j	| _
|   d S )N)nodefunccls)ru   ri   r   r   objra   _fixturemanagergetfixtureinfo_fixtureinfonames_closurefixturenames_initrequest)rh   r[   rK   r   r   fmfixtureinforw   rD   rE   ri      s   zDoctestItem.__init__r   c                  s   t  j||||dS )zThe public named constructor.)r[   rK   r   r   )ru   rV   )r   rK   r[   r   r   rw   rD   rE   rV     s   zDoctestItem.from_parentc                 C  s   i | _ t| dd| _d S )NT)	_ispytest)funcargsr   _requestrh   rD   rD   rE   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   rd   update)rh   rd   r[   valuerD   rD   rE   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   runrr   rv   rD   rD   rE   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systemrO   pluginmanager	getpluginsuspend_global_captureread_global_capturesysstdoutwritestderr)rh   capmanr   errrD   rD   rE   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   r5   Fc                   s*   g | ]\}}| j  d  dd| qS )r   03d )lineno)r^   ixr   rD   rE   
<listcomp>c  s    z,DoctestItem.repr_failure.<locals>.<listcomp>	   z?EXAMPLE LOCATION UNKNOWN, not showing all tests of that examplez>>>z??? r   z...
zUNEXPECTED EXCEPTION: c                 S  s   g | ]}| d qS )r   )stripr^   r   rD   rD   rE   r   w  s    
)#r   r   r   r   r   rr   rs   ru   repr_failurer   r   filenamer   r,   ro   r   _get_checker_get_report_choicerO   rc   	docstring
splitlines	enumeratemaxsourcer7   output_differencer   splitr   from_exc_infor   	tracebackformat_exceptionre   )rh   r   r   rs   rf   r   r   r   r   messagerm   r{   report_choicern   indentrk   inner_excinforw   r   rE   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] )rN   r   r   r[   r   rD   rD   rE   
reportinfo}  s   zDoctestItem.reportinfo)
r[   r@   rK   r   r   r   r   r   r'   r(   )
rK   r   r[   r@   r   r   r   r   r'   r   r'   r(   )r   r   r'   r   )r'   r   )ro   rp   rq   ri   classmethodrV   r   r   r   r   r   r   ry   rD   rD   rw   rE   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   rD   rD   rE   _get_flag_lookup  s   r   c                 C  s.   |  d}t }d}|D ]}||| O }q|S )Nr)   r   )getinir   )rO   optionflags_strflag_lookup_tableflag_accflagrD   rD   rE   get_optionflags  s   
r  c                 C  s    |  d}|r|  drd}|S )Nr<   usepdbF)getvalue)rO   r   rD   rD   rE   _get_continue_on_failure  s
   

r  c                   @  s   e Zd ZdZdddZdS )rX   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.   ro   __main__Fr}   r   r{   r   r[   r   r   )r   rO   r   rN   	read_textr@   r[   r  r   r   r  DocTestParserget_doctestexamplesr   rV   )rh   r   encodingtextr   r[   rd   r   r   r&   r   rD   rD   rE   r/     s*   


zDoctestTextfile.collectr'   r  )ro   rp   rq   r   r/   rD   rD   rD   rE   rX     s    rX   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   rD   rE   r`     s    z%_check_all_skipped.<locals>.<genexpr>z!all tests skipped by +SKIP option)r   allr  r   )r   all_skippedrD   r   rE   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   rD   rD   rE   
_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 rG   )r  r  _stopr   rD   rE   <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!  rE   _mock_aware_unwrap  s   z4_patch_unwrap_mock_aware.<locals>._mock_aware_unwrap)r   r  r  r   r'   r	   )inspectunwrap)r*  rD   r(  rE   _patch_unwrap_mock_aware  s   r-  c                   @  s   e Zd ZdddZdS )rU   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,  ru   _find_lineno)rh   r   source_linesrw   rD   rE   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-  ru   _find)rh   testsr   r[   moduler8  rd   seenrw   rD   rE   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   ru   _from_module)rh   r<  r  rw   rD   rE   rA  )  s   zBDoctestModule.collect.<locals>.MockAwareDocTestFinder._from_moduler   )ro   rp   rq   r   version_infopy_ver_info_minormicrois_find_lineno_brokenr7  r:  rA  ry   rD   rD   rw   rE   MockAwareDocTestFinder  s    

rF  r;   zunable to import module Fr
  r  )r   DocTestFinderr   r   CollectErrorrO   r  r   rN   ra   r   parsefactoriesr  r   r   r  findro   r  r   rV   r[   )rh   r   rF  r<  finderr   r   r   rD   rD   rE   r/     s6   =


zDoctestModule.collectNr  )ro   rp   rq   r/   rD   rD   rD   rE   rU     s    rU   type[doctest.OutputChecker]c                  C  s   dd l } G dd d| j}|S )Nr   c                      sR   e Zd ZedejZedejZede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+)
              )
            )
            wantr@   r   r   r   r'   rZ   c                   s   t  |||r
dS |t @ }|t @ }|t @ }|s!|s!|s!dS d
dd	}|r4|| j|}|| j|}|rB|| j|}|| j|}|rJ| ||}t  |||S )NTFregexre.Pattern[str]txtr@   r'   c                 S  s   t | d|S )Nz\1\2)resub)rN  rP  rD   rD   rE   remove_prefixes~  s   zX_init_checker_class.<locals>.LiteralsOutputChecker.check_output.<locals>.remove_prefixes)rN  rO  rP  r@   r'   r@   )ru   check_outputr   r   r   _unicode_literal_re_bytes_literal_re_remove_unwanted_precision)rh   rM  r   r   allow_unicodeallow_bytesallow_numberrS  rw   rD   rE   rT  s  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ziprC   r   floatr   startend)rh   rM  r   wantsgotsoffsetwgr[  exponent	precisionrD   rD   rE   rW    s&   


&.$zM_init_checker_class.<locals>.LiteralsOutputChecker._remove_unwanted_precision)rM  r@   r   r@   r   r   r'   rZ   )rM  r@   r   r@   r'   r@   )ro   rp   rq   rQ  compileUNICODErU  rV  VERBOSEr`  rT  rW  ry   rD   rD   rw   rE   LiteralsOutputCheckerU  s    rq  )r   OutputChecker)r   rq  rD   rD   rE   _init_checker_classR  s   Qrs  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%   rs  rD   rD   rD   rE   r     s   r   c                  C     ddl } | dS )z+Register and return the ALLOW_UNICODE flag.r   Nr   r   register_optionflagr   rD   rD   rE   r        
r   c                  C  ru  )z)Register and return the ALLOW_BYTES flag.r   Nr   rv  r   rD   rD   rE   r     rx  r   c                  C  ru  )z$Register and return the NUMBER flag.r   Nr   rv  r   rD   rD   rE   r     rx  r   keyr@   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)ry  r   rD   rD   rE   r     s   r   ra   )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   rD   rD   rD   rE   r     s   r   )r&   r   r'   r(   r   )rJ   r   rK   r   r'   rL   )rN   r   r'   rZ   )rO   r   rN   r   rK   r   r'   rZ   )r'   rz   r   )
r{   r|   r}   r~   r   r   r   rZ   r'   r   )r'   r   )rO   r   r'   r   )rO   r   r'   rZ   )r   r   r'   r(   )r   r  r'   rZ   )r'   r  )r'   rL  )r'   rt  )r'   r   )ry  r@   r'   r   )r'   r  )_r   
__future__r   r   collections.abcr   r   r   r   
contextlibr   r?  r+  ospathlibr   r   rQ  r   r   typestypingr	   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~  rz  r  rB   rH   r%   __annotations__rF   rI   rY   rS   rW   rT   re   r$  rr   r   r   r   r   r  r  rX   r   r  r-  rU   rs  r   r   r   r   r   r   rD   rD   rD   rE   <module>   s   	

2




6 


	



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