o
    Ú­jH  ã                
   @   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* ej+dd!… d"k rÏdd#l,m-Z- erãdd$l.m/Z/ dd%l0m1Z1 dd&l2m3Z3 d'ed(dfd)d*„Z4dbd-d.„Z5dcd1d2„Z6dcd3d4„Z7d5e$d6ee$ d(e8fd7d8„Z9	ddd5e$d:e8d6ee$ d(e
e fd;d<„Z:d5e$d(dfd=d>„Z;d5e$d(dfd?d@„Z<d5e$d(dfdAdB„Z=d5e$d6ee$ d(dfdCdD„Z>d5e$dEedF d(dfdGdH„Z?dIed(eee@e@e@f  fdJdK„ZA	9ded5e$dEdFd:e8d(efdLdM„ZBdNdOdIed(e8fdPdQ„ZCd5e$dEdFd(dRfdSdT„ZDedUd9dV�ZEeejFG dWdX„ dXe	eE ƒƒƒZGd5e$dNeGd d(efdYdZ„ZHd[e#d(efd\d]„ZIG d^d_„ d_ƒZJd[e#d(efd`da„ZKdS )fz3Basic collect and runtest protocol implementations.é    N)ÚCallable)Úcast)ÚDict)ÚGeneric)ÚList)ÚOptional)ÚTuple)ÚType)ÚTYPE_CHECKING)ÚTypeVar)ÚUnioné   )Ú
BaseReport)ÚCollectErrorRepr)ÚCollectReport)Ú
TestReport)Útiming)ÚExceptionChainRepr)ÚExceptionInfo)ÚTerminalRepr)Úfinal)ÚParser)Úcheck_ispytest)Ú	Collector)ÚItem)ÚNode)ÚExit)ÚOutcomeException)ÚSkipped)ÚTEST_OUTCOMEé   )é   é   )ÚBaseExceptionGroup)ÚLiteral)Ú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 reportingÚ	ReportingÚ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.)ÚgetgroupÚ	addoptionÚintÚfloat)r'   Úgroup© r8   úK/var/www/html/CropPilot/venv/lib/python3.10/site-packages/_pytest/runner.pyÚpytest_addoption2   s"   ú
úr:   Ú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 ]4\}}|d
k r{|j|k r{| d¡ | dt|ƒ| |f ¡  d S | |jd›d|jd›d|j› �¡ qYd S )NÚverboseÚdurationc                 S   s   | j S ©N)r=   )Úxr8   r8   r9   Ú<lambda>U   s    z)pytest_terminal_summary.<locals>.<lambda>T)ÚkeyÚreverseú=zslowest durationszslowest %s durationsr    Ú z>(%s durations < %gs hidden.  Use -vv to show these durations.)z02.2fzs z<8ú )ÚconfigÚoptionÚ	durationsÚdurations_minÚgetvalueÚstatsÚvaluesÚhasattrÚappendÚsortÚ	write_sepÚ	enumerater=   Ú
write_lineÚlenÚwhenÚnodeid)	r;   rH   rI   r<   ÚtrÚdlistÚreplistÚrepÚir8   r8   r9   Úpytest_terminal_summaryG   s>   



€þ
ÿÿ&ør[   Úsessionr%   c                 C   s   t ƒ | _d S r>   )Ú
SetupStateÚ_setupstate©r\   r8   r8   r9   Úpytest_sessionstartg   ó   r`   c                 C   s   | j  d ¡ d S r>   )r^   Úteardown_exactr_   r8   r8   r9   Úpytest_sessionfinishk   s   rc   ÚitemÚnextitemc                 C   s:   | j }|j| j| jd� t| |d� |j| j| jd� dS )N)rU   Úlocation©re   T)ÚihookÚpytest_runtest_logstartrU   rf   ÚruntestprotocolÚpytest_runtest_logfinish)rd   re   rh   r8   r8   r9   Úpytest_runtest_protocolo   s
   rl   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ÚsetupÚ	setupshowFÚ	setuponlyÚcallÚteardownrg   )
rM   rn   Ú_initrequestÚcall_and_reportÚpassedrF   Ú	getoptionÚshow_test_itemrN   Úfuncargs)rd   rm   re   Ú
hasrequestrY   Úreportsr8   r8   r9   rj   w   s   

rj   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)rd   ÚtwÚused_fixturesr8   r8   r9   rx   �   s   

rx   c                 C   s   t | dƒ | jj | ¡ d S )Nro   )Ú_update_current_test_varr\   r^   ro   )rd   r8   r8   r9   Úpytest_runtest_setup›   s   
rˆ   c              
   C   s‚   t | dƒ zt`t`t`W n	 ty   Y nw z|  ¡  W d S  ty@ } zt|ƒt_|t_|j	d us5J ‚|j	j
