U
    `»{jìK  ã                   @  sü  d 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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 �r|ddl*m+Z+ e�ršdd l,m-Z- dd!l.m/Z/ d"d#d$œd%d&„Z0d'd#d(œd)d*„Z1d+d#d,œd-d.„Z2d+d#d,œd/d0„Z3d1d2d3d4œd5d6„Z4dhd1d3d2d8d9œd:d;„Z5d1d#d<œd=d>„Z6d1d#d<œd?d@„Z7d1d#d<œdAdB„Z8d1d2d#d4œdCdD„Z9d1dEd#dFœdGdH„Z:dIdJdKœdLdM„Z;did1dNd3dOdPœdQdR„Z<dSdId3dTœdUdV„Z=edWd7dX�Z>eej?G dYdZ„ dZee> ƒƒƒZ@d1d[dOd\œd]d^„ZAd_d`daœdbdc„ZBG ddde„ deƒZCd_d`daœdfdg„ZDd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-ming{®Gázt?zJMinimal duration in seconds for inclusion in slowest list. Default: 0.005.)ZgetgroupZ	addoptionÚintÚfloat)r#   Úgroup© r0   úM/var/www/html/bwave/python/venv/lib/python3.8/site-packages/_pytest/runner.pyÚpytest_addoption2   s"    úúr2   r!   )Úterminalreporterr$   c           	      C  s.  | j jj}| j jj}| j  ¡ }|d kr*d S | }g }|j ¡ D ]"}|D ]}t|dƒrD| |¡ qDq<|shd S |j	dd„ dd� |sŒ| 
dd¡ n | 
dd|› d	�¡ |d |… }t|ƒD ]t\}}|d
k �r|j|k �r| d¡ | dt|ƒ| › d|d›d�¡  �q*| |jd›d|jd›d|j› �¡ q´d S )NÚdurationc                 S  s   | j S ©N)r4   )Úxr0   r0   r1   Ú<lambda>U   ó    z)pytest_terminal_summary.<locals>.<lambda>T)ÚkeyÚreverseú=zslowest durationszslowest z
 durationsé   Ú ú(z durations < Úgz,s hidden.  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Ú	enumerater4   Z
write_lineÚlenÚwhenÚnodeid)	r3   rC   rD   ÚverboseÚtrZdlistZreplistÚrepÚir0   r0   r1   Úpytest_terminal_summaryG   s4    




ÿrR   r    )Úsessionr$   c                 C  s   t ƒ | _d S r5   )Ú
SetupStateÚ_setupstate©rS   r0   r0   r1   Úpytest_sessionstartf   s    rW   c                 C  s   | j  d ¡ d S r5   )rU   Úteardown_exactrV   r0   r0   r1   Úpytest_sessionfinishj   s    rY   r   úItem | NoneÚbool)ÚitemÚnextitemr$   c                 C  s:   | j }|j| j| jd� t| |d� |j| j| jd� dS )N)rM   Úlocation©r]   T)ÚihookZpytest_runtest_logstartrM   r^   ÚruntestprotocolZpytest_runtest_logfinish)r\   r]   r`   r0   r0   r1   Úpytest_runtest_protocoln   s
    rb   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Úteardownr_   )rG   rd   Z_initrequestÚcall_and_reportÚpassedrA   Ú	getoptionÚshow_test_itemrH   rS   Z
shouldfailZ
shouldstopZfuncargs)r\   rc   r]   Z
hasrequestrP   Úreportsr0   r0   r1   ra   v   s"    

ra   ©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)
rA   Zget_terminal_writerÚlineÚwriterM   ÚsortedÚgetattrÚformatÚjoinÚflush)r\   ZtwZused_fixturesr0   r0   r1   rk   ’   s    

rk   c                 C  s   t | dƒ | jj | ¡ d S )Nre   )Ú_update_current_test_varrS   rU   re   )r\   r0   r0   r1   Úpytest_runtest_setupž   s    
rv   c              
   C  s¬   t | dƒ zt`t`t`tjdkr&t`W n tk
