o
    #if<                  	   @   s8  d 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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%Z%ej&dd dk rddl'm(Z( erddl)Z)ddl*Z+eeee, e,ej-f ed f Z.dee"e f de/d e0d!e
d" fd#d$Z1G d%d" d"e Z2G d&d' d'e!Z3ed(d)d*ed+e$d d!dfd,d-Z4d.a5ed(d/d*ed!ede0e0f fd0d1Z6d!e7fd2d3Z8dS )4z4Discover and run std-library "unittest" style tests.    N)Any)Callable)	Generator)Iterable)List)Optional)Tuple)Type)TYPE_CHECKING)Union)is_async_function)hookimpl)FixtureRequest)	Collector)Item)exit)fail)skip)xfail)Class)Function)Module)CallInfo   )      )ExceptionGroupNNN	collectornameobjreturnUnitTestCasec                 C   sF   zt jd }t||jsW d S W n
 ty   Y d S w tj| ||dS )Nunittest)r   r    )sysmodules
issubclassTestCase	Exceptionr"   from_parent)r   r   r    ut r+   I/var/www/html/corbot_env/lib/python3.10/site-packages/_pytest/unittest.pypytest_pycollect_makeitem1   s   
r-   c                   @   sV   e Zd ZdZdd Zdeeeef  fddZ	de
ddfd	d
Zde
ddfddZdS )r"   Tc                 C   s
   |  dS )NrunTestr    selfr+   r+   r,   newinstanceE   s   
zUnitTestCase.newinstancer!   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#   r3   r    getattr_is_skipped'_register_unittest_setup_method_fixture&_register_unittest_setup_class_fixture_register_setup_class_fixturesession_fixturemanagerparsefactoriesr2   nodeidgetTestCaseNamesTestCaseFunctionr)   r$   r%   getr'   r.   )
r1   r3   clsskippedloaderfoundsomethingr   xruntestr*   r+   r+   r,   collectM   s8   

zUnitTestCase.collectrB   Nc                    s   t ddt dddu rdu rdS t ddd  dfdd	d
tdtd f 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 Nr+   r+   r+   r+   r,   <lambda>s       zEUnitTestCase._register_unittest_setup_class_fixture.<locals>.<lambda>r!   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 r+   r+   ).0_excr+   r+   r,   
<listcomp>{   s    zlUnitTestCase._register_unittest_setup_class_fixture.<locals>.process_teardown_exceptions.<locals>.<listcomp>   r   zUnittest class cleanup errors)r6   lenr   )	exc_infos
exceptions)rB   r+   r,   process_teardown_exceptionsu   s   
zXUnitTestCase._register_unittest_setup_class_fixture.<locals>.process_teardown_exceptionsrequestr   c                 3   s    | j }t|r|j}tj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)rB   r7   __unittest_skip_why__pytestr   r(   )rZ   rB   reason)cleanuprY   setupteardownr+   r,   unittest_setup_class_fixture   s0   


