o
    v&is[                     @  st  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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/m0Z0 ddl/m1Z1 ej2d	d  d!k rdd"l3m4Z4 erdd#lm5Z5 dd	lZdd	l6Z7e8e9e: e:ej5f e8d$ B Z;dOd-d.Z<G d/d0 d0e)Z=G d1d2 d2e*Z>ed3d4dPd:d;Z?dQd=d>Z@dRd?d@ZAG dAdB dBe
ZBdSdCdDZCdEZDed3dFdTdHdIZEdUdMdNZFd	S )Vz4Discover and run std-library "unittest" style tests.    )annotations)Callable)	Generator)Iterable)Iterator)auto)EnumN)Any)TYPE_CHECKING)TestCase)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)NNN	collectorModule | ClassnamestrobjobjectreturnUnitTestCase | Nonec                 C  sT   zt jd }t||jsW d S W n
 ty   Y d S w t|r"d S tj| ||dS )Nunittest)r'   r)   )	sysmodules
issubclassr   	Exceptioninspect
isabstractUnitTestCasefrom_parent)r%   r'   r)   ut r7   V/var/www/html/karishye-ai-python/venv/lib/python3.10/site-packages/_pytest/unittest.pypytest_pycollect_makeitem:   s   

r9   c                   @  s6   e Zd ZdZdd ZdddZdddZdddZdS )r4   Tc                 C  s
   |  dS )NrunTestr)   selfr7   r7   r8   newinstanceS   s   
zUnitTestCase.newinstancer+   Iterable[Item | Collector]c           
      c  s   ddl m} | j}t|ddsd S t|}|s&| | | | |   | jj	
|  | j | }d}|| jD ]}t| j|}t|ddsKq<tj| |dV  d}q<|s~t| jdd }|d urtjdd }	|	d u st||	jjkrtj| ddV  d S d S d S d S )	Nr   )
TestLoader__test__TF)r'   r:   twisted.trial.unittest)r-   r@   r)   getattr_is_skipped'_register_unittest_setup_method_fixture&_register_unittest_setup_class_fixture_register_setup_class_fixturesession_fixturemanagerparsefactoriesr>   nodeidgetTestCaseNamesTestCaseFunctionr5   r.   r/   getr   r:   )
r=   r@   clsskippedloaderfoundsomethingr'   xruntestr6   r7   r7   r8   collect[   s8   

zUnitTestCase.collectrO   typeNonec                   s   t ddt dddu rdu rdS t ddd  dfd	d
d fdd}| jjjdj || jddd dS )zSRegister an auto-use fixture to invoke setUpClass and
        tearDownClass (#517).
setUpClassNtearDownClassdoClassCleanupsc                   S     d S Nr7   r7   r7   r7   r8   <lambda>       zEUnitTestCase._register_unittest_setup_class_fixture.<locals>.<lambda>r+   rW   c                    s@   t  dd } | s
d S dd | D }t|dkr|d td|)NtearDown_exceptionsc                 S  s   g | ]\}}}|qS r7   r7   ).0_excr7   r7   r8   
<listcomp>   s    zlUnitTestCase._register_unittest_setup_class_fixture.<locals>.process_teardown_exceptions.<locals>.<listcomp>   r   zUnittest class cleanup errors)rC   lenr#   )	exc_infos
exceptions)rO   r7   r8   process_teardown_exceptions   s   
zXUnitTestCase._register_unittest_setup_class_fixture.<locals>.process_teardown_exceptionsrequestr   Generator[None]c                 3  s    | j }t|r|j}tj|ddd ur*z  W n ty)         w d V  zd ur>  W      d S W      d S      w NT)_use_item_location)rO   rD   __unittest_skip_why__r   r1   )ri   rO   reason)cleanuprh   setupteardownr7   r8   unittest_setup_class_fixture   s0   


zYUnitTestCase._register_unittest_setup_class_fixture.<locals>.unittest_setup_class_fixture_unittest_setUpClass_fixture_classTr'   funcrK   scopeautouser+   rW   ri   r   r+   rj   rC   rH   rI   _register_fixture__qualname__rK   )r=   rO   rr   r7   )ro   rO   rh   rp   rq   r8   rF   z   s   

