o
    Zh:                  	   @   s&  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$m%Z% ddl&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e.de
d  fd!d"Z/G d#d  d e!Z0G d$d% d%e"Z1ed&d'd(ed)e%d ddfd*d+Z2d,a3ed&d-d(edede.e.f fd.d/Z4de5fd0d1Z6dS )2z4Discover and run std-library "unittest" style tests.    N)Any)Callable)	Generator)Iterable)List)Optional)Tuple)Type)TYPE_CHECKING)Union)	getimfunc)is_async_function)hookimpl)FixtureRequest)	Collector)Item)exit)fail)skip)xfail)Class)Function)Module)CallInfo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(   G/var/www/html/lang_env/lib/python3.10/site-packages/_pytest/unittest.pypytest_pycollect_makeitem.   s   
r*   c                   @   sN   e Zd Z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   Tr   c                 c   s   ddl m} | j}t|ddsd S t|}|s&| | | | |   | jj	j
| dd | }d}|| jD ]}t| j|}t|ddsIq:t|}tj| ||dV  d}q:|st| jdd }	|	d urtjd	d }
|
d u sw|	|
jjkrtj| dd
V  d S d S d S d S )Nr   )
TestLoaderZ__test__T)r    F)r   ZcallobjrunTesttwisted.trial.unittest)r   )r    r+   r   getattr_is_skipped'_register_unittest_setup_method_fixture&_register_unittest_setup_class_fixtureZ_register_setup_class_fixturesession_fixturemanagerZparsefactoriesZgetTestCaseNamesr   TestCaseFunctionr&   r!   r"   getr$   r,   )selfr+   clsskippedloaderZfoundsomethingr   xfuncobjruntestr'   r(   r(   r)   collectB   s:   

zUnitTestCase.collectr7   Nc                    s   t |ddt |dddu rdu rdS t |d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).Z
setUpClassNZtearDownClassZdoClassCleanupsc                   S      d S Nr(   r(   r(   r(   r)   <lambda>i       zEUnitTestCase._register_unittest_setup_class_fixture.<locals>.<lambda>requestr   r   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r9  W    d S W    d S    w NT)Z_use_item_location)r7   r/   __unittest_skip_why__pytestr   r%   )rB   r7   reasoncleanupsetupteardownr(   r)   unittest_setup_class_fixturek   s&   

zYUnitTestCase._register_unittest_setup_class_fixture.<locals>.unittest_setup_class_fixtureZ_unittest_setUpClass_fixture_classTr   funcnodeidscopeZautouser.   r   r   r2   r3   Z_register_fixture__qualname__rO   )r6   r7   rK   r(   rG   r)   r1   b   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).Zsetup_methodNZteardown_methodrB   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 rC   )instancer/   rD   rE   r   r%   function)rB   r6   rF   rI   rJ   r(   r)   unittest_setup_method_fixture   s   z[UnitTestCase._register_unittest_setup_method_fixture.<locals>.unittest_setup_method_fixtureZ_unittest_setup_method_fixture_rT   TrM   rQ   )r6   r7   rV   r(   rU   r)   r0      s    

z4UnitTestCase._register_unittest_setup_method_fixture)__name__
__module__rR   
nofuncargsr   r   r   r   r=   typer1   r0   r(   r(   r(   r)   r   =   s
     (c                	       sN  e Zd ZU dZdZeeejj	e
   ed< dZed ed< dd Zd- fd	d
Zd- fddZd.ddZd/ddZ						d0ddZ						d0ddZdddeddfddZ	d1dddddeddfddZ	d2d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 )3r4   TN_excinfounittest.TestCase	_testcasec                 C   s   | j d usJ t| j j| jS r?   )parentr.   r   Zoriginalnamer6   r(   r(   r)   _getobj   s   zTestCaseFunction._getobjr   c                    sB   d | _ | jd us
J | j| j| _t| j| j| _t   d S r?   )	_explicit_tearDownr^   r   r   r]   r.   _objsuperrI   r_   	__class__r(   r)   rI      s
   zTestCaseFunction.setupc                    s2   t    | jd ur|   d | _d | _d | _d S r?   )rc   rJ   ra   r]   rb   r_   rd   r(   r)   rJ      s   


