
    pjK                       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/ dVd&Z0dWd)Z1dXd,Z2dXd-Z3dYd3Z4	 dZd[d7Z5d\d8Z6d\d9Z7d\d:Z8d]d;Z9d^d>Z:d_dBZ;	 d`dadEZ<dbdHZ= edId4J          Z>eej?         G dK dLee>                                           Z@dcdNZAdddRZB G dS dT          ZCdddUZDdS )ez3Basic 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)TerminalReporterparserr   returnNonec                    |                      ddd          }|                    ddt          d dd	           |                    d
dt          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{Gzt?zJMinimal duration in seconds for inclusion in slowest list. Default: 0.005.)getgroup	addoptionintfloat)r#   groups     ^/lsinfo/ai/hellotax_ai/data_center/backend/venv/lib/python3.11/site-packages/_pytest/runner.pypytest_addoptionr7   2   s    OO0+YOOOE	OO@     
OO          terminalreporterr"   c                   | j         j        j        }| j         j        j        }| j                                         }|d S | }g }|j                                        D ],}|D ]'}t          |d          r|                    |           (-|sd S |	                    d d           |s|
                    dd           n$|
                    dd| d           |d |         }t          |          D ]\  }}|d	k     rP|j        |k     rE|                    d
           |                    dt          |          |z
   d|dd            d S |                    |j        dd|j        dd|j                    d S )Ndurationc                    | j         S N)r;   )xs    r6   <lambda>z)pytest_terminal_summary.<locals>.<lambda>U   s    QZ r8   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_minget_verbositystatsvalueshasattrappendsort	write_sep	enumerater;   
write_linelenwhennodeid)	r9   rJ   rK   verbosetrdlistreplistrepis	            r6   pytest_terminal_summaryr^   G   s    '.8I$+2@M%3355G	BE8??$$ " " 	" 	"CsJ'' "S!!!	"  	JJ''J666 "
S-....
S:Y:::;;;jyj!E"" K K3Q;;3<-77MM"MMnCJJNnnnnnn   EE
IIIsxIIISZIIJJJJK Kr8   sessionr!   c                ,    t                      | _        d S r=   )
SetupState_setupstater_   s    r6   pytest_sessionstartrd   f   s    $,,Gr8   c                :    | j                             d            d S r=   )rb   teardown_exactrc   s    r6   pytest_sessionfinishrg   j   s    &&t,,,,,r8   itemr   nextitemItem | Noneboolc                    | j         }|                    | j        | j                   t	          | |           |                    | j        | j                   dS )N)rW   locationri   T)ihookpytest_runtest_logstartrW   rm   runtestprotocolpytest_runtest_logfinish)rh   ri   ro   s      r6   pytest_runtest_protocolrs   n   s[    JE	!!t}!MMMD8,,,,	""$+"NNN4r8   Tloglist[TestReport]c                   t          | d          }|r| j        s|                                  t          | d|          }|g}|j        ri| j                            dd          rt          |            | j                            dd          s$|                    t          | d|                     | j	        j
        s| j	        j        rd }|                    t          | d||                     |rd| _        d | _        |S )	N_requestsetup	setupshowF	setuponlycallteardownrn   )rO   rw   _initrequestcall_and_reportpassedrH   	getoptionshow_test_itemrP   r_   
shouldfail
shouldstopfuncargs)rh   rt   ri   
hasrequestr\   reportss         r6   rq   rq   v   s    z**J $-  	
$
-
-CeG
z ?;  e44 	!4   {$$[%88 	?NN?4==>>> | $,"9 NN?4S8LLLMMM  Nr8   c                   | 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)
rH   get_terminal_writerlinewriterW   sortedgetattrformatjoinflush)rh   twused_fixturess      r6   r   r      s    		(	(	*	*BGGIIIHHWHHT[74<<==M J
'..tyy/G/GHHIIIHHJJJJJr8   c                d    t          | d           | j        j                            |            d S )Nrx   )_update_current_test_varr_   rb   rx   )rh   s    r6   pytest_runtest_setupr      s1    T7+++L""4(((((r8   c                   t          | d           	 t          `t          `t          `t          j        dk    rt          `n# t          $ r Y nw xY w	 |                                  d S # t          $ rf}t          |          t          _        |t          _        t          j        dk    r|t          _        |j        J |j        j        t          _         d }~ww xY w)Nr{   )r      r   )r   sys	last_type
last_valuelast_tracebackversion_infolast_excAttributeErrorruntest	Exceptionr-   __traceback__tb_next)rh   es     r6   pytest_runtest_callr      s    T6***MNz))    	 	 	Qz))CL***_4	s(   ,? 
AAA& &
C0A!CCc                    t          | d           | j        j                            |           t          | d            d S )Nr|   )r   r_   rb   rf   )rh   ri   s     r6   pytest_runtest_teardownr      sA    T:...L++H555T4(((((r8   rV   +Literal['setup', 'call', 'teardown'] | Nonec                    d}|r4| 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 () z(null)N)rW   replaceosenvironpop)rh   rV   var_namevalues       r6   r   r      sh     %H !;))$)))fh//$
8

x     r8   reportr   tuple[str, str, str] | Nonec                @    | j         dv r| j        rdS | j        rdS dS d S )N)rx   r|   )errorEERROR)skippedsSKIPPED)rD   rD   rD   )rV   failedr   r   s    r6   pytest_report_teststatusr      s:    {+++= 	((^ 	,,:4r8   $Literal['setup', 'call', 'teardown']r   c                     j         }|dk    r|j        n)|dk    r|j        n|dk    r|j        nJ d|             t          f} j                            dd          s|t          fz  }t          	                     fd||          }|
                     |	          }|r|                    |
           t          ||          r|                     ||           |S )Nrx   r{   r|   FzUnhandled runtest hook case: usepdbc                      dd iS )Nrh    r   )rh   kwdsruntest_hooks   r6   r?   z!call_and_report.<locals>.<lambda>   s    //$/$// r8   )rV   reraiserh   r{   r   noder{   r   )ro   r   r   r   r   rH   r   KeyboardInterruptCallInfo	from_callpytest_runtest_makereportpytest_runtest_logreportcheck_interactive_exceptionpytest_exception_interact)	rh   rV   rt   r   ro   r   r{   r   r   s	   `  `    @r6   r~   r~      s*    JEw,1,F	0			4<<d<<<<u04wG;  511 (%''//////dG   D 88d8NNF
 6&&f&555"400 M''TV'LLLMr8   r{   CallInfo[object]c                    | j         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)excinforO   
isinstancer   r   bdbBdbQuit)r{   r   s     r6   r   r      sP     |uvz"" u$,$w&<== u4r8   TResult)	covariantc                      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Zed d            Ze	 d!d"d            Z	d#dZ
dS )$r   z/Result/Exception info of a function invocation.TResult | None_result#ExceptionInfo[BaseException] | Noner   r4   startstopr;   /Literal['collect', 'setup', 'call', 'teardown']rV   F)	_ispytestresultr   rk   r$   r%   c               x    t          |           || _        || _        || _        || _        || _        || _        d S r=   )r   r   r   r   r   r;   rV   )selfr   r   r   r   r;   rV   r   s           r6   __init__zCallInfo.__init__  s@     	y!!!
	 			r8   r   c                h    | j         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   s    r6   r   zCallInfo.result2  s7     <# D!@!@!@AAA GT\***r8   NfuncCallable[[], TResult]r   <type[BaseException] | tuple[type[BaseException], ...] | NoneCallInfo[TResult]c           	     ^   d}t          j                    }t          j                    }	  |            }n=# t          $ r0 t	          j                    }|t          |j        |          r d}Y nw xY wt          j                    }||z
  }	t          j                    }
 | ||
|	|||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;   rV   r   r   r   )r   timeperf_counterBaseExceptionr   from_currentr   r   )clsr   rV   r   r   r   precise_startr   precise_stopr;   r   s              r6   r   zCallInfo.from_call?  s    $ +--	%)TVVFF 	 	 	#022G"z'-'I'I"FFF		 *,,-/{}}s
 
 
 	
s   
5 7A/.A/strc                \    | j         d| j        d| j        dS d| j        d| j         dS )Nz<CallInfo when=z	 result: >z	 excinfo=)r   rV   r   r   s    r6   __repr__zCallInfo.__repr__i  sD    <LTYLL4<LLLLHHHt|HHHHr8   )r   r   r   r   r   r4   r   r4   r;   r4   rV   r   r   rk   r$   r%   )r$   r   r=   )r   r   rV   r   r   r   r$   r   )r$   r   )__name__
__module____qualname____doc____annotations__r   propertyr   classmethodr   r   r   r8   r6   r   r     s          :90000LLLKKKOOO9999       & 
+ 
+ 
+ X
+ 
 QU	'
 '
 '
 '
 ['
RI I I I I Ir8   r   CallInfo[None]c                ,    t          j        | |          S r=   )r   from_item_and_callr   s     r6   r   r   o  s    (t444r8   	collectorr   r   c                D    d fd}t                               |dt          t          f          }d }|j        sd}n4t
          g}t          j                            d          }||	                    |j
                   t          |j        j        t          |                    rvd}                     |j        d	          }t          |t                    sJ t!          |                      |j        }|sJ t%          |j                  |j        |j        f}nTd
}                     |j                  }	t/          |	d          s&t          |	t$                    sJ t1          |	          }	|	}|j        s|j        nd }
t5           j        |||
          }||_        |S )Nr$   list[Item | Collector]c                 4   t           t                    rb j        j                             j         j                            d           j        j         j                            d                     t           
                                          S )N
importmodeconsider_namespace_packages)rootpathr  )r   r   rH   pluginmanager_loadconftestmodulespathr   r  getinilistcollectr  s   r6   r  z+pytest_make_collect_report.<locals>.collectt  s     i++ 	*?? **<88")2,5,<,C,C1- -	 @    I%%''(((r8   r  )r   r   unittestr   r   r   
toterminal)r$   r  )r   r   r   
SystemExitr   r   r   modulesgetrP   SkipTestr   r   tuple_repr_failure_pyr   repr	reprcrashr   r
  linenomessagerepr_failurerO   r   r   r   rW   r{   )r  r  r{   longreproutcomeskip_exceptionsr  r_r	errorinfor   r\   s   `           r6   pytest_make_collect_reportr"  s  s   ) ) ) ) ) )& %6
