o
    hWL                     @  s  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	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) ej*dk rddl+m,Z, erdd l-m.Z. dd!l/m0Z0 dgd&d'Z1dhd*d+Z2did.d/Z3did0d1Z4djd7d8Z5	dkdld<d=Z6dmd>d?Z7dmd@dAZ8dmdBdCZ9dndDdEZ:dodHdIZ;dpdMdNZ<	9dqdrdQdRZ=dsdUdVZ>edWd9dXZ?eej@G dYdZ dZee? ZAdtd\d]ZBdudadbZCG dcdd ddZDdudedfZEdS )vz3Basic collect and runtest protocol implementations.    )annotationsN)Callable)cast)final)Generic)Literal)TYPE_CHECKING)TypeVar   )
BaseReport)CollectErrorRepr)CollectReport)
TestReport)timing)ExceptionChainRepr)ExceptionInfo)TerminalRepr)Parser)check_ispytest)	Collector)	Directory)Item)Node)Exit)OutcomeException)Skipped)TEST_OUTCOME)      )BaseExceptionGroup)Session)TerminalReporterparserr   returnNonec                 C  s@   | j dddd}|jddtd ddd	 |jd
dtd ddd	 d S )Nzterminal reporting	Reportinggeneral)afterz--durationsstoreNz1Show N slowest setup/test durations (N=0 for all))actiontypedefaultmetavarhelpz--durations-minzcMinimal duration in seconds for inclusion in slowest list. Default: 0.005 (or 0.0 if -vv is given).)getgroup	addoptionintfloat)r"   group r4   O/var/www/html/openai_agents/venv/lib/python3.10/site-packages/_pytest/runner.pypytest_addoption2   s"   
r6   terminalreporterr!   c           
      C  s\  | j jj}| j jj}| j  }|d u rd S |d u r!|dk rdnd}| }g }|j D ]}|D ]}t|dr:|| q.q*|s@d S |j	dd dd |sR|
d	d
 n|
d	d| d |d | }t|D ]E\}}|j|k r|d dt||  d|dd}	| j jjd u r|	d7 }	|	d7 }	||	  d S ||jdd|jdd|j  qfd S )N   g{Gzt?g        durationc                 S  s   | j S N)r9   )xr4   r4   r5   <lambda>W   s    z)pytest_terminal_summary.<locals>.<lambda>T)keyreverse=zslowest durationszslowest z
 durations (z durations < gz	s hidden.z"  Use -vv to show these durations.)z02.2fzs z<8 )configoption	durationsdurations_minget_verbositystatsvalueshasattrappendsort	write_sep	enumerater9   
write_linelenwhennodeid)
r7   rG   rH   verbosetrdlistreplistrepimessager4   r4   r5   pytest_terminal_summaryG   sB   







