o
    v&iIM                     @  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* ddl'm+Z+ ej,dk rdd l-m.Z. erdd!l/m0Z0 dd"l1m2Z2 dmd'd(Z3dnd+d,Z4dod/d0Z5dod1d2Z6dpd8d9Z7	dqdrd=d>Z8dsd?d@Z9dsdAdBZ:dsdCdDZ;dtdEdFZ<dudIdJZ=dvdNdOZ>	:dwdxdRdSZ?dydWdXZ@dzd[d\ZAed]d:d^ZBeejCG d_d` d`eeB ZDd{dbdcZEd|dgdhZFG didj djZGd|dkdlZHdS )}z3Basic collect and runtest protocol implementations.    )annotationsN)Callable)cast)final)Generic)Literal)TYPE_CHECKING)TypeVar   )Config)
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 r5   T/var/www/html/karishye-ai-python/venv/lib/python3.10/site-packages/_pytest/runner.pypytest_addoption3   s"   
r7   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)r:   )xr5   r5   r6   <lambda>X   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	enumerater:   
write_linelenwhennodeid)
r8   rH   rI   verbosetrdlistreplistrepimessager5   r5   r6   pytest_terminal_summaryH   sB   







&r]   sessionr!   c                 C  s   t  | _d S r;   )
SetupState_setupstater^   r5   r5   r6   pytest_sessionstartk      rb   c                 C  s   | j d  d S r;   )r`   teardown_exactra   r5   r5   r6   pytest_sessionfinisho   s   re   itemr   nextitemItem | Noneboolc                 C  s:   | j }|j| j| jd t| |d |j| j| jd dS )N)rU   locationrg   T)ihookpytest_runtest_logstartrU   rj   runtestprotocolpytest_runtest_logfinish)rf   rg   rl   r5   r5   r6   pytest_runtest_protocols   s
   rp   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teardownrk   )rM   rs   _initrequestcall_and_reportpassedrF   	getoptionshow_test_itemrN   r^   
shouldfail
shouldstopfuncargs)rf   rq   rg   
hasrequestrZ   reportsr5   r5   r6   rn   {   s"   

rn   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)
rF   get_terminal_writerlinewriterU   sortedgetattrformatjoinflush)rf   twused_fixturesr5   r5   r6   r}      s   

r}   c                 C  s   t | d | jj|  d S )Nrt   )_update_current_test_varr^   r`   rt   )rf   r5   r5   r6   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 )Nrw   )r      r   )r   sys	last_type
last_valuelast_tracebackversion_infolast_excAttributeErrorruntest	Exceptionr,   __traceback__tb_next)rf   er5   r5   r6   pytest_runtest_call   s.   