z3UnitTestCase._register_unittest_setup_class_fixturec                   sb   t |dd t |dd du rdu rdS d fdd	}| jjjd
|j || jddd dS )zWRegister an auto-use fixture to invoke setup_method and
        teardown_method (#517).setup_methodNteardown_methodri   r   r+   rj   c                 3  sZ    | j }t|r|j}tj|dd d ur || j d V  d ur+|| j d S d S rk   )instancerD   rm   r   r1   function)ri   r=   rn   rp   rq   r7   r8   unittest_setup_method_fixture   s   z[UnitTestCase._register_unittest_setup_method_fixture.<locals>.unittest_setup_method_fixture_unittest_setup_method_fixture_r   Tru   rz   r{   )r=   rO   r   r7   r   r8   rE      s   

z4UnitTestCase._register_unittest_setup_method_fixtureN)r+   r?   )rO   rV   r+   rW   )__name__
__module__r}   
nofuncargsr>   rU   rF   rE   r7   r7   r7   r8   r4   N   s    

8r4   c                      s   e Zd ZU dZdZdZded< dd Zedd	 Z	d@ fddZ
d@ fddZdAddZdBddZdCddZdCddZdddDd!d"Z	#dEdFd$d%Z	dGdHd'd(ZdAd)d*ZdAd+d,ZdId/d0Zd@d1d2ZdJ fd6d7ZdKd>d?Z  ZS )LrM   TFNz7list[_pytest._code.ExceptionInfo[BaseException]] | None_excinfoc                 C  s   t | jtsJ | j| jS r\   )
isinstanceparentr4   r)   r'   r<   r7   r7   r8   _getinstance   s   zTestCaseFunction._getinstancec                 C  s   | j S r\   )r   r<   r7   r7   r8   	_testcase   s   zTestCaseFunction._testcaser+   rW   c                   s   d | _ t   d S r\   )_explicit_tearDownsuperrp   r<   	__class__r7   r8   rp      s   zTestCaseFunction.setupc                   s0   | j d ur|    d | _ d | _| `t   d S r\   )r   _obj	_instancer   rq   r<   r   r7   r8   rq      s   
zTestCaseFunction.teardowntestcaseunittest.TestCasec                 C  r[   r\   r7   r=   r   r7   r7   r8   	startTest      zTestCaseFunction.startTest
rawexcinfo_SysExcInfoTypec                 C  s   t |}ztjjt |}|j}|j}W nV tyk   z5ztj	| }|
dd td|dd W n tjtfy>     tyO   td|dd Y nw W n tyY     tjyh   tjj }Y nw Y nw | jdg | d S )Nr   zCNOTE: Incompatible Exception Representation, displaying natively:

 Fpytracez6ERROR: Unknown Incompatible Exception representation:
r   )_handle_twisted_exc_info_pytest_coder   BaseExceptionfrom_exc_infovalue	traceback	TypeErrorformat_exceptioninsertr   joinr1   KeyboardInterruptfrom_current__dict__
setdefaultappend)r=   r   excinfora   valuesr7   r7   r8   _addexcinfo   sF   