t_|‚d }~ww )Nrr   )r‡   ÚsysÚ	last_typeÚ
last_valueÚlast_tracebackÚAttributeErrorÚruntestÚ	Exceptionr/   Ú__traceback__Útb_next)rd   Úer8   r8   r9   Úpytest_runtest_call    s$   
ÿ

€ùr“   c                 C   s&   t | dƒ | jj |¡ t | d ƒ d S )Nrs   )r‡   r\   r^   rb   )rd   re   r8   r8   r9   Úpytest_runtest_teardown´   s   
r”   rT   z$Literal['setup', 'call', 'teardown']c                 C   sD   d}|r| j › d|› d�}| dd¡}|tj|< dS 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.
    ÚPYTEST_CURRENT_TESTz (ú)ú z(null)N)rU   ÚreplaceÚosÚenvironÚpop)rd   rT   Úvar_nameÚvaluer8   r8   r9   r‡   º   s   r‡   Úreportc                 C   s&   | j dv r| jr
dS | jrdS dS d S )N)ro   rs   )ÚerrorÚEÚERROR)ÚskippedÚsÚSKIPPED)rD   rD   rD   )rT   Úfailedr¢   ©rž   r8   r8   r9   Úpytest_report_teststatusË   s   
r§   c                 K   sT   t | |fi |¤Ž}| j}|j| |d�}|r|j|d� t||ƒr(|j| ||d� |S )N©rd   rr   r¦   ©Únoderr   rž   )Úcall_runtest_hookrh   Úpytest_runtest_makereportÚpytest_runtest_logreportÚcheck_interactive_exceptionÚpytest_exception_interact)rd   rT   rm   Úkwdsrr   Úhookrž   r8   r8   r9   ru   Û   s   
ru   rr   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.NFÚwasxfailT)ÚexcinforM   Ú
isinstancer�   r   ÚbdbÚBdbQuit)rr   rž   r8   r8   r9   r®   è   s   

r®   zCallInfo[None]c                    s~   |dkr	ˆj j‰ n|dkrˆj j‰ n|dkrˆj j‰ nJ d|› �ƒ‚tf}ˆj dd¡s1|tf7 }tj	‡ ‡‡fdd„||d	�S )
Nro   rr   rs   FzUnhandled runtest hook case: Úusepdbc                      s   ˆ ddˆiˆ¤ŽS )Nrd   r8   r8   r8   ©rh   rd   r°   r8   r9   r@     s    z#call_runtest_hook.<locals>.<lambda>)rT   Úreraise)
rh   rˆ   r“   r”   r   rF   rw   ÚKeyboardInterruptÚCallInfoÚ	from_call)rd   rT   r°   r¹   r8   r¸   r9   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< ded< d	d
œdee deee  de	de	de	ddde
ddfdd„Zedefdd„ƒZe	dddd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=   z/Literal['collect', 'setup', 'call', 'teardown']rT   F)Ú	_ispytestÚresultrÂ   r(   Nc                C   s0   t |ƒ || _|| _|| _|| _|| _|| _d S r>   )r   r¿   r³   rÀ   rÁ   r=   rT   )ÚselfrÃ   r³   rÀ   rÁ   r=   rT   rÂ   r8   r8   r9   Ú__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Ä   r8   r8   r9   rÃ   1  s   
zCallInfo.resultÚfunczCallable[[], TResult]r¹   .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=   rT   rÃ   r³   rÂ   )r   ÚtimeÚperf_counterÚBaseExceptionr   Úfrom_currentr´   r�   )ÚclsrÇ   rT   r¹   r³   rÀ   Úprecise_startrÃ   Úprecise_stopr=   rÁ   r8   r8   r9   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³   rT   r¿   rÆ   r8   r8   r9   Ú__repr__i  s   
zCallInfo.__repr__r>   )Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   r½   Ú__annotations__r   rÊ   r6   ÚboolrÅ   ÚpropertyrÃ   Úclassmethodr   r	   r   r¼   ÚstrrÐ   r8   r8   r8   r9   r»     sT   
 ÷þ
