o
    h1K                     @  s,  d 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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	l*Z*ej+d	d dk rddl,m-Z- erdd	l.Z.dd	l/Z0ee1e2e3 e3ej4f e1d f Z5dHd&d'Z6G d(d) d)e%Z7G d*d+ d+e&Z8ed,d-dId3d4Z9dJd6d7Z:dKd8d9Z;G d:d; d;e
Z<dLd<d=Z=d>Z>ed,d?dMdAdBZ?dNdFdGZ@d	S )Oz4Discover and run std-library "unittest" style tests.    )annotations)Callable)	Generator)Iterable)Iterator)auto)EnumN)TYPE_CHECKING)Union)is_async_function)hookimpl)FixtureRequest)MonkeyPatch)	Collector)Item)exit)fail)skip)xfail)Class)Function)Module)CallInfo   )      )ExceptionGroup)NNN	collectorModule | ClassnamestrobjobjectreturnUnitTestCase | Nonec                 C  sT   zt jd }t||jsW d S W n
 ty   Y d S w t|r"d S tj| ||dS )Nunittest)r   r!   )	sysmodules
issubclassTestCase	Exceptioninspect
isabstractUnitTestCasefrom_parent)r   r   r!   ut r0   Q/var/www/html/openai_agents/venv/lib/python3.10/site-packages/_pytest/unittest.pypytest_pycollect_makeitem4   s   

r2   c                   @  s6   e Zd ZdZdd ZdddZdddZdddZdS )r-   Tc                 C  s
   |  dS )NrunTestr!   selfr0   r0   r1   newinstanceM   s   
zUnitTestCase.newinstancer#   Iterable[Item | Collector]c           
      c  s   ddl m} | j}t|ddsd S t|}|s&| | | | |   | jj	
|  | j | }d}|| jD ]}t| j|}t|ddsKq<tj| |dV  d}q<|s~t| jdd }|d urtjdd }	|	d u st||	jjkrtj| ddV  d S d S d S d S )	Nr   )
TestLoader__test__TF)r   r3   twisted.trial.unittest)r%   r9   r!   getattr_is_skipped'_register_unittest_setup_method_fixture&_register_unittest_setup_class_fixture_register_setup_class_fixturesession_fixturemanagerparsefactoriesr7   nodeidgetTestCaseNamesTestCaseFunctionr.   r&   r'   getr)   r3   )
r6   r9   clsskippedloaderfoundsomethingr   xruntestr/   r0   r0   r1   collectU   s8   

zUnitTestCase.collectrH   typeNonec                   s   t ddt dddu rdu rdS t ddd  dfd	d
d fdd}| jjjdj || jddd dS )zSRegister an auto-use fixture to invoke setUpClass and
        tearDownClass (#517).
setUpClassNtearDownClassdoClassCleanupsc                   S     d S Nr0   r0   r0   r0   r1   <lambda>{       zEUnitTestCase._register_unittest_setup_class_fixture.<locals>.<lambda>r#   rP   c                    s@   t  dd } | s
d S dd | D }t|dkr|d td|)NtearDown_exceptionsc                 S  s   g | ]\}}}|qS r0   r0   ).0_excr0   r0   r1   
<listcomp>   s    zlUnitTestCase._register_unittest_setup_class_fixture.<locals>.process_teardown_exceptions.<locals>.<listcomp>   r   zUnittest class cleanup errors)r<   lenr   )	exc_infos
exceptions)rH   r0   r1   process_teardown_exceptions}   s   
zXUnitTestCase._register_unittest_setup_class_fixture.<locals>.process_teardown_exceptionsrequestr   Generator[None]c                 3  s    | j }t|r|j}tjj|ddd ur+z  W n ty*         w d V  zd ur?  W      d S W      d S      w NT)_use_item_location)rH   r=   __unittest_skip_why__pytestr   r*   )rb   rH   reason)cleanupra   setupteardownr0   r1   unittest_setup_class_fixture   s0   


zYUnitTestCase._register_unittest_setup_class_fixture.<locals>.unittest_setup_class_fixture_unittest_setUpClass_fixture_classTr   funcrD   scopeautouser#   rP   rb   r   r#   rc   r<   rA   rB   _register_fixture__qualname__rD   )r6   rH   rl   r0   )ri   rH   ra   rj   rk   r1   r?   t   s   

z3UnitTestCase._register_unittest_setup_class_fixturec                   sb   t |dd t |dd du rdu rdS d fdd	}| jjjd
|j || jddd dS )zWRegister an auto-use fixture to invoke setup_method and
        teardown_method (#517).setup_methodNteardown_methodrb   r   r#   rc   c                 3  s\    | j }t|r|j}tjj|dd d ur || j d V  d ur,|| j d S d S rd   )instancer=   rf   rg   r   r*   function)rb   r6   rh   rj   rk   r0   r1   unittest_setup_method_fixture   s   z[UnitTestCase._register_unittest_setup_method_fixture.<locals>.unittest_setup_method_fixture_unittest_setup_method_fixture_r{   Tro   rt   ru   )r6   rH   r}   r0   r|   r1   r>      s   

z4UnitTestCase._register_unittest_setup_method_fixtureN)r#   r8   )rH   rO   r#   rP   )__name__
__module__rw   
nofuncargsr7   rN   r?   r>   r0   r0   r0   r1   r-   H   s    