zTestCaseFunction._addexcinfoc                 C  sD   zt |d tjrt|d j W n	 ty   Y nw | | d S )Nrd   )r   r   r1   msgr   r   r=   r   r   r7   r7   r8   addError  s   zTestCaseFunction.addErrorc                 C  s   |  | d S r\   )r   r   r7   r7   r8   
addFailure  s   zTestCaseFunction.addFailurehandle_subtestsrn   r(   r   boolc                  s   ddl m  dfdd}|s|  d S t| r3|  jd ur1jd }|j|| d S d S tjdk rWjj	d urW fd	d
jj	j
D }t|dkrU|  d S d S |  d S )Nr   _SubTestr+   rW   c                     s4   zt j dd t jy   t  Y d S w rk   )r   r1   r   r.   exc_infor7   )rn   r=   r7   r8   add_skip&  s
   z*TestCaseFunction.addSkip.<locals>.add_skipr    c                   s&   g | ]\}}t | r|d ur|qS r\   r   r`   rS   yr   r7   r8   rc   <  s    z,TestCaseFunction.addSkip.<locals>.<listcomp>ry   )unittest.caser   r   r   
addSubTest	test_caser.   version_infor   _outcomeerrorsre   )r=   r   rn   r   r   r   subtest_errorsr7   )r   rn   r=   r8   addSkip!  s&   


	


zTestCaseFunction.addSkipr   c                 C  s8   z	t t| W d S  t jy   | t  Y d S w r\   )r   r(   r1   r   r.   r   )r=   r   r   rn   r7   r7   r8   addExpectedFailureF  s
   z#TestCaseFunction.addExpectedFailure"twisted.trial.unittest.Todo | Nonec                 C  sP   d}|r|d|j  7 }z	t|dd W d S  tjy'   | t  Y d S w )NzUnexpected successz: Fr   )rn   r   r1   r   r.   r   )r=   r   rn   r   r7   r7   r8   addUnexpectedSuccessQ  s   z%TestCaseFunction.addUnexpectedSuccessc                 C  r[   r\   r7   r   r7   r7   r8   
addSuccess_  r   zTestCaseFunction.addSuccessc                 C  r[   r\   r7   r   r7   r7   r8   stopTestb  r   zTestCaseFunction.stopTestelapsedfloatc                 C  r[   r\   r7   )r=   r   r   r7   r7   r8   addDuratione  r   zTestCaseFunction.addDurationc              	   C  s   ddl m} | j}|d usJ ||  t| jr|| d d S t| jts'J t| jp1t| jj}| j	
drF|sF|j| _t|ddd  t|| j| j z|| d W t|| j d S t|| j w )Nr   )&maybe_wrap_pytest_function_for_tracing)resultusepdbtearDownc                  W  r[   r\   r7   )argsr7   r7   r8   r]     r^   z*TestCaseFunction.runtest.<locals>.<lambda>)_pytest.debuggingr   r   r   r)   r   r   r4   rD   config	getoptionr   r   setattrr'   delattr)r=   r   r   rP   r7   r7   r8   rT   h  s   
	zTestCaseFunction.runtestr   *_pytest._code.ExceptionInfo[BaseException]_pytest._code.Tracebackc                   s&   t  |}|dd }|s|}|S )Nc                 S  s   | j jd S )N
__unittest)frame	f_globalsrN   )rS   r7   r7   r8   r]     s    z4TestCaseFunction._traceback_filter.<locals>.<lambda>)r   _traceback_filterfilter)r=   r   r   
ntracebackr   r7   r8   r     s   z"TestCaseFunction._traceback_filterr   r	   testr   r   ^ExceptionInfo[BaseException] | tuple[type[BaseException], BaseException, TracebackType] | Nonec              	     s  | t d r  t|dd}n   td r n  d u rn n  |}n}t| td  d |dddddd}t|jtr@|jnd }| jj| |d}t	j
|t|t|jdd d d	}	| jj|	d
 t||	ro| jj| ||	d tjdk rddlm   fdd| jjjD }
 fdd| jjjD }t|
dkrt|dkr|d }||d u r|
D ]\}}| j||dd qd S d S d S d S d S )Nr7   T)	_ispytestr   call)startstopdurationwhenr   )itemr   )r   kwargs)captured_outputcaptured_logs)report)noder   r   r    r   c                   s"   g | ]\}}t | s||fqS r7   r   r   r   r7   r8   rc     s    z/TestCaseFunction.addSubTest.<locals>.<listcomp>c                   s*   g | ]\}}t | r|d ur||fqS r\   r   r   r   r7   r8   rc     s    r   Fr   )tupler   r   r   r   _messager(   ihookpytest_runtest_makereportr   _newr   dictparamspytest_runtest_logreportr   pytest_exception_interactr.   r   r   r   r   r   rP   r   re   r   )r=   r   r   r   exception_infounreachable	call_infor   r   
sub_reportnon_subtest_skipr   last_subset_errorr   rn   r7   r   r8   r     s^   	$	



zTestCaseFunction.addSubTestry   )r   r   r+   rW   )r   r   r+   rW   )r   r   r   r   r+   rW   )r   r   rn   r(   r   r   r+   rW   )r   )r   r   r   r   rn   r(   r+   rW   r\   )r   r   rn   r   r+   rW   )r   r   r   r   r+   rW   )r   r   r+   r   )r   r	   r   r   r   r   r+   rW   )r   r   r}   r   failfastr   __annotations__r   propertyr   rp   rq   r   r   r   r   r   r   r   r   r   r   rT   r   r   __classcell__r7   r7   r   r8   rM      s2   
 



"

)



!rM   T)tryfirstr   r   r   CallInfo[None]rW   c                   s   t | tr| jr| jd|_z|`W n	 ty   Y nw tj	d}|rF|jrHt |jj
|jrJ|j td   fdd|j}|j|_d S d S d S d S )Nr   r-   c                     s   t t jS r\   )r   r(   r   r7   r   r7   r8   r]     s    z+pytest_runtest_makereport.<locals>.<lambda>)r   rM   r   popr   r   AttributeErrorr.   r/   rN   r   SkipTestr   	from_callr   )r   r   r-   call2r7   r  r8   r     s   
r   r   c                 C  s   t t| ddS )zDReturn True if the given object has been marked with @unittest.skip.__unittest_skip__F)r   rC   r;   r7   r7   r8   rD     s   rD   c                  C  s6   t  tjurddlm}  ddlm} |t|  dS dS )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  rM   )r  r  r7   r7   r8   pytest_configure  s
   r  c                   @  s"   e Zd ZdZe Ze Ze ZdS )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  r7   r7   r7   r8   r    s
    
