a
    *ñ»jWL  ã                   @  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 �r|ddl+m,Z, e�ršdd l-m.Z. dd!l/m0Z0 d"d#d$œd%d&„Z1d'd#d(œd)d*„Z2d+d#d,œd-d.„Z3d+d#d,œd/d0„Z4d1d2d3d4œd5d6„Z5dhd1d3d2d8d9œd:d;„Z6d1d#d<œd=d>„Z7d1d#d<œd?d@„Z8d1d#d<œdAdB„Z9d1d2d#d4œdCdD„Z:d1dEd#dFœdGdH„Z;dIdJdKœdLdM„Z<did1dNd3dOdPœdQdR„Z=dSdId3dTœdUdV„Z>edWd7dX�Z?eej@G dYdZ„ dZee? ƒƒƒZAd1d[dOd\œd]d^„ZBd_d`daœdbdc„ZCG ddde„ deƒZDd_d`daœdfdg„ZEdS )jz3Basic 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)ÚTerminalReporterr   ÚNone)Ú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-minzcMinimal duration in seconds for inclusion in slowest list. Default: 0.005 (or 0.0 if -vv is given).)ZgetgroupZ	addoptionÚintÚfloat)r#   Úgroup© r0   ú4E:\soccer\ml_env\Lib\site-packages\_pytest/runner.pyÚpytest_addoption2   s"    úúr2   r!   )Úterminalreporterr$   c           
      C  s`  | j jj}| j jj}| j  ¡ }|d u r*d S |d u rB|dk r>dnd}| }g }|j ¡ D ]"}|D ]}t|dƒr\| |¡ q\qT|s€d S |j	dd„ dd� |s¤| 
d	d
¡ n | 
d	d|› d�¡ |d |… }t|ƒD ]Ž\}}|j|k �r6| d¡ dt|ƒ| › d|d›d�}	| j jjd u �r|	d7 }	|	d7 }	| |	¡  �q\| |jd›d|jd›d|j› �¡ qÌd S )Né   g{®Gázt?g        Údurationc                 S  s   | j S ©N)r5   )Úxr0   r0   r1   Ú<lambda>W   ó    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_minZget_verbosityÚstatsÚvaluesÚhasattrÚappendÚsortZ	write_sepÚ	enumerater5   Z
write_lineÚlenÚwhenÚnodeid)
r3   rD   rE   ÚverboseÚtrZdlistZreplistÚrepÚiÚmessager0   r0   r1   Úpytest_terminal_summaryG   s<    





rT   r    )Úsessionr$   c                 C  s   t ƒ | _d S r6   )Ú
SetupStateÚ_setupstate©rU   r0   r0   r1   Úpytest_sessionstartj   s    rY   c                 C  s   | j  d ¡ d S r6   )rW   Úteardown_exactrX   r0   r0   r1   Úpytest_sessionfinishn   s    r[   r   úItem | NoneÚbool)ÚitemÚnextitemr$   c                 C  s:   | j }|j| j| jd� t| |d� |j| j| jd� dS )N)rN   Úlocation©r_   T)ÚihookZpytest_runtest_logstartrN   r`   ÚruntestprotocolZpytest_runtest_logfinish)r^   r_   rb   r0   r0   r1   Úpytest_runtest_protocolr   s
    rd   Tzlist[TestReport])r^   Úlogr_   r$   c                 C  s¨   t | dƒ}|r| js|  ¡  t| d|ƒ}|g}|jrj| j dd¡rJt| ƒ | j dd¡sj| t| d|ƒ¡ | j	j
sz| j	jr~d }| t| d||d�¡ |r¤d| _d | _|S )	NÚ_requestÚsetupZ	setupshowFZ	setuponlyÚcallÚteardownra   )rH   rf   Z_initrequestÚcall_and_reportÚpassedrB   Ú	getoptionÚshow_test_itemrI   rU   Z
shouldfailZ
shouldstopZfuncargs)r^   re   r_   Z
hasrequestrQ   Úreportsr0   r0   r1   rc   z   s"    

rc   ©r^   r$   c                 C  s^   | j  ¡ }| ¡  | d¡ | | j¡ tt| dg ƒƒ}|rR| d d |¡¡¡ | 	¡  dS )zAShow test function, parameters and the fixtures of the test item.z        Zfixturenamesz (fixtures used: {})z, N)
rB   Zget_terminal_writerÚlineÚwriterN   ÚsortedÚgetattrÚformatÚjoinÚflush)r^   ZtwZused_fixturesr0   r0   r1   rm   –   s    

rm   c                 C  s   t | dƒ | jj | ¡ d S )Nrg   )Ú_update_current_test_varrU   rW   rg   )r^   r0   r0   r1   Ú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0 z|  ¡  W n^ t	y¦ } zFt
|ƒt_|t_tjdkrx|t_|jd us†J ‚|jjt_‚ W Y d }~n
d }~0 0 d S )Nrh   )r   é   r   )rw   ÚsysÚ	last_typeÚ
last_valueÚlast_tracebackÚversion_infoÚlast_excÚAttributeErrorZruntestÚ	Exceptionr)   Ú__traceback__Útb_next)r^   Úer0   r0   r1   Úpytest_runtest_call§   s&    