8r-   c                      s   e Zd ZU dZdZded< dd Zedd Zd4 fddZ	d4 fddZ
d5ddZd6ddZd7ddZd7ddZd8ddZ	d9d:d d!Z	d;d<d#d$Zd5d%d&Zd5d'd(Zd=d+d,Zd4d-d.Zd> fd2d3Z  ZS )?rF   TNz7list[_pytest._code.ExceptionInfo[BaseException]] | None_excinfoc                 C  s   t | jtsJ | j| jS rU   )
isinstanceparentr-   r!   r   r5   r0   r0   r1   _getinstance   s   zTestCaseFunction._getinstancec                 C  s   | j S rU   )rz   r5   r0   r0   r1   	_testcase   s   zTestCaseFunction._testcaser#   rP   c                   s   d | _ t   d S rU   )_explicit_tearDownsuperrj   r5   	__class__r0   r1   rj      s   zTestCaseFunction.setupc                   s0   | j d ur|    d | _ d | _| `t   d S rU   )r   _obj	_instancer   rk   r5   r   r0   r1   rk      s   
zTestCaseFunction.teardowntestcaseunittest.TestCasec                 C  rT   rU   r0   r6   r   r0   r0   r1   	startTest      zTestCaseFunction.startTest
rawexcinfo_SysExcInfoTypec                 C  s   t |}ztjjt |}|j}|j}W nV tyk   z5ztj	| }|
dd td|dd W n tjtfy>     tyO   td|dd Y nw W n tyY     tjyh   tjj }Y nw Y nw | jdg | d S )Nr   zCNOTE: Incompatible Exception Representation, displaying natively:

 Fpytracez6ERROR: Unknown Incompatible Exception representation:
r   )_handle_twisted_exc_info_pytest_codeExceptionInfoBaseExceptionfrom_exc_infovalue	traceback	TypeErrorformat_exceptioninsertr   joinr*   KeyboardInterruptfrom_current__dict__
setdefaultappend)r6   r   excinforZ   valuesr0   r0   r1   _addexcinfo   sF   


zTestCaseFunction._addexcinfoc                 C  sD   zt |d tjrt|d j W n	 ty   Y nw | | d S )Nr]   )r   r   r*   msgr   r   r6   r   r   r0   r0   r1   addError  s   zTestCaseFunction.addErrorc                 C  s   |  | d S rU   )r   r   r0   r0   r1   
addFailure  s   zTestCaseFunction.addFailurerh   r    c                 C  s6   zt jj|dd tjy   | t  Y d S w rd   )rg   r   r*   r   r&   exc_info)r6   r   rh   r0   r0   r1   addSkip  s
   zTestCaseFunction.addSkipr   c                 C  s8   z	t t| W d S  t jy   | t  Y d S w rU   )r   r    r*   r   r&   r   )r6   r   r   rh   r0   r0   r1   addExpectedFailure   s
   z#TestCaseFunction.addExpectedFailure"twisted.trial.unittest.Todo | Nonec                 C  sP   d}|r|d|j  7 }z	t|dd W d S  tjy'   | t  Y d S w )NzUnexpected successz: Fr   )rh   r   r*   r   r&   r   )r6   r   rh   r   r0   r0   r1   addUnexpectedSuccess+  s   z%TestCaseFunction.addUnexpectedSuccessc                 C  rT   rU   r0   r   r0   r0   r1   
addSuccess9  r   zTestCaseFunction.addSuccessc                 C  rT   rU   r0   r   r0   r0   r1   stopTest<  r   zTestCaseFunction.stopTestelapsedfloatc                 C  rT   rU   r0   )r6   r   r   r0   r0   r1   addDuration?  r   zTestCaseFunction.addDurationc              	   C  s   ddl m} | j}|d usJ ||  t| jr|| d d S t| jts'J t| jp1t| jj}| j	
drF|sF|j| _t|ddd  t|| j| j z|| d W t|| j d S t|| j w )Nr   )&maybe_wrap_pytest_function_for_tracing)resultusepdbtearDownc                  W  rT   rU   r0   )argsr0   r0   r1   rV   Y  rW   z*TestCaseFunction.runtest.<locals>.<lambda>)_pytest.debuggingr   rz   r   r!   r   r   r-   r=   config	getoptionr   r   setattrr   delattr)r6   r   r   rI   r0   r0   r1   rM   B  s   
	zTestCaseFunction.runtestr   *_pytest._code.ExceptionInfo[BaseException]_pytest._code.Tracebackc                   s&   t  |}|dd }|s|}|S )Nc                 S  s   | j jd S )N