r   c                 C  s&   t | d | jj| t | d  d S )Nrx   )r   r^   r`   rd   )rf   rg   r5   r5   r6   pytest_runtest_teardown   s   
r   rT   +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 (rD    z(null)N)rU   replaceosenvironpop)rf   rT   var_namevaluer5   r5   r6   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)rt   rx   )errorEERROR)skippedsSKIPPED)rA   rA   rA   )rT   failedr   r   r5   r5   r6   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j fdd|t jd}|j |d	}|rB|j	|d
 t
||rO|j ||d |S )Nrt   rw   rx   FzUnhandled runtest hook case: c                     s   dd iS )Nrf   r5   r5   r5   rf   kwdsruntest_hookr5   r6   r=      s    z!call_and_report.<locals>.<lambda>)rT   reraiserf   rw   r   noderw   r   )rl   r   r   r   CallInfo	from_callget_reraise_exceptionsrF   pytest_runtest_makereportpytest_runtest_logreportcheck_interactive_exceptionpytest_exception_interact)rf   rT   rq   r   rl   rw   r   r5   r   r6   rz      s&   
rz   rF   r   tuple[type[BaseException], ...]c                 C  s    t f}| dds|tf7 }|S )z@Return exception types that should not be suppressed in general.usepdbF)r   r|   KeyboardInterrupt)rF   r   r5   r5   r6   r     s   
r   rw   CallInfo[object]c                 C  s8   | j du rdS t|drdS t| j jttjB rdS dS )zVCheck whether the call raised an exception that should be reported as
    interactive.NFwasxfailT)excinforM   
isinstancer   r   bdbBdbQuit)rw   r   r5   r5   r6   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   r3   startstopr:   /Literal['collect', 'setup', 'call', 'teardown']rT   F)	_ispytestresultr   ri   r$   r%   c                C  s0   t | || _|| _|| _|| _|| _|| _d S r;   )r   r   r   r   r   r:   rT   )selfr   r   r   r   r:   rT   r   r5   r5   r6   __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   r5   r5   r6   r   ?  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   r:   rT   r   r   r   )r   InstantBaseExceptionr   from_currentr   r   elapsedr   timer   seconds)clsr   rT   r   r   instantr   r:   r5   r5   r6   r   L  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   rT   r   r   r5   r5   r6   __repr__r  s   
zCallInfo.__repr__)r   r   r   r   r   r3   r   r3   r:   r3   rT   r   r   ri   r$   r%   )r$   r   r;   )r   r   rT   r   r   r   r$   r   )r$   r   )__name__
__module____qualname____doc____annotations__r   propertyr   classmethodr   r   r5   r5   r5   r6   r     s    
 %r   CallInfo[None]c                 C  s   t | |S r;   )r   from_item_and_callr   r5   r5   r6   r   x  rc   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   rF   pluginmanager_loadconftestmodulespathr|   r   getinilistcollectr5   r   r5   r6   r   }  s   

	z+pytest_make_collect_report.<locals>.collectr   )r   r{   unittestr   r   r   
toterminal)r$   r   )r   r   r   
SystemExitr   r   r   modulesgetrN   SkipTestr   r   tuple_repr_failure_pyr   repr	reprcrashr   r   linenor\   repr_failurerM   r   r   r   rU   rw   )r   r   rw   longreproutcomeskip_exceptionsr   r_r	errorinfor   rZ   r5   r   r6   pytest_make_collect_report|  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   r5   r5   r6   r     s   
zSetupState.__init__rf   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_tracebackrS   rx   rt   r   r   )r   rf   needed_collectorscol
finalizersexcr5   r5   r6   rt     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  rN   )r   r  r   r5   r5   r6   addfinalizer  s   zSetupState.addfinalizerrg   rh   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   keysrS   popitemr   r   rN   extendr    )r   rg   r  
exceptionsr   r  _these_exceptionsfinr   msgr5   r5   r6   rd     s<    


zSetupState.teardown_exactN)r$   r%   rf   r   r$   r%   )r  r  r   r   r$   r%   )rg   rh   r$   r%   )r   r   r   r   r   rt   r  rd   r5   r5   r5   r6   r_     s    
?


r_   c                 C  sN   | j }|j| d |j| d}|jdd }|r%t||r%|j| ||d |S )Nr   rw   r   )rl   pytest_collectstartr  __dict__r   r   r   )r   rl   rZ   rw   r5   r5   r6   collect_one_node=  s   r'  )r#   r   r$   r%   )r8   r"   r$   r%   )r^   r!   r$   r%   )rf   r   rg   rh   r$   ri   )TN)rf   r   rq   ri   rg   rh   r$   rr   r$  )rf   r   rg   rh   r$   r%   )rf   r   rT   r   r$   r%   )r   r   r$   r   )T)rf   r   rT   r   rq   ri   r$   r   )rF   r   r$   r   )rw   r   r   r   r$   ri   )rf   r   rw   r   r$   r   )r   r   r$   r   )Ir   
__future__r   r   collections.abcr   dataclassesr   r   typestypingr   r   r   r   r   r	   rF   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"   r7   r]   rb   re   rp   rn   r}   r   r   r   r   r   rz   r   r   r   	dataclassr   r   r  r_   r'  r5   r5   r5   r6   <module>   s   



#

	








[
3 