r…   c                 C  s&   t | dƒ | jj |¡ t | d ƒ d S )Nri   )rw   rU   rW   rZ   )r^   r_   r0   r0   r1   Úpytest_runtest_teardown¿   s    
r†   z+Literal['setup', 'call', 'teardown'] | None)r^   rM   r$   c                 C  sB   d}|r2| j › d|› d�}| dd¡}|tj|< ntj |¡ dS )zŸUpdate :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 (r@   ú z(null)N)rN   ÚreplaceÚosÚenvironÚpop)r^   rM   Úvar_nameÚvaluer0   r0   r1   rw   Å   s    rw   r   ztuple[str, str, str] | None)Úreportr$   c                 C  s&   | j dv r"| jrdS | jrdS dS d S )N)rg   ri   )ÚerrorÚEÚERROR)ÚskippedÚsZSKIPPED)r=   r=   r=   )rM   Úfailedr’   ©rŽ   r0   r0   r1   Úpytest_report_teststatusÖ   s    
r–   z$Literal['setup', 'call', 'teardown']r   )r^   rM   re   r$   c                   s¾   ˆ j }|dkr|j‰n2|dkr&|j‰n"|dkr6|j‰ndsHJ d|› �ƒ‚tf}ˆ j dd¡sf|tf7 }tj	‡ ‡‡fdd„||d	�}|j
ˆ |d
�}|r |j|d� t||ƒrº|jˆ ||d� |S )Nrg   rh   ri   FzUnhandled runtest hook case: Zusepdbc                     s   ˆf dˆ iˆ¤ŽS )Nr^   r0   r0   ©r^   ÚkwdsZruntest_hookr0   r1   r8   ö   r9   z!call_and_report.<locals>.<lambda>)rM   Úreraise©r^   rh   r•   ©Únoderh   rŽ   )rb   rx   r…   r†   r   rB   rl   ÚKeyboardInterruptÚCallInfoÚ	from_callÚpytest_runtest_makereportZpytest_runtest_logreportÚcheck_interactive_exceptionÚpytest_exception_interact)r^   rM   re   r˜   rb   r™   rh   rŽ   r0   r—   r1   rj   æ   s(    
ÿ
rj   zCallInfo[object])rh   rŽ   r$   c                 C  s8   | j du rdS t|dƒrdS t| j jttjfƒr4dS dS )zVCheck whether the call raised an exception that should be reported as
    interactive.NFZwasxfailT)ÚexcinforH   Ú
isinstancer�   r   ÚbdbZBdbQuit)rh   rŽ   r0   r0   r1   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ddd
dddœdd„Zeddœdd„ƒZed!dd
dddœdd„ƒZ	ddœdd „Z
dS )"rž   z/Result/Exception info of a function invocation.zTResult | NoneÚ_resultz#ExceptionInfo[BaseException] | Noner£   r.   ÚstartÚstopr5   z/Literal['collect', 'setup', 'call', 'teardown']rM   F)Ú	_ispytestr]   r"   )Úresultr£   r©   rª   r5   rM   r«   r$   c                C  s0   t |ƒ || _|| _|| _|| _|| _|| _d S r6   )r   r¨   r£   r©   rª   r5   rM   )Úselfr¬   r£   r©   rª   r5   rM   r«   r0   r0   r1   Ú__init__#  s    zCallInfo.__init__r¦   ©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­   r0   r0   r1   r¬   6  s    
zCallInfo.resultNzCallable[[], TResult]z<type[BaseException] | tuple[type[BaseException], ...] | NonezCallInfo[TResult])ÚfuncrM   r™   r$   c              	   C  st   d}t  ¡ }z
|ƒ }W n4 tyJ   t ¡ }|durBt|j|ƒrB‚ d}Y n0 | ¡ }| |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ª   r5   rM   r¬   r£   r«   )r   ZInstantÚBaseExceptionr   Zfrom_currentr¤   r�   Úelapsedr©   Útimerª   Úseconds)Úclsr±   rM   r™   r£   Zinstantr¬   r5   r0   r0   r1   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£   rM   r¨   r°   r0   r0   r1   Ú__repr__i  s    
zCallInfo.__repr__)N)Ú__name__Ú
__module__Ú__qualname__Ú__doc__Ú__annotations__r®   Úpropertyr¬   ÚclassmethodrŸ   r¹   r0   r0   r0   r1   rž     s   
÷  ü%rž   zCallInfo[None])r^   rh   r$   c                 C  s   t  | |¡S r6   )r   Zfrom_item_and_callrš   r0   r0   r1   r    o  s    r    r   r   )Ú	collectorr$   c                   s  ddœ‡ fdd„}t j|dttfd�}d }|js6d}n¸tg}tj d¡}|d ur\| 	|j
¡ t|jjt|ƒƒrºd	}ˆ  |jd
¡}t|tƒs–J t|ƒƒ‚|j}|s¤J ‚t|jƒ|j|jf}n4d}ˆ  |j¡}	t|	dƒsêt|	tƒsâJ ‚t|	ƒ}	|	}|jsú|jnd }
tˆ j|||
ƒ}||_|S )Nzlist[Item | Collector]r¯   c                     sB   t ˆ tƒr6ˆ jjjˆ jˆ j d¡ˆ jjˆ j d¡d� t	ˆ  
¡ ƒS )NZ
importmodeÚconsider_namespace_packages)ÚrootpathrÂ   )r¤   r   rB   ZpluginmanagerZ_loadconftestmodulesÚpathrl   rÃ   ZgetiniÚlistÚcollectr0   ©rÁ   r0   r1   rÆ   t  s    