ýüûúù	÷

öúþýÿüù*r»   c                 C   s   t  | |¡S r>   )r   Úfrom_item_and_callr¨   r8   r8   r9   r¬   o  ra   r¬   Ú	collectorc                    s  t  ‡ fdd„d¡}d }|jsd}n\tg}tj d¡}|d ur%| |j¡ t	|jj
t|ƒƒrTd}ˆ  |jd¡}t	|tƒsBJ t|ƒƒ‚|j}|sIJ ‚t|jƒ|j|jf}nd}ˆ  |j¡}t|d	ƒslt	|tƒshJ ‚t|ƒ}|}|jst|jnd }	tˆ j|||	ƒ}
||
_|
S )
Nc                      s   t ˆ  ¡ ƒS r>   )ÚlistÚcollectr8   ©rÛ   r8   r9   r@   t  s    z,pytest_make_collect_report.<locals>.<lambda>rÝ   rv   Úunittestr¢   r~   r¥   Ú
toterminal)r»   r¼   r³   r   r‰   ÚmodulesÚgetrN   ÚSkipTestr´   r�   ÚtupleÚ_repr_failure_pyr   ÚreprÚ	reprcrashrÙ   ÚpathÚlinenoÚmessageÚrepr_failurerM   r   rÃ   r   rU   rr   )rÛ   rr   ÚlongreprÚoutcomeÚskip_exceptionsrß   Úr_ÚrÚ	errorinforÃ   rY   r8   rÞ   r9   Úpytest_make_collect_reports  s2   
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 )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(   Nc                 C   s
   i | _ d S r>   )ÚstackrÆ   r8   r8   r9   rÅ   Ò  s   
øzSetupState.__init__rd   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ó   ÚitemsrS   rs   ro   r   )rÄ   rd   Úneeded_collectorsÚcolÚ
finalizersÚexcr8   r8   r9   ro   Þ  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ó   rN   )rÄ   rú   rª   r8   r8   r9   Úaddfinalizeró  s   zSetupState.addfinalizerre   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 ‚|r‡t
d|ddd… ƒ‚|du r�| jr’J ‚dS 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Ü   ÚkeysrS   Úpopitemr›   r   rN   Úextendr#   )rÄ   re   rö   Ú
exceptionsrª   rø   Ú_Úthese_exceptionsÚfinr’   Úmsgr8   r8   r9   rb   ý  s<    
€ÿü
ð
ÿzSetupState.teardown_exact)r(   N)rÑ   rÒ   rÓ   rÔ   rÅ   r   ro   r   Úobjectr   rü   r   rb   r8   r8   r8   r9   r]   ’  s    
?
r]   c                 C   sN   | j }|j| d� |j| d�}|j dd ¡}|r%t||ƒr%|j| ||d� |S )NrÞ   rr   r©   )rh   Úpytest_collectstartrò   Ú__dict__r›   r®   r¯   )rÛ   rh   rY   rr   r8   r8   r9   Úcollect_one_node   s   r	  )r;   r&   r(   N)r\   r%   r(   N)TN)T)LrÔ   rµ   Údataclassesr™   r‰   Útypingr   r   r   r   r   r   r   r	   r
   r   r   r{   r   r   r   r   Ú_pytestr   Ú_pytest._code.coder   r   r   Ú_pytest.compatr   Ú_pytest.config.argparsingr   Ú_pytest.deprecatedr   Ú_pytest.nodesr   r   r   Ú_pytest.outcomesr   r   r   r   Úversion_infoÚexceptiongroupr#   Útyping_extensionsr$   Ú_pytest.mainr%   Ú_pytest.terminalr&   r:   r[   r`   rc   rÖ   rl   rj   rx   rˆ   r“   r”   r‡   rÙ   r§   ru   r®   r«   r½   Ú	dataclassr»   r¬   rò   r]   r	  r8   r8   r8   r9   Ú<module>   s¼    

 
	ÿÿÿÿ
þÿÿ
þ ÿÿÿÿ
þÿÿ
þ` 