r<   Y nX z|  ¡  W n\ t	k
r¦ } z>t
|ƒt_|t_tjdkr||t_|jd k	sŠt‚|jjt_‚ W 5 d }~X Y nX d S )Nrf   )r   é   r   )ru   ÚsysÚ	last_typeÚ
last_valueÚlast_tracebackÚversion_infoÚlast_excÚAttributeErrorZruntestÚ	Exceptionr)   Ú__traceback__ÚAssertionErrorÚtb_next)r\   Úer0   r0   r1   Úpytest_runtest_call£   s&    




r„   c                 C  s&   t | dƒ | jj |¡ t | d ƒ d S )Nrg   )ru   rS   rU   rX   )r\   r]   r0   r0   r1   Úpytest_runtest_teardown»   s    
r…   z-Literal[('setup', 'call', 'teardown')] | None)r\   rL   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 (ú)ú z(null)N)rM   ÚreplaceÚosÚenvironÚpop)r\   rL   Úvar_nameÚvaluer0   r0   r1   ru   Á   s    ru   r   ztuple[str, str, str] | None)Úreportr$   c                 C  s&   | j dkr"| jrdS | jrdS dS d S )N)re   rg   )ÚerrorÚEÚERROR)ÚskippedÚsZSKIPPED)r=   r=   r=   )rL   Úfailedr’   ©rŽ   r0   r0   r1   Úpytest_report_teststatusÒ   s    
r–   z&Literal[('setup', 'call', 'teardown')]r   )r\   rL   rc   r$   c                   s¾   ˆ j }|dkr|j‰n2|dkr&|j‰n"|dkr6|j‰ndsHt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 )Nre   rf   rg   FzUnhandled runtest hook case: Zusepdbc                     s   ˆf dˆ iˆ—ŽS )Nr\   r0   r0   ©r\   ÚkwdsZruntest_hookr0   r1   r7   ò   r8   z!call_and_report.<locals>.<lambda>)rL   Úreraise©r\   rf   r•   ©Únoderf   rŽ   )r`   rv   r„   r…   r�   r   rA   rj   ÚKeyboardInterruptÚCallInfoÚ	from_callÚpytest_runtest_makereportZpytest_runtest_logreportÚcheck_interactive_exceptionÚpytest_exception_interact)r\   rL   rc   r˜   r`   r™   rf   rŽ   r0   r—   r1   rh   â   s,    
  ÿ
rh   zCallInfo[object])rf   rŽ   r$   c                 C  s8   | j dk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)ÚexcinforG   Ú
isinstancer�   r   ÚbdbZBdbQuit)rf   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Ústopr4   z1Literal[('collect', 'setup', 'call', 'teardown')]rL   F)Ú	_ispytestr[   r"   )Úresultr£   r©   rª   r4   rL   r«   r$   c                C  s0   t |ƒ || _|| _|| _|| _|| _|| _d S r5   )r   r¨   r£   r©   rª   r4   rL   )Úselfr¬   r£   r©   rª   r4   rL   r«   r0   r0   r1   Ú__init__  s    zCallInfo.__init__r¦   ©r$   c                 C  s$   | j dk	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¬   2  s    
zCallInfo.resultNzCallable[[], TResult]z<type[BaseException] | tuple[type[BaseException], ...] | NonezCallInfo[TResult])ÚfuncrL   r™   r$   c              	   C  s„   d}t  ¡ }t  ¡ }z
|ƒ }W n6 tk
rT   t ¡ }|dk	rLt|j|ƒrL‚ d}Y nX t  ¡ }|| }	t  ¡ }
| ||
|	|||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ª   r4   rL   r¬   r£   r«   )r   ÚtimeÚperf_counterÚBaseExceptionr   Zfrom_currentr¤   r�   )Úclsr±   rL   r™   r£   r©   Zprecise_startr¬   Zprecise_stopr4   rª   r0   r0   r1   rŸ   ?  s,    