ÿü	z+pytest_make_collect_report.<locals>.collectrÆ   )r™   rk   Úunittestr’   rp   r”   Z
toterminal)rž   rŸ   r�   Ú
SystemExitr£   r   rz   ÚmodulesÚgetrI   ZSkipTestr¤   r�   ÚtupleZ_repr_failure_pyr   ÚreprZ	reprcrashr·   rÄ   ÚlinenorS   Zrepr_failurerH   r   r¬   r   rN   rh   )rÁ   rÆ   rh   ZlongreprÚoutcomeZskip_exceptionsrÈ   Zr_ÚrZ	errorinfor¬   rQ   r0   rÇ   r1   Úpytest_make_collect_reports  s8    
ÿ
rÑ   c                   @  sP   e Zd ZdZddœdd„Zdddœdd	„Zd
dddœdd„Zdddœdd„ZdS )rV   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 r6   )Ústackr°   r0   r0   r1   r®   æ  s    
øzSetupState.__init__r   ro   c                 C  sÔ   |  ¡ }| j ¡ D ]2\}\}}||v s.J dƒ‚|r|d  |d ¡‚q|t| jƒd… D ]v}|| jvsjJ ‚|jgdf| j|< z| ¡  W qX tyÌ } z,| j| d ||jff| j|< ‚ W Y d}~qXd}~0 0 qXdS )z4Setup objects along the collector chain to the item.z(previous item was not torn down properlyr   r
   N)	Ú	listchainrÒ   ÚitemsÚwith_tracebackrL   ri   rg   r   r‚   )r­   r^   Úneeded_collectorsÚcolÚ
finalizersÚexcr0   r0   r1   rg   ò  s    zSetupState.setupzCallable[[], object]r   )Ú	finalizerrœ   r$   c                 C  sN   |rt |tƒrJ ‚t|ƒsJ ‚|| jv s6J || 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Ò   rI   )r­   rÚ   rœ   r0   r0   r1   Úaddfinalizer  s    zSetupState.addfinalizerr\   )r_   r$   c              
   C  s&  |r|  ¡ pg }g }| jrÜt| j ¡ ƒ|dt| jƒ… kr<qÜ| j ¡ \}\}}g }|rš| ¡ }z
|ƒ  W qR ty– }	 z| |	¡ W Y d}	~	qRd}	~	0 0 qRt|ƒdkr²| 	|¡ q|rd|›�}
| t
|
|ddd… ƒ¡ qt|ƒdkrò|d ‚n|�rt
d|ddd… ƒ‚|du �r"| j�r"J ‚dS )zÍTeardown 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Å   ÚkeysrL   Úpopitemr‹   r   rI   Úextendr   )r­   r_   rÖ   Ú
exceptionsrœ   rØ   Ú_Zthese_exceptionsZfinr„   Úmsgr0   r0   r1   rZ     s0     
"


zSetupState.teardown_exactN)rº   r»   r¼   r½   r®   rg   rÜ   rZ   r0   r0   r0   r1   rV   ¦  s
   ?
rV   c                 C  sN   | j }|j| d� |j| d�}|j dd ¡}|rJt||ƒrJ|j| ||d� |S )NrÇ   rh   r›   )rb   Zpytest_collectstartrÑ   Ú__dict__r‹   r¡   r¢   )rÁ   rb   rQ   rh   r0   r0   r1   Úcollect_one_node4  s    rå   )TN)T)Fr½   Ú
__future__r   r¥   Úcollections.abcr   Údataclassesr‰   rz   ÚtypesÚtypingr   r   r   r   r   r	   rn   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!   r2   rT   rY   r[   rd   rc   rm   rx   r…   r†   rw   r–   rj   r¡   r¦   Ú	dataclassrž   r    rÑ   rV   rå   r0   r0   r0   r1   Ú<module>   sz   #	 ÿ ÿ[3 