&r\   sessionr    c                 C  s   t  | _d S r:   )
SetupState_setupstater]   r4   r4   r5   pytest_sessionstartj      ra   c                 C  s   | j d  d S r:   )r_   teardown_exactr`   r4   r4   r5   pytest_sessionfinishn   s   rd   itemr   nextitemItem | Noneboolc                 C  s:   | j }|j| j| jd t| |d |j| j| jd dS )N)rT   locationrf   T)ihookpytest_runtest_logstartrT   ri   runtestprotocolpytest_runtest_logfinish)re   rf   rk   r4   r4   r5   pytest_runtest_protocolr   s
   ro   Tloglist[TestReport]c                 C  s   t | d}|r| js|   t| d|}|g}|jr5| jddr%t|  | jdds5|t| d| | j	j
s=| j	jr?d }|t| d||d |rRd| _d | _|S )	N_requestsetup	setupshowF	setuponlycallteardownrj   )rL   rr   _initrequestcall_and_reportpassedrE   	getoptionshow_test_itemrM   r]   
shouldfail
shouldstopfuncargs)re   rp   rf   
hasrequestrY   reportsr4   r4   r5   rm   z   s"   

rm   c                 C  s^   | j  }|  |d || j tt| dg }|r)|dd| |	  dS )zAShow test function, parameters and the fixtures of the test item.z        fixturenamesz (fixtures used: {})z, N)
rE   get_terminal_writerlinewriterT   sortedgetattrformatjoinflush)re   twused_fixturesr4   r4   r5   r|      s   

r|   c                 C  s   t | d | jj|  d S )Nrs   )_update_current_test_varr]   r_   rs   )re   r4   r4   r5   pytest_runtest_setup   s   
r   c              
   C  s   t | d zt`t`t`tjdkrt`W n	 ty   Y nw z|   W d S  t	yN } zt
|t_|t_tjdkr=|t_|jd usDJ |jjt_ d }~ww )Nrv   )r      r   )r   sys	last_type
last_valuelast_tracebackversion_infolast_excAttributeErrorruntest	Exceptionr+   __traceback__tb_next)re   er4   r4   r5   pytest_runtest_call   s.   




r   c                 C  s&   t | d | jj| t | d  d S )Nrw   )r   r]   r_   rc   )re   rf   r4   r4   r5   pytest_runtest_teardown   s   
r   rS   +Literal['setup', 'call', 'teardown'] | Nonec                 C  sD   d}|r| j  d| d}|dd}|tj|< dS tj| dS )zUpdate :envvar:`PYTEST_CURRENT_TEST` to reflect the current item and stage.

    If ``when`` is None, delete ``PYTEST_CURRENT_TEST`` from the environment.
    PYTEST_CURRENT_TESTz (rC    z(null)N)rT   replaceosenvironpop)re   rS   var_namevaluer4   r4   r5   r      s   r   reportr   tuple[str, str, str] | Nonec                 C  s&   | j dv r| jr
dS | jrdS dS d S )N)rs   rw   )errorEERROR)skippedsSKIPPED)r@   r@   r@   )rS   failedr   r   r4   r4   r5   pytest_report_teststatus   s   
r   $Literal['setup', 'call', 'teardown']r   c                   s    j }|dkr|jn|dkr|jn|dkr|jnJ d| tf} jdds1|tf7 }tj	 fdd||d	}|j
 |d
}|rN|j|d t||r[|j ||d |S )Nrs   rv   rw   FzUnhandled runtest hook case: usepdbc                     s   dd iS )Nre   r4   r4   r4   re   kwdsruntest_hookr4   r5   r<      s    z!call_and_report.<locals>.<lambda>)rS   reraisere   rv   r   noderv   r   )rk   r   r   r   r   rE   r{   KeyboardInterruptCallInfo	from_callpytest_runtest_makereportpytest_runtest_logreportcheck_interactive_exceptionpytest_exception_interact)re   rS   rp   r   rk   r   rv   r   r4   r   r5   ry      s(   

ry   rv   CallInfo[object]c                 C  s8   | j du rdS t|drdS t| j jttjfrdS dS )zVCheck whether the call raised an exception that should be reported as
    interactive.NFwasxfailT)excinforL   
isinstancer   r   bdbBdbQuit)rv   r   r4   r4   r5   r      s   

r   TResult)	covariantc                   @  s|   e Zd ZU dZded< ded< ded< ded< ded	< d
ed< ddd#ddZed$ddZe	d%d&ddZ	d'd!d"Z
dS )(r   z/Result/Exception info of a function invocation.TResult | None_result#ExceptionInfo[BaseException] | Noner   r2   startstopr9   /Literal['collect', 'setup', 'call', 'teardown']rS   F)	_ispytestresultr   rh   r#   r$   c                C  s0   t | || _|| _|| _|| _|| _|| _d S r:   )r   r   r   r   r   r9   rS   )selfr   r   r   r   r9   rS   r   r4   r4   r5   __init__#  s   
zCallInfo.__init__r   c                 C  s$   | j durt| dtt| jS )zlThe return value of the call, if it didn't raise.

        Can only be accessed if excinfo is None.
        Nz has no valid result)r   r   r   r   r   r   r4   r4   r5   r   6  s   
zCallInfo.resultNfuncCallable[[], TResult]r   <type[BaseException] | tuple[type[BaseException], ...] | NoneCallInfo[TResult]c              	   C  st   d}t  }z| }W n ty%   t }|dur!t|j|r! d}Y nw | }| |jj	|j
j	|j|||ddS )a  Call func, wrapping the result in a CallInfo.

        :param func:
            The function to call. Called without arguments.
        :type func: Callable[[], _pytest.runner.TResult]
        :param when:
            The phase in which the function is called.
        :param reraise:
            Exception or exceptions that shall propagate if raised by the
            function, instead of being wrapped in the CallInfo.
        NT)r   r   r9   rS   r   r   r   )r   InstantBaseExceptionr   from_currentr   r   elapsedr   timer   seconds)clsr   rS   r   r   instantr   r9   r4   r4   r5   r   C  s(   
zCallInfo.from_callstrc                 C  s6   | j d u rd| jd| jdS d| jd| j dS )Nz<CallInfo when=z	 result: >z	 excinfo=)r   rS   r   r   r4   r4   r5   __repr__i  s   
zCallInfo.__repr__)r   r   r   r   r   r2   r   r2   r9   r2   rS   r   r   rh   r#   r$   )r#   r   r:   )r   r   rS   r   r   r   r#   r   )r#   r   )__name__
__module____qualname____doc____annotations__r   propertyr   classmethodr   r   r4   r4   r4   r5   r     s    
 %r   CallInfo[None]c                 C  s   t | |S r:   )r   from_item_and_callr   r4   r4   r5   r   o  rb   r   	collectorr   r   c                   s  d fdd}t j|dttfd}d }|jsd}n\tg}tjd}|d ur,|	|j
 t|jjt|r[d	} |jd
}t|tsIJ t||j}|sPJ t|j|j|jf}nd} |j}	t|	dsst|	tsoJ t|	}	|	}|js{|jnd }
t j|||
}||_|S )Nr#   list[Item | Collector]c                     sB   t  tr jjj j jd jj jdd t	 
 S )N
importmodeconsider_namespace_packages)rootpathr   )r   r   rE   pluginmanager_loadconftestmodulespathr{   r   getinilistcollectr4   r   r4   r5   r   t  s   

	z+pytest_make_collect_report.<locals>.collectr   )r   rz   unittestr   r   r   
toterminal)r#   r   )r   r   r   
SystemExitr   r   r   modulesgetrM   SkipTestr   r   tuple_repr_failure_pyr   repr	reprcrashr   r   linenor[   repr_failurerL   r   r   r   rT   rv   )r   r   rv   longreproutcomeskip_exceptionsr   r_r	errorinfor   rY   r4   r   r5   pytest_make_collect_reports  s8   

r  c                   @  s8   e Zd ZdZdddZddd	ZdddZdddZdS )r^   aE  Shared state for setting up/tearing down test items or collectors
    in a session.

    Suppose we have a collection tree as follows:

    <Session session>
        <Module mod1>
            <Function item1>
        <Module mod2>
            <Function item2>

    The SetupState maintains a stack. The stack starts out empty:

        []

    During the setup phase of item1, setup(item1) is called. What it does
    is:

        push session to stack, run session.setup()
        push mod1 to stack, run mod1.setup()
        push item1 to stack, run item1.setup()

    The stack is:

        [session, mod1, item1]

    While the stack is in this shape, it is allowed to add finalizers to
    each of session, mod1, item1 using addfinalizer().

    During the teardown phase of item1, teardown_exact(item2) is called,
    where item2 is the next item to item1. What it does is:

        pop item1 from stack, run its teardowns
        pop mod1 from stack, run its teardowns

    mod1 was popped because it ended its purpose with item1. The stack is:

        [session]

    During the setup phase of item2, setup(item2) is called. What it does
    is:

        push mod2 to stack, run mod2.setup()
        push item2 to stack, run item2.setup()

    Stack:

        [session, mod2, item2]

    During the teardown phase of item2, teardown_exact(None) is called,
    because item2 is the last item. What it does is:

        pop item2 from stack, run its teardowns
        pop mod2 from stack, run its teardowns
        pop session from stack, run its teardowns

    Stack:

        []

    The end!
    r#   r$   c                 C  s
   i | _ d S r:   )stackr   r4   r4   r5   r     s   
zSetupState.__init__re   r   c                 C  s   |  }| j D ]\}\}}||v sJ d|r"|d |d q	|t| jd D ]4}|| jvs5J |jgdf| j|< z|  W q, ty` } z| j| d ||jff| j|<  d}~ww dS )z4Setup objects along the collector chain to the item.z(previous item was not torn down properlyr   r
   N)		listchainr  itemswith_tracebackrR   rw   rs   r   r   )r   re   needed_collectorscol
