B
    u9as(                 @   sj  d dl Z d dlZd dlZd dlZd dlZd dlZd dlZd dlZd dlZd dl	Z	d dl
Z
d dlmZ d dlmZmZ d dlmZ d dlmZ dZd ZdZdZd	Zd
ZdZdZedededededededediZdZddddddddddg
Ze Z g Z!d d! Z"d"d# Z#d9d$d%Z$dee fd&d'Z%d(d) Z&e 'd*d+Z(d,d- Z)d.d/ Z*d0d1 Z+d2d3 Z,d:d5d6Z-d7d8 Z.dS );    N)support)dash_Rclear_caches)saved_test_environment)print_warning   iz	%s passedz	%s failedz%s failed (env changed)z
%s skippedz%s skipped (resource denied)z%s interruptedz
%s crashedz%s run no testsg      >@Ztest_grammarZtest_opcodesZ	test_dictZtest_builtinZtest_exceptionsZ
test_typesZtest_unittestZtest_doctestZtest_doctest2Ztest_supportc             C   s,   | j }|ttttfkrdS |tkr(|jS dS )NFT)resultPASSEDRESOURCE_DENIEDSKIPPEDTEST_DID_NOT_RUNENV_CHANGEDZfail_env_changed)r   nsok r   /usr/lib/python3.7/runtest.py	is_failedC   s    r   c             C   s   t | jd}|| j S )Nz%s)_FORMAT_TEST_RESULTgetr   	test_name)r   Zfmtr   r   r   format_test_resultL   s    r   c             C   s   | pt jt jtpt jS )N)ospathdirname__file__curdir)r   r   r   r   findtestdirQ   s    r!   c       	      C   sv   t | } t| }g }t||B }xF|D ]>}tj|\}}|d d dkr(|dkr(||kr(|| q(W |t| S )N   Ztest_)z.py )r!   r   listdirsetr   splitextappendsorted)	testdirZstdtestsZnottestsnamestestsZothersnamemodZextr   r   r   	findtestsU   s    

 r.   c             C   s    | ds| jr|S d| S d S )Nztest.)
startswithr)   )r   r   r   r   r   get_abs_moduleb   s    r0   
TestResultz#test_name result test_time xml_datac                sJ  | j }| jd k	}|r$tj| jdd t }z t| j | j	rFg nd  t_
}| jr\dt_|rdt_t }tj}tj}z@|t_|t_t| |dd}	|	tkr| }
||
 |  W d |t_|t_X n| jt_t| || j d}	|rdd lm  m   fdd|D }nd }t | }t||	||S |r>t  d t_
X d S )NT)exitF)display_failurer   c                s   g | ]}  |d qS )zus-ascii)Ztostringdecode).0x)ETr   r   
<listcomp>   s    z_runtest.<locals>.<listcomp>)Zverbose3ZtimeoutfaulthandlerZdump_traceback_latertimeZperf_counterr   Zset_match_testsZmatch_testsZxmlpathZjunit_xml_listZfailfastverboseioStringIOsysstdoutstderr_runtest_innerr   getvaluewriteflushZxml.etree.ElementTreeZetreeZElementTreer1   Zcancel_dump_traceback_later)r   r   Zoutput_on_failureZuse_timeoutZ
start_timeZxml_liststreamZorig_stdoutZorig_stderrr   outputZxml_dataZ	test_timer   )r7   r   _runtestm   sL    


rG   c             C   sN   y
t | |S    | js<t }td| d| tjdd t|tdd S d S )Nztest z crashed -- T)filerD   g        )	rG   pgo	traceback
format_excprintr>   r@   r1   FAILED)r   r   msgr   r   r   runtest   s    
rO   c             C   sL   t  }|| }x|jD ]}t|tjd qW |jr>tdt	| d S )N)rH   zerrors while loading tests)
unittestZ
TestLoaderZloadTestsFromModuleerrorsrL   r>   r@   	Exceptionr   Zrun_unittest)
the_moduleloaderr+   errorr   r   r   _test_module   s    
rV   c          	   C   s   t | |}t| t|}t|dd }|d kr>tt|}z"| j	rTt
| ||}n
|  d}W d t|| j X t  tjrdt_t| dttj d ttj tj  t  |S )NZ	test_mainFTz	 created z uncollectable object(s).)r0   r   Zunload	importlibimport_modulegetattr	functoolspartialrV   Z
huntrleaksr   cleanup_test_droppingsr;   
gc_collectgcZgarbageenvironment_alteredr   lenFOUND_GARBAGEextendclearZreap_children)r   r   ZabstestrS   Ztest_runnerrefleakr   r   r   _runtest_inner2   s(    



re   Tc          
   C   s  dt _| jrd}y8t  t|| j| j| jd}t| |}W d Q R X W nD t jk
r } z&| js~| js~t	| d| dd t
S d }~X Y  n tjk
r } z&| js| jst	| d| dd tS d }~X Y n t jk
r( } z4d| d}|r| d| }t	|tjdd	 tS d }~X Y nf t jk
r>   tS  tk
rX   t	  tS    | jst }t	d| d
| tjdd	 tS |rtS |jrtS tS )NF)rI   z skipped -- T)rD   ztest z failedz -- )rH   rD   z crashed -- )r   r_   rI   r   r   r;   quietre   ZResourceDeniedrL   r   rP   ZSkipTestr   Z
TestFailedr>   r@   rM   ZTestDidNotRunr   KeyboardInterruptINTERRUPTEDrJ   rK   Zchangedr   r   )r   r   r3   Zenvironmentrd   rN   excr   r   r   rA      sJ    rA   c             C   s  t   xt jdfD ]}tj|s&qtj|rHdd l}d|j }}n*tj	|rbdtj
 }}ntd|d|rtd| ||f  dt _y.dd l}t||j|jB |jB  || W q tk
 r } z"t|  d	| d
|d|  W d d }~X Y qX qW d S )NZdb_homer   Z	directoryrH   zos.path says z) exists but is neither directory nor filez%r left behind %s %rTz left behind  z and it couldn't be removed: )r   r]   ZTESTFNr   r   existsisdirshutilZrmtreeisfileunlinkRuntimeErrorr   r_   statchmodS_IRWXUS_IRWXGS_IRWXOrR   )r   r;   r,   rm   kindZnukerrq   ri   r   r   r   r\   *  s(    
r\   )N)T)/collectionsr9   rZ   r^   rW   r<   r   r>   r:   rJ   rP   Ztestr   Ztest.libregrtest.refleakr   r   Ztest.libregrtest.save_envr   Ztest.libregrtest.utilsr   r   rM   r   r   r   rh   ZCHILD_ERRORr   r   ZPROGRESS_MIN_TIMEZSTDTESTSr%   ZNOTTESTSra   r   r   r!   r.   r0   
namedtupler1   rG   rO   rV   re   rA   r\   r   r   r   r   <module>   sp   	
9
,
0