r  c                  C  sN   dt jvrtjS dd l} dd l}| jd}|j|}|j	dkr$tj
S tjS )NrB   r   twisted   )r.   r/   r  r  importlib.metadatapackaging.versionmetadataversionparsemajorr  r  )	importlib	packagingversion_strr  r7   r7   r8   r    s   

r  _twisted_raw_excinfo)wrapperIterator[None]c                 #  s    t  tju r=dd lm  m} |jj 	 d fdd	}t	 }|
|jd| d V W  d    S 1 s6w   Y  d S d V S )Nr   c                   s   |d u r	t  }n|d u rt|}|d u rt  d }|||f}t| tt| z | ||||d W d S  tyE    | ||| Y d S w )Nr   )captureVars)r.   r   rV   r   TWISTED_RAW_EXCINFO_ATTRr   r   )r=   	exc_valueexc_typeexc_tbr$  raw_exc_infooriginal__init__r7   r8   store_raw_exception_info&  s   


z9pytest_runtest_protocol.<locals>.store_raw_exception_info__init__)NNNN)r  r  r  twisted.python.failurepythonfailureFailurer-  r   contextr   )r   r6   r,  patcherr7   r*  r8   pytest_runtest_protocol  s   
$r4  r   _SysExcInfoType | BaseExceptionr   c                 C  s   t  }|tju r
| S |tju r"t| tr t| t}t| t |S | S |tju rPt	| t
rNddl}t	| |jjjrN| j}|du rEt 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   FzUnexpected Twisted version: )r  r  r  r  hasattrr%  rC   r   r  r   r   r.  r/  r0  r1  __traceback__r.   r   rV   r   )r   twisted_versionsaved_exc_infor  tbr7   r7   r8   r   @  s&   






r   )r%   r&   r'   r(   r)   r*   r+   r,   )r   r   r   r  r+   rW   )r+   r   ry   )r+   r  )r   r   r+   r#  )r   r5  r+   r   )Gr  
__future__r   collections.abcr   r   r   r   enumr   r   r2   r.   r   typestypingr	   r
   r-   r   _pytest._coder   r   _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.unittestr  r   rV   r   r   r9   r4   rM   r   rD   r  r  r  r%  r4  r   r7   r7   r7   r8   <module>   sz   
   

	
!