o
    ZhoK                  
   @   s  d 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$ 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d# d$k rdd%l-m.Z. erdd&l/m0Z0 dd'l1m2Z2 d(ed)dfd*d+Z3d`d.d/Z4dad2d3Z5dad4d5Z6d6e%d7ee% d)e7fd8d9Z8	dbd6e%d;e7d7ee% d)ee fd<d=Z9d6e%d)dfd>d?Z:d6e%d)dfd@dAZ;d6e%d)dfdBdCZ<d6e%d7ee% d)dfdDdEZ=d6e%dFeedG  d)dfdHdIZ>dJed)eee?e?e?f  fdKdLZ@	:dcd6e%dFedG d;e7d)efdMdNZAdOdPdJed)e7fdQdRZBedSd:dTZCe	ejDG dUdV dVe
eC ZEd6e%dOeEd d)efdWdXZFdYe#d)efdZd[ZGG d\d] d]ZHdYe#d)efd^d_ZIdS )dz3Basic collect and runtest protocol implementations.    N)Callable)cast)Dict)final)Generic)List)Literal)Optional)Tuple)Type)TYPE_CHECKING)TypeVar)Union   )
BaseReport)CollectErrorRepr)CollectReport)
TestReport)timing)ExceptionChainRepr)ExceptionInfo)TerminalRepr)Parser)check_ispytest)	Collector)	Directory)Item)Node)Exit)OutcomeException)Skipped)TEST_OUTCOME   )      )BaseExceptionGroup)Session)TerminalReporterparserreturnc                 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 reportingZ	ReportingZgeneral)afterz--durationsstoreNz1Show N slowest setup/test durations (N=0 for all))actiontypedefaultmetavarhelpz--durations-ming{Gzt?zJMinimal duration in seconds for inclusion in slowest list. Default: 0.005.)ZgetgroupZ	addoptionintfloat)r(   group r5   E/var/www/html/lang_env/lib/python3.10/site-packages/_pytest/runner.pypytest_addoption4   s"   
r7   terminalreporterr'   c           	      C   s(  | j jj}| j jj}| j d}|d u rd S | }g }|j D ]}|D ]}t|dr/|| q#q|s5d S |j	dd dd |sG|
dd n|
dd	|  |d | }t|D ]8\}}|d
k r|j|k r|d |dt||  d|dd  d S ||jdd|jdd|j  qYd S )Nverbosedurationc                 S   s   | j S N)r:   )xr5   r5   r6   <lambda>W   s    z)pytest_terminal_summary.<locals>.<lambda>T)keyreverse=zslowest durationszslowest %s durationsr"    (z durations < gz,s hidden.  Use -vv to show these durations.)z02.2fzs z<8 )configoption	durationsdurations_mingetvaluestatsvalueshasattrappendsortZ	write_sep	enumerater:   Z
write_linelenwhennodeid)	r8   rG   rH   r9   trZdlistZreplistrepir5   r5   r6   pytest_terminal_summaryI   s:   




&rV   sessionr&   c                 C   s   t  | _d S r;   )
SetupState_setupstaterW   r5   r5   r6   pytest_sessionstarth      r[   c                 C   s   | j d  d S r;   )rY   teardown_exactrZ   r5   r5   r6   pytest_sessionfinishl   s   r^   itemnextitemc                 C   s:   | j }|j| j| jd t| |d |j| j| jd dS )N)rR   locationr`   T)ihookZpytest_runtest_logstartrR   ra   runtestprotocolZpytest_runtest_logfinish)r_   r`   rc   r5   r5   r6   pytest_runtest_protocolp   s
   re   Tlogc                 C   s   t | d}|r| js|   t| d|}|g}|jr5| jddr%t|  | jdds5|t| d| |t| d||d |rHd| _d | _	|S )	N_requestsetupZ	setupshowFZ	setuponlycallteardownrb   )
rL   rg   Z_initrequestcall_and_reportpassedrE   	getoptionshow_test_itemrM   Zfuncargs)r_   rf   r`   Z
hasrequestrT   reportsr5   r5   r6   rd   x   s   

rd   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        Zfixturenamesz (fixtures used: {})z, N)
rE   Zget_terminal_writerlinewriterR   sortedgetattrformatjoinflush)r_   ZtwZused_fixturesr5   r5   r6   rn      s   

rn   c                 C   s   t | d | jj|  d S )Nrh   )_update_current_test_varrW   rY   rh   )r_   r5   r5   r6   pytest_runtest_setup   s   
rx   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	yO } zt
|t_|t_tjdkr=|t_|jd usDJ |jjt_|d }~ww )Nri   )r#      r   )rw   sys	last_type
last_valuelast_tracebackversion_infolast_excAttributeErrorZruntest	Exceptionr.   __traceback__tb_next)r_   er5   r5   r6   pytest_runtest_call   s.   




r   c                 C   s&   t | d | jj| t | d  d S )Nrj   )rw   rW   rY   r]   )r_   r`   r5   r5   r6   pytest_runtest_teardown   s   
r   rQ   )rh   ri   rj   c                 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.
    ZPYTEST_CURRENT_TESTz () z(null)N)rR   replaceosenvironpop)r_   rQ   var_namevaluer5   r5   r6   rw      s   rw   reportc                 C   s&   | j dv r| jr