__unittest)frame	f_globalsrG   )rL   r0   r0   r1   rV   h      z4TestCaseFunction._traceback_filter.<locals>.<lambda>)r   _traceback_filterfilter)r6   r   r   
ntracebackr   r0   r1   r   c  s   z"TestCaseFunction._traceback_filterrs   )r   r   r#   rP   )r   r   r#   rP   )r   r   r   r   r#   rP   )r   r   rh   r    r#   rP   )r   )r   r   r   r   rh   r    r#   rP   rU   )r   r   rh   r   r#   rP   )r   r   r   r   r#   rP   )r   r   r#   r   )r   r   rw   r   r   __annotations__r   propertyr   rj   rk   r   r   r   r   r   r   r   r   r   r   rM   r   __classcell__r0   r0   r   r1   rF      s,   
 



"







!rF   T)tryfirstitemr   callCallInfo[None]rP   c                   s   t | tr| jr| jd|_z|`W n	 ty   Y nw tj	d}|rF|jrHt |jj
|jrJ|j td   fdd|j}|j|_d S d S d S d S )Nr   r%   c                     s   t t jS rU   )rg   r   r    r   r0   r   r0   r1   rV     r   z+pytest_runtest_makereport.<locals>.<lambda>)r   rF   r   popr   r   AttributeErrorr&   r'   rG   r   SkipTestr   	from_callwhen)r   r   r%   call2r0   r   r1   pytest_runtest_makereporto  s    
r   boolc                 C  s   t t| ddS )zDReturn True if the given object has been marked with @unittest.skip.__unittest_skip__F)r   r<   r4   r0   r0   r1   r=     s   r=   c                  C  s6   t  tjurddlm}  ddlm} |t|  dS dS )zRRegister the TestCaseFunction class as an IReporter if twisted.trial is available.r   )	IReporter)classImplementsN)_get_twisted_versionTwistedVersionNotInstalledtwisted.trial.itrialr   zope.interfacer   rF   )r   r   r0   r0   r1   pytest_configure  s
   r   c                   @  s"   e Zd ZdZe Ze Ze ZdS )r   z
    The Twisted version installed in the environment.

    We have different workarounds in place for different versions of Twisted.
    N)r   r   rw   __doc__r   	Version24	Version25r   r0   r0   r0   r1   r     s
    
r   c                  C  sN   dt jvrtjS dd l} dd l}| jd}|j|}|j	dkr$tj
S tjS )Nr;   r   twisted   )r&   r'   r   r   importlib.metadatapackaging.versionmetadataversionparsemajorr   r   )	importlib	packagingversion_strr   r0   r0   r1   r     s   

r   _twisted_raw_excinfo)wrapperIterator[None]c                 #  s    t  tju r=dd lm  m} |jj 	 d fdd	}t	 }|
|jd| d V W  d    S 1 s6w   Y  d S d V S )Nr   c                   s   |d u r	t  }n|d u rt|}|d u rt  d }|||f}t| tt| z | ||||d W d S  tyE    | ||| Y d S w )Nr   )captureVars)r&   r   rO   r   TWISTED_RAW_EXCINFO_ATTRtupler   )r6   	exc_valueexc_typeexc_tbr   raw_exc_infooriginal__init__r0   r1   store_raw_exception_info  s   


z9pytest_runtest_protocol.<locals>.store_raw_exception_info__init__)NNNN)r   r   r   twisted.python.failurepythonfailureFailurer   r   contextr   )r   r/   r   patcherr0   r   r1   pytest_runtest_protocol  s   
$r  r   _SysExcInfoType | BaseExceptionr   c                 C  s   t  }|tju r
| S |tju r"t| tr t| t}t| t |S | S |tju rPt	| t
rNddl}t	| |jjjrN| j}|du rEt d }t| j| j|fS | S J d| )z
    Twisted passes a custom Failure instance to `addError()` instead of using `sys.exc_info()`.
    Therefore, if `rawexcinfo` is a `Failure` instance, convert it into the equivalent `sys.exc_info()` tuple
    as expected by pytest.
    r   Nr   FzUnexpected Twisted version: )r   r   r   r   hasattrr   r<   r   r   r   r   r  r  r  r  __traceback__r&   r   rO   r   )r   twisted_versionsaved_exc_infor   tbr0   r0   r1   r     s&   






r   )r   r   r   r    r!   r"   r#   r$   )r   r   r   r   r#   rP   )r#   r   rs   )r#   r   )r   r   r#   r   )r   r  r#   r   )Ar   
__future__r   collections.abcr   r   r   r   enumr   r   r+   r&   r   typestypingr	   r
   _pytest._coder   _pytest.compatr   _pytest.configr   _pytest.fixturesr   _pytest.monkeypatchr   _pytest.nodesr   r   _pytest.outcomesr   r   r   r   _pytest.pythonr   r   r   _pytest.runnerr   rg   version_infoexceptiongroupr   r%   twisted.trial.unittestr   r   rO   r   TracebackTyper   r2   r-   rF   r   r=   r   r   r   r   r  r   r0   r0   r0   r1   <module>   sn   
  %

	
!