
    ESjXb                       d 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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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l0m1Z1 dd l0m2Z2 ejf                  d	d! d"k  rdd#l4m5Z5 erdd$lm6Z6 dd	lZdd	l7Z8e9e:e;   e;ejl                  f   e9d%   z  Z<	 	 	 	 	 	 	 	 d7d&Z= G d' d(e*      Z> G d) d*e+      Z? ed+,      d8d-       Z@d9d.ZAd:d/ZB G d0 d1e
      ZCd;d2ZDd3ZE ed+4      d<d5       ZF	 	 	 	 d=d6ZGy	)>z4Discover and run std-library "unittest" style tests.    )annotations)Callable)	Generator)Iterable)Iterator)auto)EnumN)Any)TYPE_CHECKING)TestCase)fixtures)ExceptionInfo)assert_never)is_async_function)hookimpl)FixtureRequest)MonkeyPatch)	Collector)Item)exit)fail)skip)xfail)Class)Function)Module)CallInfo)check_interactive_exception)SubtestContext)SubtestReport         )ExceptionGroup)TracebackType)NNNc                    	 t         j                  d   }t        ||j                        sy 	 t        j                  |      ry t        j                  | ||      S # t        $ r Y y w xY w)Nunittest)nameobj)	sysmodules
issubclassr   	Exceptioninspect
isabstractUnitTestCasefrom_parent)	collectorr)   r*   uts       a/Users/ahmed/devFolder/Ultron/claude-voice/.venv/lib/python3.12/site-packages/_pytest/unittest.pypytest_pycollect_makeitemr6   ;   sl    [[$ #r{{+ , ###IDc#BB  s   )A 	A'&A'c                  6    e Zd ZdZd ZddZd	dZd	dZd	dZy)
r1   Tc                $    | j                  d      S )NrunTestr*   selfs    r5   newinstancezUnitTestCase.newinstanceT   s     xx	""    c              #    K   ddl m} | j                  }t        |dd      sy t	        |      }|s3| j                  |       | j                  |       | j                          n| j                  |       | j                  j                  j                  | j                         |         |       }d}|j                  | j                        D ]A  }t        | j                  |      }t        |dd      s't        j                  | |       d}C |spt        | j                  dd       }|Vt         j"                  j%                  d	d       }	|	||	j&                  j(                  k7  rt        j                  | d       y y y y w)
Nr   )
TestLoader__test__T)holdernodeF)r)   r9   twisted.trial.unittest)r(   r@   r*   getattr_is_skipped'_register_unittest_setup_method_fixture&_register_unittest_setup_class_fixture_register_setup_class_fixture_register_unittest_skip_fixturesession_fixturemanagerparsefactoriesr=   getTestCaseNamesTestCaseFunctionr2   r+   r,   getr   r9   )
r<   r@   clsskippedloaderfoundsomethingr)   xruntestr4   s
             r5   collectzUnitTestCase.collect\   s^    'hhsJ-c"88=77<..0005$$33##%D 	4 	
 ++DHH5D$'A1j$/"..t$.??!N 6 dhh	48G"[[__%=tD:BKK,?,?!?*66t)6LL "@ # s   FFc                    t        dd      t        dd      yt        dd       dfd	 	 	 	 dfd}t        j                  dj                   || d	d
       y)zSRegister an auto-use fixture to invoke setUpClass and
        tearDownClass (#517).
setUpClassNtearDownClassdoClassCleanupsc                      y N r^   r>   r5   <lambda>zEUnitTestCase._register_unittest_setup_class_fixture.<locals>.<lambda>   s    $r>   c                     t        dd       } | sy | D cg c]  \  }}}|
 }}}t        |      dk(  r|d   t        d|      c c}}w )NtearDown_exceptions   r   zUnittest class cleanup errors)rE   lenr%   )	exc_infos_exc