$C   D BFH< !:B");??:..""8#4555dl(%*@*@AA 	!G++DL&AABb"455??tBxx??5AHH1AFQXqy9HHG!..t|<<I9l33 8!)S11111,Y77	 H $6T[[$F
	('8V
D
DCCHJr8   c                  2    e Zd ZdZddZddZddZddZdS )ra   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                    i | _         d S r=   )stackr   s    r6   r   zSetupState.__init__  s      	


r8   rh   r   c                   |                                 }| j                                        D ]9\  }\  }}||v s
J d            |r!|d                             |d                   :|t	          | j                  d         D ]k}|| j        vsJ |j        gdf| j        |<   	 |                                 5# t          $ r*}| j        |         d         ||j        ff| j        |<    d}~ww xY 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_tracebackrU   r|   rx   r   r   )r   rh   needed_collectorscol
finalizersexcs         r6   rx   zSetupState.setup  s-    NN,, '+j&6&6&8&8 	4 	4"C"*c++++-W+++ 4!f++CF3334 %S__%6%67 	 	Cdj(((( #~t4DJsO		   #':c?1#5S=N7O"P
3	 	s   $B99
C-%C((C-	finalizerCallable[[], object]r   r   c                    |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%  rP   )r   r.  r   s      r6   addfinalizerzSetupState.addfinalizer  s{    
 3JtU33333	"""""tz!!!D$*#5!!!
4""9-----r8   ri   rj   c           	        |r|                                 pg }g }| j        rt          | j                                                  |dt	          | j                           k    rn| j                                        \  }\  }}g }|rN|                                }	  |             n,# t          $ r}	|                    |	           Y d}	~	nd}	~	ww xY w|Nt	          |          dk    r|	                    |           n3|r1d|}
|                    t          |
|ddd                              | j        t	          |          dk    r|d         |rt          d|ddd                   |	| j        rJ 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  keysrU   popitemr   r   rP   extendr    )r   ri   r*  
exceptionsr   r,  _these_exceptionsfinr   msgs              r6   rf   zSetupState.teardown_exact  s    %=););)=)=C*,
j 	SDJOO%%&&*;<Mc$*oo<M*NNN$(J$6$6$8$8!D/:q! / nn&&/CEEEE# / / /$++A......../	  / #$$))!!"23333! S;4;;!!"4S:J44R4:P"Q"QRRR! j 	S$ z??aQ- 	V$%BJttQStDTUUUz!!> !!s    
B+ +
C5CCN)r$   r%   rh   r   r$   r%   )r.  r/  r   r   r$   r%   )ri   rj   r$   r%   )r   r   r   r   r   rx   r2  rf   r   r8   r6   ra   ra     so        = =~
 
 
 
   *. . . . "  "  "  "  "  "r8   ra   c                    | j         }|                    |            |                    |           }|j                            dd           }|r(t          ||          r|                    | ||           |S )Nr  r{   r   )ro   pytest_collectstartr"  __dict__r   r   r   )r  ro   r\   r{   s       r6   collect_one_noderA  4  s    OE		22299I9NNC<FD))D O+D#66 O''YT#'NNNJr8   )r#   r   r$   r%   )r9   r"   r$   r%   )r_   r!   r$   r%   )rh   r   ri   rj   r$   rk   )TN)rh   r   rt   rk   ri   rj   r$   ru   r=  )rh   r   ri   rj   r$   r%   )rh   r   rV   r   r$   r%   )r   r   r$   r   )T)rh   r   rV   r   rt   rk   r$   r   )r{   r   r   r   r$   rk   )rh   r   r{   r   r$   r   )r  r   r$   r   )Er   
__future__r   r   dataclassesr   r   typestypingr   r   r   r   r   r	   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^   rd   rg   rs   rq   r   r   r   r   r   r   r~   r   r   	dataclassr   r   r"  ra   rA  r   r8   r6   <module>rP     sw   9 9 " " " " " " 



     				 



                                                        % % % % % % " " " " " "             1 1 1 1 1 1 , , , , , , + + + + + + , , , , , , - - - - - - # # # # # # # # # # # #             ! ! ! ! ! ! - - - - - - $ $ $ $ $ $ ) ) ) ) ) ) g111111 2$$$$$$111111   *K K K K>' ' ' '- - - -    ;?    8	 	 	 	) ) ) )
   0) ) ) )! ! ! !"	 	 	 	" IM    4    ')t
,
,
, \I \I \I \I \Iww \I \I  \I~5 5 5 50 0 0 0fK" K" K" K" K" K" K" K"\     r8   