o
    h9                     @   sh  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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( 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"Z2de3d%e/d&e/d'e
e/ d(e(d)e4fd*d+Z5G d,d- d-e#Z6ed.d/d0ed1e&d d dfd2d3Z7ed.d4d0ed ed fd5d6Z8g fd7e	e9 d dfd8d9Z:d e4fd:d;Z;dS )<z4Discover 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)ScopeNNN	collectornameobjreturnUnitTestCasec                 C   sJ   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item r*   F/var/www/html/ai/venv/lib/python3.10/site-packages/_pytest/unittest.pypytest_pycollect_makeitem,   s   
r,   c                   @   s<   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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sDq5t|}tj| ||dV  d}q5|s|t| jdd }	|	d ur~tjd	d }
|
d u sr|	|
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_inject_setup_teardown_fixtures_inject_setup_class_fixturesession_fixturemanagerparsefactoriesgetTestCaseNamesr   TestCaseFunctionr'   r"   r#   getr%   r0   )selfr-   clsskippedloaderfoundsomethingr   xfuncobjruntestr(   r*   r*   r+   collectA   s8   
zUnitTestCase.collectr=   Nc                 C   sH   t |dddtjdd}|r||_t |dddtjd	d}|r"||_dS dS )
zxInjects a hidden auto-use fixture to invoke setUpClass/setup_method and corresponding
        teardown functions (#517).
setUpClasstearDownClassdoClassCleanupsF)scope	pass_selfsetup_methodteardown_methodNT)_make_xunit_fixturer   r   !_UnitTestCase__pytest_class_setupr   "_UnitTestCase__pytest_method_setup)r<   r=   class_fixturemethod_fixturer*   r*   r+   r4   `   s*   
z,UnitTestCase._inject_setup_teardown_fixtures)__name__
__module____qualname__
nofuncargsr   r   r   r   rD   typer4   r*   r*   r*   r+   r    <   s    
setup_nameteardown_namecleanup_namerH   rI   c                    s   t | |d t | |d d u rd u rd S |r!t | |dd  ndd  tj|jdd| d| j dd	td
td f fdd}|S )Nc                  W      d S Nr*   argsr*   r*   r+   <lambda>       z%_make_xunit_fixture.<locals>.<lambda>c                  W   rY   rZ   r*   r[   r*   r*   r+   cleanup      z$_make_xunit_fixture.<locals>.cleanupT
_unittest_	_fixture_)rH   autouser   requestr   r   c                 3   s    t | r| j}tjj|ddd ur5zr| |j n  W n ty4   r0 |       w d V  zd urIrF| |j n  W rR |  d S    d S r^ |  w    w NT)_use_item_location)r3   __unittest_skip_why__pytestr   r&   function)r<   rd   reasonr_   rI   setupteardownr*   r+   fixture   s<   

z$_make_xunit_fixture.<locals>.fixture)r2   rh   rn   valuerS   r   r   )r   rV   rW   rX   rH   rI   rn   r*   rk   r+   rL   z   s   " rL   c                	       sF  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-d	d
Zd-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 )3r:   TN_excinfounittest.TestCase	_testcasec                 C   s   | j d usJ t| j j| jS rZ   )parentr2   r   originalnamer<   r*   r*   r+   _getobj   s   zTestCaseFunction._getobjr   c                 C   sP   d | _ | jd us
J | j| j| _t| j| j| _t| dr&| j	  d S d S )N_request)
_explicit_tearDownrs   r   r   rr   r2   _objhasattrrw   _fillfixturesru   r*   r*   r+   rl      s   
zTestCaseFunction.setupc                 C   s(   | j d ur|    d | _ d | _d | _d S rZ   )rx   rr   ry   ru   r*   r*   r+   rm      s
   