zYUnitTestCase._register_unittest_setup_class_fixture.<locals>.unittest_setup_class_fixture_unittest_setUpClass_fixture_classTr   funcr>   scopeautouser!   Nr6   r   r   r;   r<   _register_fixture__qualname__r>   )r1   rB   rc   r+   )r`   rB   rY   ra   rb   r,   r9   l   s$   

z3UnitTestCase._register_unittest_setup_class_fixturec                    sn   t |dd t |dd du rdu rdS dtdtd f 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_methodrZ   r!   r   c                 3   s\    | j }t|r|j}tjj|dd d ur || j d V  d ur,|| j d S d S r[   )instancer7   r]   r^   r   r(   function)rZ   r1   r_   ra   rb   r+   r,   unittest_setup_method_fixture   s   z[UnitTestCase._register_unittest_setup_method_fixture.<locals>.unittest_setup_method_fixture_unittest_setup_method_fixture_rq   Trf   rk   )r1   rB   rs   r+   rr   r,   r8      s    

z4UnitTestCase._register_unittest_setup_method_fixture)__name__
__module__rm   
nofuncargsr2   r   r   r   r   rH   typer9   r8   r+   r+   r+   r,   r"   @   s    8c                	       sJ  e Zd ZU dZdZeeejj	e
   ed< dd Zedd Zd. fd	d
Zd. fddZd/ddZd0ddZ						d1ddZ						d1ddZdddeddfddZ	d2dddddeddfddZ	d3ddded ddfd d!Zd/d"d#Zd/d$d%Zddd&eddfd'd(Zd.d)d*Zd+ejj	e
 dejjf fd,d-Z  Z S )4r@   TN_excinfoc                 C   s   t | jtsJ | j| jS rM   )
isinstanceparentr"   r    r   r0   r+   r+   r,   _getinstance   s   zTestCaseFunction._getinstancec                 C   s   | j S rM   )rp   r0   r+   r+   r,   	_testcase   s   zTestCaseFunction._testcaser!   c                    s   d | _ t   d S rM   )_explicit_tearDownsuperra   r0   	__class__r+   r,   ra      s   zTestCaseFunction.setupc                    s2   | j d ur|    d | _ d | _d | _t   d S rM   )r~   _obj	_instancer   rb   r0   r   r+   r,   rb      s   
zTestCaseFunction.teardowntestcaseunittest.TestCasec                 C   rL   rM   r+   r1   r   r+   r+   r,   	startTest      zTestCaseFunction.startTest
rawexcinfo_SysExcInfoTypec                 C   s   t |d|}ztjjt |}|j}|j}W nV tym   z5ztj	| }|
dd td|dd W n tjtfy@     tyQ   td|dd Y nw W n ty[     tjyj   tjj }Y nw Y nw | jdg | d S )	N_rawexcinfor   zCNOTE: Incompatible Exception Representation, displaying natively:

 Fpytracez6ERROR: Unknown Incompatible Exception representation:
ry   )r6   _pytest_codeExceptionInfoBaseExceptionfrom_exc_infovalue	traceback	TypeErrorformat_exceptioninsertr   joinr(   KeyboardInterruptfrom_current__dict__
setdefaultappend)r1   r   excinforR   valuesr+   r+   r,   _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 )NrU   )rz   r   r(   msgr   r   r1   r   r   r+   r+   r,   addError  s   zTestCaseFunction.addErrorc                 C   s   |  | d S rM   )r   r   r+   r+   r,   
addFailure  s   zTestCaseFunction.addFailurer_   c                 C   s6   zt jj|dd tjy   | t  Y d S w r[   )r^   r   r(   r   r$   exc_info)r1   r   r_   r+   r+   r,   addSkip  s
   zTestCaseFunction.addSkipr   c                 C   s8   z	t t| W d S  t jy   | t  Y d S w rM   )r   strr(   r   r$   r   )r1   r   r   r_   r+   r+   r,   addExpectedFailure  s
   z#TestCaseFunction.addExpectedFailureztwisted.trial.unittest.Todoc                 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   )r_   r   r(   r   r$   r   )r1   r   r_   r   r+   r+   r,   addUnexpectedSuccess$  s   z%TestCaseFunction.addUnexpectedSuccessc                 C   rL   rM   r+   r   r+   r+   r,   
addSuccess2  r   zTestCaseFunction.addSuccessc                 C   rL   rM   r+   r   r+   r+   r,   stopTest5  r   zTestCaseFunction.stopTestelapsedc                 C   rL   rM   r+   )r1   r   r   r+   r+   r,   addDuration8  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   rL   rM   r+   )argsr+   r+   r,   rN   R  rO   z*TestCaseFunction.runtest.<locals>.<lambda>)_pytest.debuggingr   rp   r   r    rz   r{   r"   r7   config	getoptionr   r~   setattrr   delattr)r1   r   r   rC   r+   r+   r,   rG   ;  s   
	zTestCaseFunction.runtestr   c                    s&   t  |}|dd }|s|}|S )Nc                 S   s   | j jd S )N
__unittest)frame	f_globalsrA   )rF   r+   r+   r,   rN   a      z4TestCaseFunction._traceback_filter.<locals>.<lambda>)r   _traceback_filterfilter)r1   r   r   
ntracebackr   r+   r,   r   \  s   z"TestCaseFunction._traceback_filterrj   )r   r   r!   N)r   r   r!   N)r   r   r   r   r!   N)r   rM   )!ru   rv   rm   rw   ry   r   r   r   r   r   r   __annotations__r|   propertyr}   ra   rb   r   r   r   r   r   r   r   r   r   r   floatr   rG   	Tracebackr   __classcell__r+   r+   r   r,   r@      sh   
 


#








!
r@   T)tryfirstitemcallc                    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 rM   )r^   r   r   r   r+   r   r+   r,   rN   z  r   z+pytest_runtest_makereport.<locals>.<lambda>)rz   r@   ry   popr   r   AttributeErrorr$   r%   rA   r   SkipTestr   	from_callwhen)r   r   r#   call2r+   r   r,   pytest_runtest_makereporth  s    
r   F)wrapperc                 #   s    t | trEdtjv rEtjd }|jj ts)ddlm} ddl	m
} |t| da	 d	 fdd	}||j_z
d V }W  |j_|S  |j_w d V }|S )
Nr5   ztwisted.python.failurer   )	IReporter)classImplementsTc                    sl   |d u r
t  | _n|d u rt|}|||f| _z | ||||d W d S  ty5    | ||| Y d S w )N)captureVars)r$   r   r   rx   r   )r1   	exc_valueexc_typeexc_tbr   Failure__init__r+   r,   excstore  s   
z)pytest_runtest_protocol.<locals>.excstore)NNNN)rz   r@   r$   r%   Failure__init__classImplements_has_runtwisted.trial.itrialr   zope.interfacer   )r   r*   r   r   r   resr+   r   r,   pytest_runtest_protocol  s&   


r   c                 C   s   t t| ddS )zDReturn True if the given object has been marked with @unittest.skip.__unittest_skip__F)boolr6   r/   r+   r+   r,   r7     s   r7   )9__doc__r$   r   typestypingr   r   r   r   r   r   r   r	   r
   r   _pytest._coder   _pytest.compatr   _pytest.configr   _pytest.fixturesr   _pytest.nodesr   r   _pytest.outcomesr   r   r   r   _pytest.pythonr   r   r   _pytest.runnerr   r^   version_infoexceptiongroupr   r#   twisted.trial.unittesttwistedr   TracebackTyper   r   objectr-   r"   r@   r   r   r   r   r7   r+   r+   r+   r,   <module>   st   

  &&