o
    hg:                  	   @   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(   I/var/www/html/wtlms/venv/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   )
TestLoader__test__T)r    F)r   callobjrunTesttwisted.trial.unittest)r   )r    r+   r   getattr_is_skipped'_register_unittest_setup_method_fixture&_register_unittest_setup_class_fixture_register_setup_class_fixturesession_fixturemanagerparsefactoriesgetTestCaseNamesr   TestCaseFunctionr&   r!   r"   getr$   r.   )selfr+   clsskippedloaderfoundsomethingr   xfuncobjruntestr'   r(   r(   r)   collectB   s:   

zUnitTestCase.collectr<   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).
setUpClassNtearDownClass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)_use_item_location)r<   r1   __unittest_skip_why__pytestr   r%   )rK   r<   reasoncleanupsetupteardownr(   r)   unittest_setup_class_fixturek   s&   

zYUnitTestCase._register_unittest_setup_class_fixture.<locals>.unittest_setup_class_fixture_unittest_setUpClass_fixture_classTr   funcnodeidscopeautouser0   r   r   r5   r6   _register_fixture__qualname__rZ   )r;   r<   rU   r(   rQ   r)   r3   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).setup_methodNteardown_methodrK   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 rL   )instancer1   rN   rO   r   r%   function)rK   r;   rP   rS   rT   r(   r)   unittest_setup_method_fixture   s   z[UnitTestCase._register_unittest_setup_method_fixture.<locals>.unittest_setup_method_fixture_unittest_setup_method_fixture_rc   TrX   r]   )r;   r<   re   r(   rd   r)   r2      s    

z4UnitTestCase._register_unittest_setup_method_fixture)__name__
__module__r_   
nofuncargsr   r   r   r   rC   typer3   r2   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 )3r9   TN_excinfounittest.TestCase	_testcasec                 C   s   | j d usJ t| j j| jS rH   )parentr0   r   originalnamer;   r(   r(   r)   _getobj   s   zTestCaseFunction._getobjr   c                    sB   d | _ | jd us
J | j| j| _t| j| j| _t   d S rH   )	_explicit_tearDownrn   r   r   rm   r0   _objsuperrS   rp   	__class__r(   r)   rS      s
   zTestCaseFunction.setupc                    s2   t    | jd ur|   d | _d | _d | _d S rH   )rt   rT   rr   rm   rs   rp   ru   r(   r)   rT      s   


zTestCaseFunction.teardowntestcasec                 C   rG   rH   r(   r;   rw   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:
rk   )r0   _pytest_codeExceptionInfoBaseExceptionfrom_exc_infovalue	traceback	TypeErrorformat_exceptioninsertr   joinr%   KeyboardInterruptfrom_current__dict__
setdefaultappend)r;   r{   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%   msgr   r   r;   rw   r{   r(   r(   r)   addError   s   zTestCaseFunction.addErrorc                 C   s   |  | d S rH   )r   r   r(   r(   r)   
addFailure   s   zTestCaseFunction.addFailurerP   c                 C   s6   zt jj|dd tjy   | t  Y d S w rL   )rO   r   r%   r   r!   exc_info)r;   rw   rP   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 rH   )r   strr%   r   r!   r   )r;   rw   r{   rP   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   )rP   r   r%   r   r!   r   )r;   rw   rP   r   r(   r(   r)   addUnexpectedSuccess  s   z%TestCaseFunction.addUnexpectedSuccessc                 C   rG   rH   r(   rx   r(   r(   r)   
addSuccess  rz   zTestCaseFunction.addSuccessc                 C   rG   rH   r(   rx   r(   r(   r)   stopTest  rz   zTestCaseFunction.stopTestelapsedc                 C   rG   rH   r(   )r;   rw   r   r(   r(   r)   addDuration!  rz   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)resultusepdbtearDownc                  W   rG   rH   r(   )argsr(   r(   r)   rI   ;  rJ   z*TestCaseFunction.runtest.<locals>.<lambda>)_pytest.debuggingr   rm   r   r   r   rn   r   r1   config	getoptionr   rr   setattrr   delattr)r;   r   r=   r(   r(   r)   rB   $  s   
	
"zTestCaseFunction.runtestr   c                    s&   t  |}|dd }|s|}|S )Nc                 S   s   | j jd S )N
__unittest)frame	f_globalsr:   )r@   r(   r(   r)   rI   J      z4TestCaseFunction._traceback_filter.<locals>.<lambda>)rt   _traceback_filterfilter)r;   r   r   
ntracebackru   r(   r)   r   E  s   z"TestCaseFunction._traceback_filter)r   N)rw   rl   r   N)r{   r|   r   N)rw   rl   r{   r|   r   N)r~   rH   ) rg   rh   r_   ri   rk   r   r   r   r   r   r   __annotations__rm   rq   rS   rT   ry   r   r   r   r   r   r   r   r   r   floatr   rB   	Tracebackr   __classcell__r(   r(   ru   r)   r9      sf   
 	

#








!
r9   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 rH   )rO   r   r   r   r(   r   r(   r)   rI   e  r   z+pytest_runtest_makereport.<locals>.<lambda>)r   r9   rk   popr   r   AttributeErrorr!   r"   r:   r   SkipTestr   	from_callwhen)r   r   r    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   r}   rj   r   )r;   	exc_valueexc_typeexc_tbr   Failure__init__r(   r)   excstore{  s   
z)pytest_runtest_protocol.<locals>.excstore)NNNN)r   r9   r!   r"   Failure__init__classImplements_has_runtwisted.trial.itrialr   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.__unittest_skip__F)boolr0   )r   r(   r(   r)   r1     s   r1   )7__doc__r!   r   typestypingr   r   r   r   r   r   r   r	   r
   r   _pytest._coder   _pytest.compatr   r   _pytest.configr   _pytest.fixturesr   _pytest.nodesr   r   _pytest.outcomesr   r   r   r   _pytest.pythonr   r   r   _pytest.runnerr   rO   r    twisted.trial.unittesttwistedr   TracebackTyper|   r   objectr*   r   r9   r   r   r   r   r1   r(   r(   r(   r)   <module>   sp   

l )&