exceptionsrQ   s       r5   process_teardown_exceptionszXUnitTestCase._register_unittest_setup_class_fixture.<locals>.process_teardown_exceptions   s_      %:DAI1:;+1c1#J; :!# m#$%DjQQ <s   Ac              3  ,  K   | j                   }t        |      r#|j                  }t        j                  |d      	          d  	                            y # t        $ r                    w xY w#                   w xY wwNT_use_item_location)rQ   rF   __unittest_skip_why__r   r.   )requestrQ   reasoncleanuprh   setupteardowns      r5   unittest_setup_class_fixturezYUnitTestCase._register_unittest_setup_class_fixture.<locals>.unittest_setup_class_fixture   s      ++C322nnVEE G .'J	+- ! I/1 	+-s5   =BA% B	B B%A>>BBB_unittest_setUpClass_fixture_classTr)   funcrC   scopeautousereturnNonern   r   r{   zGenerator[None]rE   r   register_fixture__qualname__)r<   rQ   rs   rp   rh   rq   rr   s    ` @@@@r5   rH   z3UnitTestCase._register_unittest_setup_class_fixture   s     \4036=X-#0,?	R	.#	.	. 	.0 	!!01A1A0BC-	
r>   c                `    dfd}t        j                  dj                   || dd       y)zzRegister an auto-use fixture to skip tests for a class decorated
        with @unittest.skip or @unittest.skipIf (#13885).c                L    t        dd      }t        j                  |d      )Nrm    Trk   )rE   r   r.   )rn   ro   rQ   s     r5   unittest_skip_fixturezKUnitTestCase._register_unittest_skip_fixture.<locals>.unittest_skip_fixture   s#    S"92>F..DAAr>   _unittest_skip_fixture_ru   Trv   N)rn   r   r{   r|   )r   r   r   )r<   rQ   r   s    ` r5   rJ   z,UnitTestCase._register_unittest_skip_fixture   s6    	B 	!!*3+;+;*<=&	
r>   c                    t        |dd      t        |dd      y	 	 	 	 d	fd}t        j                  d|j                   || dd       y)
zWRegister an auto-use fixture to invoke setup_method and
        teardown_method (#517).setup_methodNteardown_methodc              3     K   | j                   }t        |      r#|j                  }t        j                  |d       || j
                         d   || j
                         y y wrj   )instancerF   rm   r   r.   function)rn   r<   ro   rq   rr   s      r5   unittest_setup_method_fixturez[UnitTestCase._register_unittest_setup_method_fixture.<locals>.unittest_setup_method_fixture   sl      ##D4 33nnVEE dG,,-#w//0 $s   A+A._unittest_setup_method_fixture_r   Trv   r}   r~   )r<   rQ   r   rq   rr   s      @@r5   rG   z4UnitTestCase._register_unittest_setup_method_fixture   sq     ^T23 148=X-	1#	1	1 	!!233C3C2DE.	
r>   N)r{   zIterable[Item | Collector])rQ   typer{   r|   )	__name__
__module__r   
nofuncargsr=   rW   rH   rJ   rG   r^   r>   r5   r1   r1   O   s%     J#!MF6
p
 
r>   r1   c                  2    e Zd ZU dZdZdZded<   d Zed        Z	d fdZ
d fd	Zdd
ZddZ	 	 	 	 	 	 ddZ	 	 	 	 	 	 ddZdd	 	 	 	 	 	 	 ddZ	 d	 	 	 	 	 	 	 ddZ	 d 	 	 	 	 	 d!dZddZddZd"dZddZ	 	 	 	 d# fdZ	 	 	 	 	 	 	 	 d$dZd%dZ xZS )&rO   TFNz7list[_pytest._code.ExceptionInfo[BaseException]] | None_excinfoc                    t        | j                  t              sJ | j                  j                  | j                        S r]   )
isinstanceparentr1   r*   r)   r;   s    r5   _getinstancezTestCaseFunction._getinstance   s-    $++|444{{tyy))r>   c                    | j                   S r]   )r   r;   s    r5   	_testcasezTestCaseFunction._testcase   s    }}r>   c                f    d | _         t        | 	          t        j                  dk  rd | _        y y )Nr"   )_explicit_tearDownsuperrq   r+   version_info_cached_errors_and_skipsr<   	__class__s    r5   rq   zTestCaseFunction.setup   s3    =Ag% QUD) &r>   c                z    | j                   | j                          d | _         d | _        | `t        |           y r]   )r   _obj	_instancer   rr   r   s    r5   rr   zTestCaseFunction.teardown   s:    "".##%&*D#	Nr>   c                     y r]   r^   r<   testcases     r5   	startTestzTestCaseFunction.startTest      r>   c                   t        |      }	 t        j                  j                  t           j                  |      }|j                  }|j                  }| j                   j#                  dg       j%                         y # t        $ r 	 	 t        j                  | }|j                  dd       t        dj                  |      d       n8# t        j                  t        f$ r  t        $ r t        d|d       Y nw xY wnJ# t        $ r  t        j                  $ r+ t        j                  j                  j                         }Y nw xY wY w xY w)Nr   zCNOTE: Incompatible Exception Representation, displaying natively:

r   Fpytracez6ERROR: Unknown Incompatible Exception representation:
r   )_handle_twisted_exc_info_pytest_coder   BaseExceptionfrom_exc_infovalue	traceback	TypeErrorformat_exceptioninsertr   joinr.   KeyboardInterruptfrom_current__dict__
setdefaultappend)r<   
rawexcinfoexcinfore   valuess        r5   _addexcinfozTestCaseFunction._addexcinfo	  s8   -j9
	Emm11-@NNG
 A!!A. 	  R077@-  	EE&77DFMM3
 %8(9: $ ,,6>; % % >> E!--55BBDE)	EsV   AB 	EA CD2D?DDDEAE
EEEEc                    	 t        |d   t        j                        rt        |d   j                         | j                  |       y # t        $ r Y w xY w)Nrb   )r   r   r.   msgr   r   r<   r   r   s      r5   addErrorzTestCaseFunction.addError+  sO    	*Q-8Z]&&' 	$  		s   5A	 		AAc                &    | j                  |       y r]   )r   r   s      r5   
addFailurezTestCaseFunction.addFailure5  s     	$r>   handle_subtestsc                   ddl m} d fd}|s |        y t        ||      rA |         j                  - j                  d   } j	                  |j
                  ||       y y t        j                  dk  r@ j                  j                  * j                         \  }}t        |      dk(  r |        y y  |        y )Nr   _SubTestc                     	 t        j                   d      # t         j                  $ r& j                  t        j                                Y y w xY wrj   )r   r.   r   r+   exc_info)ro   r<   s   r5   add_skipz*TestCaseFunction.addSkip.<locals>.add_skip?  s@    1nnVEE>> 1  01s    6AAr"   rz   )unittest.caser   r   r   
addSubTest	test_caser+   r   r   _outcome_obtain_errors_and_skipsrc   )	r<   r   ro   r   r   r   r   subtest_errorsre   s	   ` `      r5   addSkipzTestCaseFunction.addSkip:  s     	+	1 Jh)J}}(==, 2 2HhG ) ')dmm.D.D.P$($A$A$C!~&!+J , 
r>   c                    	 t        t        |             y # t         j                  $ r& | j                  t	        j
                                Y y w xY wr]   )r   strr.   r   r+   r   )r<   r   r   ro   s       r5   addExpectedFailurez#TestCaseFunction.addExpectedFailure[  s:    	-#f+ 	-S\\^,	-s    6AAc                    d}|r|d|j                    z  }	 t        |d       y # t        j                  $ r& | j                  t	        j
                                Y y w xY w)NzUnexpected successz: Fr   )ro   r   r.   r   r+   r   )r<   r   ro   r   s       r5   addUnexpectedSuccessz%TestCaseFunction.addUnexpectedSuccessf  sW    
 #R''C	-e$~~ 	-S\\^,	-s   & 6AAc                     y r]   r^   r   s     r5   
addSuccesszTestCaseFunction.addSuccesst  r   r>   c                     y r]   r^   r   s     r5   stopTestzTestCaseFunction.stopTestw  r   r>   c                     y r]   r^   )r<   r   elapseds      r5   addDurationzTestCaseFunction.addDurationz  r   r>   c                R   ddl m} | j                  }|J  ||        t        | j                        r
 ||        y t        | j                  t              sJ t        | j                        xs t        | j                  j                        }| j                  j                  d      r!|s|j                  | _        t        |dd        t        || j                  | j                         	  ||        t        || j                         y # t        || j                         w xY w)Nr   )&maybe_wrap_pytest_function_for_tracing)resultusepdbtearDownc                      y r]   r^   )argss    r5   r_   z*TestCaseFunction.runtest.<locals>.<lambda>  s    Dr>   )_pytest.debuggingr   r   r   r*   r   r   r1   rF   config	getoptionr   r   setattrr)   delattr)r<   r   r   rR   s       r5   rV   zTestCaseFunction.runtest}  s    L==###.t4 TXX&D! dkk<888!$((+K{4;;??/KG{{$$X.w*2*;*;'*.@A Hdii2-%$)),$)),s   .	D D&c                T    t         |   |      } |j                  d       }|s|}|S )Nc                N    | j                   j                  j                  d       S )N
