B
    `o6                 @   sZ  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( ddl'm)Z) erddl*Z*ddlm+Z+ eeee, e,ej-f ed f Z.e$e/e0e
d d d!d"Z1G d#d de"Z2e3e/e/e
e/ d$e4d%d&d'Z5G d(d) d)e#Z6ed*d+ee&d dd,d-d.Z7ed*d/eed d0d1d2Z8g fe	e9 dd3d4d5Z:e4d6d7d8Z;dS )9z4Discover 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)PyCollector)CallInfo)skipped_by_mark_key)unexpectedsuccess_key)_Scope)NNNUnitTestCase)	collectornameobjreturnc             C   sH   yt jd }t||jsd S W n tk
r2   d S X tj| ||d}|S )Nunittest)r   r    )sysmodules
issubclassTestCase	Exceptionr   from_parent)r   r   r    utitem r+   X/home/kop/projects/devel/pgwui/test_venv/lib/python3.7/site-packages/_pytest/unittest.pypytest_pycollect_makeitem.   s    
r-   c               @   s:   e Zd ZdZeeeef  dddZe	ddddZ
dS )	r   T)r!   c             c   s   ddl m} | j}t|dds"d S t|}|s@| | |   | jjj	| dd | }d}xL|
| jD ]<}t| j|}t|ddsqjt|}tj| ||dV  d}qjW |st| jdd }	|	d k	rtjd	d }
|
d ks|	|
jjkrtj| dd
V  d S )Nr   )
TestLoaderZ__test__T)r"   F)r   ZcallobjrunTestztwisted.trial.unittest)r   )r"   r.   r    getattr_is_skipped_inject_setup_teardown_fixturesZ_inject_setup_class_fixturesessionZ_fixturemanagerZparsefactoriesZgetTestCaseNamesr   TestCaseFunctionr(   r#   r$   getr&   r/   )selfr.   clsskippedloaderZfoundsomethingr   xfuncobjruntestr)   r+   r+   r,   collectC   s0    
zUnitTestCase.collectN)r7   r!   c             C   s@   t |dddddd}|r||_t |ddd	d
dd}|r<||_d	S )zxInjects a hidden auto-use fixture to invoke setUpClass/setup_method and corresponding
        teardown functions (#517).Z
setUpClassZtearDownClassZdoClassCleanupsclassF)scope	pass_selfZsetup_methodZteardown_methodNfunctionT)_make_xunit_fixtureZ!_UnitTestCase__pytest_class_setupZ"_UnitTestCase__pytest_method_setup)r6   r7   Zclass_fixtureZmethod_fixturer+   r+   r,   r2   b   s$    z,UnitTestCase._inject_setup_teardown_fixtures)__name__
__module____qualname__
nofuncargsr   r   r   r   r=   typer2   r+   r+   r+   r,   r   >   s   r   )r    
setup_nameteardown_namecleanup_namer?   r@   c                s   t | |d t | |d d kr,d kr,d S |rBt | |dd  ndd  tj|dd| d| j dttd	 d
 fdd}|S )Nc              W   s   d S )Nr+   )argsr+   r+   r,   <lambda>       z%_make_xunit_fixture.<locals>.<lambda>c              W   s   d S )Nr+   )rK   r+   r+   r,   cleanup   s    z$_make_xunit_fixture.<locals>.cleanupTZ	unittest_Z	_fixture_)r?   Zautouser   )NNN)requestr!   c             3   s   t | r| j}t| d k	rhyr4| |j n  W n* tk
rf   rZ |  n    Y nX d V  z$d k	rr| |j n  W d r |  n   X d S )N)r1   Z__unittest_skip_why__pytestr   rA   r'   )r6   rO   reason)rN   r@   setupteardownr+   r,   fixture   s,    




z$_make_xunit_fixture.<locals>.fixture)r0   rP   rT   rE   r   r   )r    rH   rI   rJ   r?   r@   rT   r+   )rN   r@   rR   rS   r,   rB   |   s      rB   c               @   s.  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ddZddd	d
ZdddddZdddddZddddddZddddddZdeddddZd+ddeddddZd,deddddZdddd d!Zdddd"d#Zedd$d%Zddd&d'Zejj	e
 dd(d)d*ZdS )-r4   TN_excinfozunittest.TestCase	_testcase)r!   c             C   sL   d | _ | jd k	st| j| j| _t| j| j| _t| drH| j	
  d S )N_request)_explicit_tearDownparentAssertionErrorr    r   rV   r0   _objhasattrrW   Z_fillfixtures)r6   r+   r+   r,   rR      s    
zTestCaseFunction.setupc             C   s(   | j d k	r|    d | _ d | _d | _d S )N)rX   rV   r[   )r6   r+   r+   r,   rS      s
    
zTestCaseFunction.teardown)testcaser!   c             C   s   d S )Nr+   )r6   r]   r+   r+   r,   	startTest   s    zTestCaseFunction.startTest_SysExcInfoType)
rawexcinfor!   c             C   s   t |d|}ytj|}|j |j W n tk
r   yry,tj| }|dd t	d
|dd W n@ t	jtfk
r    Y n& tk
r   t	d|f dd Y nX W n6 tk
r    Y n" t	jk
r   tjj }Y nX Y nX | jdg | d S )	N_rawexcinfor   zCNOTE: Incompatible Exception Representation, displaying natively:

 F)Zpytracez8ERROR: Unknown Incompatible Exception representation:
%rrU   )r0   _pytest_codeExceptionInfovalue	traceback	TypeErrorformat_exceptioninsertr   joinr'   KeyboardInterruptBaseExceptionZfrom_current__dict__
setdefaultappend)r6   r`   excinfovaluesr+   r+   r,   _addexcinfo   s2    