finalizersexcr4   r4   r5   rs     s"   zSetupState.setup	finalizerCallable[[], object]r   r   c                 C  sN   |rt |tr	J t|sJ || jv sJ || jf| j| d | dS )zgAttach a finalizer to the given node.

        The node must be currently active in the stack.
        r   N)r   r   callabler  rM   )r   r  r   r4   r4   r5   addfinalizer  s   zSetupState.addfinalizerrf   rg   c              
   C  s(  |r|  pg }g }| jrqt| j |dt| j krnS| j \}\}}g }|rN| }z|  W n tyK }	 z||	 W Y d}	~	nd}	~	ww |s+t|dkrZ|	| n|rnd|}
|t
|
|ddd  | jst|dkr{|d |rt
d|ddd |du r| jrJ dS dS )zTeardown the current stack up until reaching nodes that nextitem
        also descends from.

        When nextitem is None (meaning we're at the last item), the entire
        stack is torn down.
        Nr
   zerrors while tearing down r   zerrors during test teardown)r  r  r   keysrR   popitemr   r   rM   extendr   )r   rf   r  
exceptionsr   r  _these_exceptionsfinr   msgr4   r4   r5   rc     s<    


zSetupState.teardown_exactN)r#   r$   re   r   r#   r$   )r  r  r   r   r#   r$   )rf   rg   r#   r$   )r   r   r   r   r   rs   r  rc   r4   r4   r4   r5   r^     s    
?