ùzCallInfo.from_callÚstrc                 C  s6   | j d kr d| j›d| j›d�S d| j›d| j ›d�S )Nz<CallInfo when=z	 result: ú>z	 excinfo=)r£   rL   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\   rf   r$   c                 C  s   t  | |¡S r5   )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 k	r\| 	|j
¡ t|jjt|ƒƒrºd	}ˆ  |jd
¡}t|tƒs–tt|ƒƒ‚|j}|s¤t‚t|jƒ|j|jf}n4d}ˆ  |j¡}	t|	dƒsêt|	tƒsât‚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   rA   ZpluginmanagerZ_loadconftestmodulesÚpathrj   rÂ   ZgetiniÚlistÚcollectr0   ©rÀ   r0   r1   rÅ   t  s    

ÿü	z+pytest_make_collect_report.<locals>.collectrÅ   )r™   ri   Úunittestr’   rn   r”   Z
toterminal)rž   rŸ   r�   Ú
SystemExitr£   r   rx   ÚmodulesÚgetrH   ZSkipTestr¤   r�   ÚtupleZ_repr_failure_pyr   r�   ÚreprZ	reprcrashr¶   rÃ   ÚlinenoÚmessageZrepr_failurerG   r   r¬   r   rM   rf   )rÀ   rÅ   rf   ZlongreprZoutcomeZskip_exceptionsrÇ   Zr_ÚrZ	errorinfor¬   rP   r0   rÆ   r1   Úpytest_make_collect_reports  s<      ÿ
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 )rT   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 r5   )Ústackr°   r0   r0   r1   r®   æ  s    
øzSetupState.__init__r   rm   c                 C  sÒ   |  ¡ }| j ¡ D ]2\}\}}||ks.tdƒ‚|r|d  |d ¡‚q|t| jƒd… D ]t}|| jksjt‚|jgdf| j|< z| ¡  W qX tk
rÊ } z$| j| d ||j	ff| j|< ‚ W 5 d}~X Y qXX qXdS )z4Setup objects along the collector chain to the item.z(previous item was not torn down properlyr   r
   N)
Ú	listchainrÑ   Úitemsr�   Úwith_tracebackrK   rg   re   r   r€   )r­   r\   Úneeded_collectorsÚcolÚ
finalizersÚexcr0   r0   r1   re   ò  s    zSetupState.setupzCallable[[], object]r   )Ú	finalizerrœ   r$   c                 C  sN   |rt |tƒrt‚t|ƒst‚|| jks6t|| 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Ë   r�   ÚcallablerÑ   rH   )r­   rÙ   rœ   r0   r0   r1   Úaddfinalizer  s    zSetupState.addfinalizerrZ   )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k
r” }	 z| |	¡ W 5 d}	~	X Y qRX 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k�r | j�r t‚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Ä   ÚkeysrK   Úpopitemr‹   r   rH   Úextendr   r�   )r­   r]   rÕ   Ú
exceptionsrœ   r×   Ú_Zthese_exceptionsZfinrƒ   Úmsgr0   r0   r1   rX     s0     



zSetupState.teardown_exactN)r¹   rº   r»   r¼   r®   re   rÛ   rX   r0   r0   r0   r1   rT   ¦  s
   ?
rT   c                 C  sN   | j }|j| d� |j| d�}|j dd ¡}|rJt||ƒrJ|j| ||d� |S )NrÆ   rf   r›   )r`   Zpytest_collectstartrÐ   Ú__dict__r‹   r¡   r¢   )rÀ   r`   rP   rf   r0   r0   r1   Úcollect_one_node4  s    rä   )TN)T)Er¼   Ú
__future__r   r¥   Údataclassesr‰   rx   ÚtypesÚtypingr   r   r   r   r   r   r	   rl   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   rR   rW   rY   rb   ra   rk   rv   r„   r…   ru   r–   rh   r¡   r¦   Ú	dataclassrž   r    rÐ   rT   rä   r0   r0   r0   r1   Ú<module>   s|   	   ÿ ÿ_3 