dS | jrdS dS d S )N)rh   rj   )errorEERROR)skippedsZSKIPPED)rA   rA   rA   )rQ   failedr   r   r5   r5   r6   pytest_report_teststatus   s   
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 )Nrh   ri   rj   FzUnhandled runtest hook case: Zusepdbc                      s   dd iS )Nr_   r5   r5   r5   r_   kwdsZruntest_hookr5   r6   r=      s    z!call_and_report.<locals>.<lambda>)rQ   reraiser_   ri   r   noderi   r   )rc   rx   r   r   r   rE   rm   KeyboardInterruptCallInfo	from_callpytest_runtest_makereportZpytest_runtest_logreportcheck_interactive_exceptionpytest_exception_interact)r_   rQ   rf   r   rc   r   ri   r   r5   r   r6   rk      s(   

rk   ri   z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.NFZwasxfailT)excinforL   
isinstancer   r    bdbZBdbQuit)ri   r   r5   r5   r6   r      s   

r   TResult)	covariantc                   @   s   e Zd ZU dZee ed< eee  ed< e	ed< e	ed< e	ed< e
d ed< d	d
dee deee  de	de	de	de
d deddfddZedefddZe	ddeg ef de
d deeee eee df f  ddfddZdefddZdS )r   z/Result/Exception info of a function invocation._resultr   startstopr:   )collectrh   ri   rj   rQ   F)	_ispytestresultr   r)   Nc                C   s0   t | || _|| _|| _|| _|| _|| _d S r;   )r   r   r   r   r   r:   rQ   )selfr   r   r   r   r:   rQ   r   r5   r5   r6   __init__  s   
zCallInfo.__init__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   0  s   
zCallInfo.resultfuncr   .zCallInfo[TResult]c              	   C   s   d}t  }t  }z| }W n ty)   t }|dur%t|j|r% d}Y nw t  }|| }	t  }
| ||
|	|||ddS )av  Call func, wrapping the result in a CallInfo.

        :param func:
            The function to call. Called without arguments.
        :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:   rQ   r   r   r   )r   timeperf_counterBaseExceptionr   Zfrom_currentr   r   )clsr   rQ   r   r   r   Zprecise_startr   Zprecise_stopr:   r   r5   r5   r6   r   =  s.   
zCallInfo.from_callc                 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   rQ   r   r   r5   r5   r6   __repr__h  s   
zCallInfo.__repr__r;   )__name__
__module____qualname____doc__r	   r   __annotations__r   r   r3   r   boolr   propertyr   classmethodr   r   r   r
   r   strr   r5   r5   r5   r6   r     sT   
 
	


*r   c                 C   s   t | |S r;   )r   Zfrom_item_and_callr   r5   r5   r6   r   n  r\   r   	collectorc                    s  dt tttf  f fdd}t|d}d }|jsd}n\tg}tj	
d}|d ur0||j t|jjt|r_d} |jd}t|tsMJ t||j}|sTJ t|j|j|jf}nd	} |j}	t|	d
swt|	tssJ t|	}	|	}|js|jnd }
t j|||
}||_|S )Nr)   c                      sB   t  tr jjj j jd jj jdd t	 
 S )NZ
importmodeconsider_namespace_packages)rootpathr   )r   r   rE   ZpluginmanagerZ_loadconftestmodulespathrm   r   Zgetinilistr   r5   r   r5   r6   r   s  s   

	z+pytest_make_collect_report.<locals>.collectr   rl   unittestr   rp   r   Z
toterminal)r   r   r   r   r   r   r   r    rz   modulesgetrM   ZSkipTestr   r   tupleZ_repr_failure_pyr   reprZ	reprcrashr   r   linenomessageZrepr_failurerL   r   r   r   rR   ri   )r   r   ri   ZlongreproutcomeZskip_exceptionsr   Zr_rZ	errorinfor   rT   r5   r   r6   pytest_make_collect_reportr  s4   
r   c                   @   s`   e Zd ZdZdddZdeddfddZd	eg ef d
e	ddfddZ
dee ddfddZdS )rX   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)   Nc                 C   s
   i | _ d S r;   )stackr   r5   r5   r6   r     s   
zSetupState.__init__r_   c                 C   s   |  }| j D ]\}\}}||v sJ d|r|q	|t| jd D ]2}|| jvs.J |jgdf| j|< z|  W q% tyW } z| j| d |f| j|< |d}~ww dS )z4Setup objects along the collector chain to the item.z(previous item was not torn down properlyNr   )	listchainr   itemsrP   rj   rh   r!   )r   r_   needed_collectorscol
finalizersexcr5   r5   r6   rh     s"   zSetupState.setup	finalizerr   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   r5   r5   r6   addfinalizer  s   zSetupState.addfinalizerr`   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   keysrP   popitemr   r!   rM   extendr%   )r   r`   r   
exceptionsr   r   _Zthese_exceptionsZfinr   msgr5   r5   r6   r]     s<    


zSetupState.teardown_exact)r)   N)r   r   r   r   r   r   rh   r   objectr   r   r	   r]   r5   r5   r5   r6   rX     s    
?
rX   c                 C   sN   | j }|j| d |j| d}|jdd }|r%t||r%|j| ||d |S )Nr   ri   r   )rc   Zpytest_collectstartr   __dict__r   r   r   )r   rc   rT   ri   r5   r5   r6   collect_one_node2  s   r   )r8   r'   r)   N)rW   r&   r)   N)TN)T)Jr   r   dataclassesr   rz   typingr   r   r   r   r   r   r   r	   r
   r   r   r   r   ro   r   r   r   r   Z_pytestr   Z_pytest._code.coder   r   r   Z_pytest.config.argparsingr   Z_pytest.deprecatedr   Z_pytest.nodesr   r   r   r   Z_pytest.outcomesr   r   r    r!   r~   Zexceptiongroupr%   Z_pytest.mainr&   Z_pytest.terminalr'   r7   rV   r[   r^   r   re   rd   rn   rx   r   r   rw   r   r   rk   r   r   	dataclassr   r   r   rX   r   r5   r5   r5   r6   <module>   s   


	


 
`2 