zTestCaseFunction.teardowntestcasec                 C   r>   r?   r(   r6   rf   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Zpytracez6ERROR: Unknown Incompatible Exception representation:
r[   )r.   _pytest_codeExceptionInfoBaseExceptionZfrom_exc_infovalue	traceback	TypeErrorformat_exceptioninsertr   joinr%   KeyboardInterruptZfrom_current__dict__
setdefaultappend)r6   rj   excinfo_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 )N   )
isinstancer   r%   msgru   r   r6   rf   rj   r(   r(   r)   addError   s   zTestCaseFunction.addErrorc                 C   s   |  | d S r?   )r   r   r(   r(   r)   
addFailure   s   zTestCaseFunction.addFailurerF   c                 C   s6   zt jj|dd tjy   | t  Y d S w rC   )rE   r   r%   r   r!   exc_info)r6   rf   rF   r(   r(   r)   addSkip   s
   zTestCaseFunction.addSkiprm   c                 C   s8   z	t t| W d S  t jy   | t  Y d S w r?   )r   strr%   r   r!   r   )r6   rf   rj   rF   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: Frn   )rF   r   r%   r   r!   r   )r6   rf   rF   r   r(   r(   r)   addUnexpectedSuccess  s   z%TestCaseFunction.addUnexpectedSuccessc                 C   r>   r?   r(   rg   r(   r(   r)   
addSuccess  ri   zTestCaseFunction.addSuccessc                 C   r>   r?   r(   rg   r(   r(   r)   stopTest  ri   zTestCaseFunction.stopTestelapsedc                 C   r>   r?   r(   )r6   rf   r   r(   r(   r)   addDuration!  ri   zTestCaseFunction.addDurationc              	   C   s   ddl m} | jd usJ ||  t| jr| j| d d S t| jts&J t| jp0t| jj}| j	
drG|sG| jj| _t| jddd  t| j| j| j z| j| d W t| j| j d S t| j| j w )Nr   )&maybe_wrap_pytest_function_for_tracing)resultZusepdbtearDownc                  W   r>   r?   r(   )argsr(   r(   r)   r@   ;  rA   z*TestCaseFunction.runtest.<locals>.<lambda>)Z_pytest.debuggingr   r]   r   r   r   r^   r   r/   configZ	getoptionr   ra   setattrr   delattr)r6   r   r8   r(   r(   r)   r<   $  s   
	
"zTestCaseFunction.runtestr}   c                    s&   t  |}|dd }|s|}|S )Nc                 S   s   | j jd S )NZ
__unittest)frame	f_globalsr5   )r:   r(   r(   r)   r@   J      z4TestCaseFunction._traceback_filter.<locals>.<lambda>)rc   _traceback_filterfilter)r6   r}   rt   Z
ntracebackrd   r(   r)   r   E  s   z"TestCaseFunction._traceback_filter)r   N)rf   r\   r   N)rj   rk   r   N)rf   r\   rj   rk   r   N)rm   r?   ) rW   rX   rR   rY   r[   r   r   ro   rp   rq   rr   __annotations__r]   r`   rI   rJ   rh   r   r   r   r   r   r   r   r   r   floatr   r<   	Tracebackr   __classcell__r(   r(   rd   r)   r4      sf   
 	

#








!
r4   T)Z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 r?   )rE   r   r   rs   r(   r}   r(   r)   r@   e  r   z+pytest_runtest_makereport.<locals>.<lambda>)r   r4   r[   popr}   r   AttributeErrorr!   r"   r5   rs   ZSkipTestr   Z	from_callwhen)r   r   r    Zcall2r(   r   r)   pytest_runtest_makereportQ  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 )
Nr-   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   rl   rZ   ru   )r6   	exc_valueexc_typeexc_tbr   ZFailure__init__r(   r)   excstore{  s   
z)pytest_runtest_protocol.<locals>.excstore)NNNN)r   r4   r!   r"   ZFailure__init__classImplements_has_runZtwisted.trial.itrialr   Zzope.interfacer   )r   r'   r   r   r   resr(   r   r)   pytest_runtest_protocoln  s&   


r   c                 C   s   t t| ddS )zDReturn True if the given object has been marked with @unittest.skip.Z__unittest_skip__F)boolr.   )r   r(   r(   r)   r/     s   r/   )7__doc__r!   rt   typestypingr   r   r   r   r   r   r   r	   r
   r   Z_pytest._codero   Z_pytest.compatr   r   Z_pytest.configr   Z_pytest.fixturesr   Z_pytest.nodesr   r   Z_pytest.outcomesr   r   r   r   Z_pytest.pythonr   r   r   Z_pytest.runnerr   rE   r    Ztwisted.trial.unittestZtwistedrr   TracebackTyperk   r   objectr*   r   r4   r   r   r   r   r/   r(   r(   r(   r)   <module>   sp   

l )&