__unittest)frame	f_globalsrP   )rU   s    r5   r_   z4TestCaseFunction._traceback_filter.<locals>.<lambda>  s    !''++//==r>   )r   _traceback_filterfilter)r<   r   r   
ntracebackr   s       r5   r   z"TestCaseFunction._traceback_filter  s9     G-g6	%Y%%=

 "Jr>   c           	        ddl m} |xt        d x\    t        |d      }n& xxt        d x\   n xn n  |}n}t	        |       t        d    d ddddd      }|j                  |u rd nt        |j                        }| j                  j                  | |      }	t        j                  |	t        |t        |j                        	      d d 
      }
| j                  j                  |
       t!        ||
      r| j                  j#                  | ||
       t$        j&                  dk  r]| j)                         \  }}t+        |      dkD  r;t+        |      dkD  r,|d   }||d   u r|D ]  \  }}| j-                  ||d        y y y y y )Nr   )_subtest_msg_sentinelr^   T)	_ispytestcall)startstopdurationwhenr   )itemr   )r   kwargs)captured_outputcaptured_logs)report)rC   r   r  r"   r   Fr   )r   r   tupler   r   r   _messager   ihookpytest_runtest_makereportr    _newr   dictparamspytest_runtest_logreportr   pytest_exception_interactr+   r   r   rc   r   )r<   r   testr   r   exception_infounreachable	call_infor   r  
sub_reportr   non_subtest_skiplast_subset_errorr   ro   s                   r5   r   zTestCaseFunction.addSubTest  s    	8 !.x4!H '4'!)[)TN
	 mm'<<d#dmmBT554i5P"''s4+<= 	

 	

++:+>&y*=JJ00	* 1 
 g%/3/L/L/N,N, #$q(S-@1-D$22$6!044,<(&XvuM -= 5 .E( &r>   c                   ddl m} t        j                  dk  sJ d       | j                  | j                  S | j
                  j                  j                  D cg c]  \  }}t        ||      r|||f }}}| j
                  j                  j                  D cg c]  \  }}t        ||      s||f }}}||f| _        ||fS c c}}w c c}}w )zMCompute or obtain the cached values for subtest errors and non-subtest skips.r   r   r"   z2This workaround only should be used in Python 3.10)
r   r   r+   r   r   r   r   errorsr   rR   )r<   r   rU   yr   non_subtest_skipss         r5   r   z)TestCaseFunction._obtain_errors_and_skips  s    *') 	
@	
) ((4000 ..55
51!X&1= F5 	 
 ..66
61a* F6 	 

 *89J(K%000

s   CCrz   )r   unittest.TestCaser{   r|   )r   _SysExcInfoTyper{   r|   )r   r  r   r  r{   r|   )r   r  ro   r   r   boolr{   r|   )r   )r   r  r   r  ro   r   r{   r|   r]   )r   r  ro   z"twisted.trial.unittest.Todo | Noner{   r|   )r   r  r   floatr{   r|   )r   z*_pytest._code.ExceptionInfo[BaseException]r{   z_pytest._code.Traceback)r   r
   r  r   r   z^ExceptionInfo[BaseException] | tuple[type[BaseException], BaseException, TracebackType] | Noner{   r|   )r{   ztuple[list[Any], list[Any]])r   r   r   r   failfastr   __annotations__r   propertyr   rq   rr   r   r   r   r   r   r   r   r   r   r   rV   r   r   r   __classcell__)r   s   @r5   rO   rO      se   JHHLHEL*  U AD%)%7F%	%%)%7F%	% TX)36LP	J 		-#	- $	- 		-
 
	- 6:-#- 3- 
	--B	A		 	8N8N 8N	8N 