r^   c                 C  sN   | j }|j| d |j| d}|jdd }|r%t||r%|j| ||d |S )Nr   rv   r   )rk   pytest_collectstartr  __dict__r   r   r   )r   rk   rY   rv   r4   r4   r5   collect_one_node4  s   r$  )r"   r   r#   r$   )r7   r!   r#   r$   )r]   r    r#   r$   )re   r   rf   rg   r#   rh   )TN)re   r   rp   rh   rf   rg   r#   rq   r!  )re   r   rf   rg   r#   r$   )re   r   rS   r   r#   r$   )r   r   r#   r   )T)re   r   rS   r   rp   rh   r#   r   )rv   r   r   r   r#   rh   )re   r   rv   r   r#   r   )r   r   r#   r   )Fr   
__future__r   r   collections.abcr   dataclassesr   r   typestypingr   r   r   r   r   r	   r   r   r   r   r   _pytestr   _pytest._code.coder   r   r   _pytest.config.argparsingr   _pytest.deprecatedr   _pytest.nodesr   r   r   r   _pytest.outcomesr   r   r   r   r   exceptiongroupr   _pytest.mainr    _pytest.terminalr!   r6   r\   ra   rd   ro   rm   r|   r   r   r   r   r   ry   r   r   	dataclassr   r   r  r^   r$  r4   r4   r4   r5   <module>   s|   



#

	







[
3 