zTestCaseFunction._addexcinfo)r]   r`   r!   c             C   sF   y"t |d tjr t|d j W n tk
r6   Y nX | | d S )N   )
isinstancer   r'   msgrh   rs   )r6   r]   r`   r+   r+   r,   addError   s    zTestCaseFunction.addErrorc             C   s   |  | d S )N)rs   )r6   r]   r`   r+   r+   r,   
addFailure   s    zTestCaseFunction.addFailure)r]   rQ   r!   c             C   s@   yt | W n. t jk
r:   d| jt< | t  Y nX d S )NT)r   r'   _storer   rs   r#   exc_info)r6   r]   rQ   r+   r+   r,   addSkip  s
    
zTestCaseFunction.addSkiprb   )r]   r`   rQ   r!   c             C   s:   yt t| W n$ t jk
r4   | t  Y nX d S )N)r   strr'   rs   r#   rz   )r6   r]   r`   rQ   r+   r+   r,   addExpectedFailure  s    z#TestCaseFunction.addExpectedFailurec             C   s   || j t< d S )N)ry   r   )r6   r]   rQ   r+   r+   r,   addUnexpectedSuccess  s    z%TestCaseFunction.addUnexpectedSuccessc             C   s   d S )Nr+   )r6   r]   r+   r+   r,   
addSuccess  s    zTestCaseFunction.addSuccessc             C   s   d S )Nr+   )r6   r]   r+   r+   r,   stopTest  s    zTestCaseFunction.stopTestc             C   s$   t |dd}t | dd}t|p |S )zgReturn True if the given unittest method (or the entire class) is marked
        with @expectedFailure.Z__unittest_expecting_failure__F)r0   bool)r6   Ztest_methodZexpecting_failure_methodZexpecting_failure_classr+   r+   r,   _expecting_failure  s    
z#TestCaseFunction._expecting_failurec          	   C   s   ddl m} | jd k	st||  t| jr:| j| d nf| jdrlt| jsl| jj	| _
t| jddd  t| j| j| j z| j| d W d t| j| j X d S )Nr   )&maybe_wrap_pytest_function_for_tracing)resultZusepdbtearDownc              W   s   d S )Nr+   )rK   r+   r+   r,   rL   ;  rM   z*TestCaseFunction.runtest.<locals>.<lambda>)Z_pytest.debuggingr   rV   rZ   r   r    configZ	getoptionr1   r   rX   setattrr   delattr)r6   r   r+   r+   r,   r<   '  s    

zTestCaseFunction.runtest)rq   r!   c             C   s*   t | | |jdd }|r&||_d S )Nc             S   s   | j jd S )NZ
__unittest)frame	f_globalsr5   )r:   r+   r+   r,   rL   J  rM   z2TestCaseFunction._prunetraceback.<locals>.<lambda>)r   _prunetracebackrg   filter)r6   rq   rg   r+   r+   r,   r   E  s
    
z TestCaseFunction._prunetraceback)rb   )rb   )rC   rD   rE   rF   rU   r   r   rc   rd   re   rm   __annotations__rV   rR   rS   r^   rs   rw   rx   r|   r{   r}   r~   r   r   r   r   r<   r   r+   r+   r+   r,   r4      s,   
	"		
r4   T)Ztryfirst)r*   callr!   c                s   t | tr<| jr<| jd|_y|`W n tk
r:   Y nX tj	d}|r|jrt |jj
|jr|j td   fdd|j}|j|_d S )Nr   r"   c                  s   t t jS )N)rP   r   r|   rf   r+   )rq   r+   r,   rL   c  rM   z+pytest_runtest_makereport.<locals>.<lambda>)ru   r4   rU   poprq   r   AttributeErrorr#   r$   r5   rf   ZSkipTestr   Z	from_callwhen)r*   r   r"   Zcall2r+   )rq   r,   pytest_runtest_makereportP  s    
r   )Zhookwrapper)r*   r!   c             #   s\   t | trRdtjkrRtjd }|jj t  d fdd	}||j_d V   |j_nd V  d S )Nztwisted.trial.unittestztwisted.python.failurec                sn   |d krt  | _n|d kr$t|}|||f| _y | ||||d W n" tk
rh    | ||| Y nX d S )N)captureVars)r#   rz   ra   rG   rh   )r6   	exc_valueexc_typeexc_tbr   )Failure__init__r+   r,   excstorer  s    z)pytest_runtest_protocol.<locals>.excstore)NNNN)ru   r4   r#   r$   ZFailure__init__(check_testcase_implements_trial_reporter)r*   r)   r   r+   )r   r,   pytest_runtest_protocolk  s    

r   )doner!   c             C   s8   | rd S ddl m} ddlm} |t| | d d S )Nr   )classImplements)	IReporterrt   )Zzope.interfacer   Ztwisted.trial.itrialr   r4   rp   )r   r   r   r+   r+   r,   r     s    
r   )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)r   r0   )r    r+   r+   r,   r1     s    r1   )<__doc__r#   rg   typestypingr   r   r   r   r   r   r   r	   r
   r   Z_pytest._coderc   rP   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   Z_pytest.skippingr   r   r"   r   rm   TracebackTyper_   r|   objectr-   r   rG   r   rB   r4   r   r   intr   r1   r+   r+   r+   r,   <module>   sl   ?7 