8Nt1r>   rO   T)tryfirstc                   t        | t              r/| j                  r#| j                  j                  d      |_        	 |`t        j                  j                  d      }|r||j                  rot        |j                  j                  |j                        rD|j                  t        d    j                  fd|j                        }|j                  |_        y y y y # t        $ r Y w xY w)Nr   r(   c                 @    t        t         j                              S r]   )r   r   r   )r   s   r5   r_   z+pytest_runtest_makereport.<locals>.<lambda>  s    c'--6H1Ir>   )r   rO   r   popr   r   AttributeErrorr+   r,   rP   r   SkipTestr   	from_callr   )r   r   r(   call2r   s       @r5   r  r    s    $()====,,Q/DLK {{z*HDLLZ0B0BHDUDU%V,,(()I499U}} &WLx " s   C 	C+*C+c                .    t        t        | dd            S )zDReturn True if the given object has been marked with @unittest.skip.__unittest_skip__F)r  rE   r:   s    r5   rF   rF     s    0%899r>   c                 l    t               t        j                  urddlm}  ddlm}  |t        |        yy)zRRegister the TestCaseFunction class as an IReporter if twisted.trial is available.r   )	IReporter)classImplementsN)_get_twisted_versionTwistedVersionNotInstalledtwisted.trial.itrialr*  zope.interfacer+  rO   )r*  r+  s     r5   pytest_configurer1    s*    ^%@%@@22()4	 Ar>   c                  :    e Zd ZdZ e       Z e       Z e       Zy)r-  z
    The Twisted version installed in the environment.

    We have different workarounds in place for different versions of Twisted.
    N)r   r   r   __doc__r   	Version24	Version25r.  r^   r>   r5   r-  r-    s     II6Lr>   r-  c                     dt         j                  vrt        j                  S dd l} dd l}| j                  j                  d      }|j                  j                  |      }|j                  dk  rt        j                  S t        j                  S )NrD   r   twisted   )r+   r,   r-  r.  importlib.metadatapackaging.versionmetadataversionparsemajorr4  r5  )	importlib	packagingversion_strr<  s       r5   r,  r,  ,  sr      s{{2***$$,,Y7K%%k2G}}''''''r>   _twisted_raw_excinfo)wrapperc              #  *  K   t               t        j                  u redd lmc m} |j                  j                  	 dfd	}t        j                         5 }|j                  |j                  d|       d cd d d        S d S # 1 sw Y   y xY ww)Nr   c                   |t        j                         }n+|t        |      }|t        j                         d   }|||f}t        | t        t        |             	  | ||||       y # t        $ r  | |||       Y y w xY w)Nr!   )captureVars)r+   r   r   r   TWISTED_RAW_EXCINFO_ATTRr  r   )r<   	exc_valueexc_typeexc_tbrF  raw_exc_infooriginal__init__s         r5   store_raw_exception_infoz9pytest_runtest_protocol.<locals>.store_raw_exception_infoM  s      "||~##IH> \\^A.F ()V<D2E,4GHD )Xv;  D y(FCDs   A- -BB__init__)NNNN)r,  r-  r4  twisted.python.failurepythonfailureFailurerN  r   contextr   )r   r4   rM  patcherrL  s       @r5   pytest_runtest_protocolrU  E  s|     !9!99++ ::.. KO	D&   "gOOBJJ
4LM #" 	 #"s   AB!B9BBBc                   t               }|t        j                  u r| S |t        j                  u r4t	        | t
              r"t        | t
              }t        | t
               |S | S |t        j                  u rt        | t              ruddl}t        | |j                  j                  j                        rG| j                  }|t!        j"                         d   }t%        | j&                        | j&                  |fS | S J d|        )z
    Twisted passes a custom Failure instance to `addError()` instead of using `sys.exc_info()`.
    Therefore, if `rawexcinfo` is a `Failure` instance, convert it into the equivalent `sys.exc_info()` tuple
    as expected by pytest.
    r   Nr!   zUnexpected Twisted version: )r,  r-  r.  r4  hasattrrG  rE   r   r5  r   r   rO  rP  rQ  rR  __traceback__r+   r   r   r   )r   twisted_versionsaved_exc_infor7  tbs        r5   r   r   g  s     +,O.555 	N44	4 :78$Z1IJNJ 89!!	N44	4j-0)*gnn&<&<&D&DE--:*BJ,,-z/?/?CC 	G4_4EFFur>   )r3   zModule | Classr)   r   r*   objectr{   zUnitTestCase | None)r   r   r   zCallInfo[None]r{   r|   )r{   r  rz   )r{   r-  )r   r   r{   zIterator[None])r   z_SysExcInfoType | BaseExceptionr{   r  )Hr3  
__future__r   collections.abcr   r   r   r   enumr   r	   r/   r+   r   typestypingr
   r   r(   r   r   r   _pytest._coder   _pytest.compatr   r   _pytest.configr   _pytest.fixturesr   _pytest.monkeypatchr   _pytest.nodesr   r   _pytest.outcomesr   r   r   r   _pytest.pythonr   r   r   _pytest.runnerr   r   _pytest.subtestsr   r    r   exceptiongroupr%   r&   twisted.trial.unittestr7  r  r   r   r  r6   r1   rO   r  rF   r1  r-  r,  rG  rU  r   r^   r>   r5   <module>rn     s|   : " $ % $ $    
         ' ' , # + + #  ! ! ! "   # ! # 6 + * BQ'!-#! 
$}
}e.A.A
AB CC%(C/5CC(T
5 T
nS1x S1l 
4% %$:
5T (, 2  
$ B&G/&G&Gr>   