zTestCaseFunction.teardowntestcasec                 C   rY   rZ   r*   r<   r|   r*   r*   r+   	startTest   r`   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|f 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pytracez8ERROR: Unknown Incompatible Exception representation:
%rrp   )r2   _pytest_codeExceptionInfoBaseExceptionfrom_exc_inforo   	traceback	TypeErrorformat_exceptioninsertr   joinr&   KeyboardInterruptfrom_current__dict__
setdefaultappend)r<   r   excinfovaluesr*   r*   r+   _addexcinfo   sB   


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<   r|   r   r*   r*   r+   addError   s   zTestCaseFunction.addErrorc                 C   s   |  | d S rZ   )r   r   r*   r*   r+   
addFailure  s   zTestCaseFunction.addFailurerj   c                 C   s6   zt jj|dd tjy   | t  Y d S w re   )rh   r   r&   r   r"   exc_info)r<   r|   rj   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 rZ   )r   strr&   r   r"   r   )r<   r|   r   rj   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   )rj   r   r&   r   r"   r   )r<   r|   rj   r   r*   r*   r+   addUnexpectedSuccess  s   z%TestCaseFunction.addUnexpectedSuccessc                 C   rY   rZ   r*   r}   r*   r*   r+   
addSuccess'  r`   zTestCaseFunction.addSuccessc                 C   rY   rZ   r*   r}   r*   r*   r+   stopTest*  r`   zTestCaseFunction.stopTestelapsedc                 C   rY   rZ   r*   )r<   r|   r   r*   r*   r+   addDuration-  r`   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   rY   rZ   r*   r[   r*   r*   r+   r]   G  r^   z*TestCaseFunction.runtest.<locals>.<lambda>)_pytest.debuggingr   rr   r   r   r   rs   r    r3   config	getoptionr   rx   setattrr   delattr)r<   r   r>   r*   r*   r+   rC   0  s   
	
"zTestCaseFunction.runtestr   c                    s&   t  |}|dd }|s|}|S )Nc                 S   s   | j jd S )N
__unittest)frame	f_globalsr;   )rA   r*   r*   r+   r]   V      z4TestCaseFunction._traceback_filter.<locals>.<lambda>)super_traceback_filterfilter)r<   r   r   
ntraceback	__class__r*   r+   r   Q  s   z"TestCaseFunction._traceback_filter)r   N)r|   rq   r   N)r   r   r   N)r|   rq   r   r   r   N)r   rZ   ) rQ   rR   rS   rT   rp   r   r   r   r   r   r   __annotations__rr   rv   rl   rm   r~   r   r   r   r   r   r   r   r   r   floatr   rC   	Tracebackr   __classcell__r*   r*   r   r+   r:      sf   
 
	
	

!








!
r:   T)tryfirstr)   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 rZ   )rh   r   r   ro   r*   r   r*   r+   r]   s  r   z+pytest_runtest_makereport.<locals>.<lambda>)r   r:   rp   popr   r   AttributeErrorr"   r#   r;   ro   SkipTestr   	from_callwhen)r)   r   r!   call2r*   r   r+   pytest_runtest_makereport]  s*   
r   )hookwrapperc                 #   sb    t | tr,dtjv r,tjd }|jj t  	 d fdd	}||j_d V   |j_d S d V  d S )Nr1   ztwisted.python.failurec                    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   rU   r   )r<   	exc_valueexc_typeexc_tbr   Failure__init__r*   r+   excstore  s   
z)pytest_runtest_protocol.<locals>.excstore)NNNN)r   r:   r"   r#   Failure__init__(check_testcase_implements_trial_reporter)r)   r(   r   r*   r   r+   pytest_runtest_protocol{  s   

r   donec                 C   s8   | rd S ddl m} ddlm} |t| | d d S )Nr   )classImplements)	IReporterr   )zope.interfacer   twisted.trial.itrialr   r:   r   )r   r   r   r*   r*   r+   r     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)boolr2   )r   r*   r*   r+   r3     s   r3   )<__doc__r"   r   typestypingr   r   r   r   r   r   r   r	   r
   r   _pytest._coder   rh   _pytest.compatr   r   _pytest.configr   _pytest.fixturesr   _pytest.nodesr   r   _pytest.outcomesr   r   r   r   _pytest.pythonr   r   r   _pytest.runnerr   _pytest.scoper   r!   twisted.trial.unittesttwistedr   TracebackTyper   r   objectr,   r    rU   r   rL   r:   r   r   intr   r3   r*   r*   r*   r+   <module>   s    

>
= '
