Your IP : 216.73.216.218


Current Path : /lib/python3.9/test/libregrtest/__pycache__/
Upload File :
Current File : //lib/python3.9/test/libregrtest/__pycache__/main.cpython-39.pyc

a

ؒd5d�@sddlZddlZddlZddlZddlZddlZddlZddlZddlZddl	Z	ddl
Z
ddlZddlm
Z
ddlmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZddlmZddl m!Z!ddl"m#Z#m$Z$m%Z%m&Z&ddl'm(Z(dZ)Gd	d
�d
�Z*d
dd�Z+dS)�N)�_parse_args)�	findtests�runtest�get_abs_module�	is_failed�STDTESTS�NOTTESTS�PROGRESS_MIN_TIME�Passed�Failed�
EnvChanged�Skipped�ResourceDenied�Interrupted�
ChildError�	DidNotRun)�setup_tests)�setup_pgo_tests)�removepy�count�format_duration�	printlist)�supportg^@c@s�eZdZdZdd�Zdd�Zd7dd�Zd8d
d�Zdd
�Zdd�Z	dd�Z
dd�Zdd�Zdd�Z
dd�Zdd�Zdd�Zdd�Zd d!�Zd"d#�Zd$d%�Zd&d'�Zd(d)�Zd*d+�Zd,d-�Zd.d/�Zd9d1d2�Zd3d4�Zd5d6�Zd0S):�RegrtestalExecute a test suite.

    This also parses command-line options and modifies its behavior
    accordingly.

    tests -- a list of strings containing test names (optional)
    testdir -- the directory in which to look for tests (optional)

    Users other than the Python test suite will certainly want to
    specify testdir; if it's omitted, the directory containing the
    Python test suite is searched for.

    If the tests argument is omitted, the tests listed on the
    command-line will be used.  If that's empty, too, then all *.py
    files beginning with test_ will be used.

    The other default arguments (verbose, quiet, exclude,
    single, randomize, findleaks, use_resources, trace, coverdir,
    print_slow, and random_seed) allow programmers calling main()
    directly to set the values that would normally be set by flags
    on the command line.
    cCs�d|_g|_g|_g|_g|_g|_g|_g|_g|_g|_	g|_
d|_d|_g|_
d|_t��|_d|_d|_d|_d|_d|_d|_d|_d|_dS)NF��)�ns�tests�selected�good�bad�skipped�resource_denieds�environment_changed�run_no_tests�
need_rerun�rerun�first_result�interrupted�
test_times�tracer�time�	monotonic�
start_time�
test_count�test_count_width�next_single_test�next_single_filename�
testsuite_xml�win_load_tracker�tmp_dir�worker_test_name��self�r8�+/usr/lib/python3.9/test/libregrtest/main.py�__init__6s0
zRegrtest.__init__cCs<t|j�t|j�Bt|j�Bt|j�Bt|j�Bt|j�BS�N)�setrr r!r"r#r$r6r8r8r9�get_executedas���zRegrtest.get_executedFc	Cs�|j}t|ttf�s*|s*|j�|j|f�t|t�rB|j�|�n�t|t	�rf|j
�|�|j�|�n�t|t�r~|j
�|�nvt|t
�r�|j�|�n^t|t�r�|s�|j�|�|j�|�n6t|t�r�|j�|�nt|t�r�d|_ntd|��|�rt|ttf��s|j�|�|j}|�r~ddlmm}|D]D}z|j�|�|��Wn&|j�yxt|tj d��Yn0�q8dS)NTzinvalid test result: %rr��file)!�name�
isinstancerrr)�appendZduration_secr
rrr!r"r
rr#rr r%rr$r(�
ValueError�remove�xml_data�xml.etree.ElementTree�etree�ElementTreer2Z
fromstringZ
ParseError�print�sys�
__stderr__)r7�resultr&�	test_namerE�ET�er8r8r9�accumulate_resultfs@






zRegrtest.accumulate_resultrcCst|}|��}|dur(d|d�d|��}t��|j}tjt|�d�}|�d|��}|rd|dd�}t|dd�dS)Nz
load avg: z.2f� )Zseconds���T)�flush)�
getloadavgr+r,r-�datetimeZ	timedelta�intrI)r7�line�emptyZload_avg�	test_timer8r8r9�log�szRegrtest.logcCsh|jjrdS||j��|j��}t|j�t|j�}|rN|jjsN|�d|��}|�d|�d|���dS)N�/�[z] )	r�quietr/r.�lenr r#�pgorZ)r7�
test_index�textrWZfailsr8r8r9�display_progress�szRegrtest.display_progressc
Cs�ttjdd�fi|��}|jr,gt_|_|j}|dur`ddlm	}||j�\}}||_||_
t|j�|j
r�|j
\}}}|dks�|dkr�d}	t|	tjdd�t�d�|jr�tj�|j�|_||_dS)Nrr)�parse_worker_argszwInvalid values for the --huntrleaks/-R parameters. The number of warmups and repetitions must be at least 1 each (1:1).T�r?rS�)rrJ�argv�xmlpathrZjunit_xml_listr2�worker_args�test.libregrtest.runtest_mprcr5r�args�
huntrleaksrI�stderr�exit�tempdir�os�path�
expanduserr)
r7�kwargsrrhrcrM�warmup�repetitions�_�msgr8r8r9�
parse_args�s&

zRegrtest.parse_argscCs�||_|jjrxtj�|jd�|_zDt|jd��$}|�	��
�}|g|_Wd�n1sX0YWntyvYn0|jj�rg|_t
�d�}ttj�tj|jj���T}|D]>}|�dd�d}|�
�}|�|�}|dur�|j�|���q�Wd�n1�s0Yt|j�|jj�r.t|j�tdd�}t��}|jj�r�|jjD]$}	|	|v�rl|�|	�|�|	��qTg|j_|jj�r�t |jjt!�t"��}
nt |jj||�}
|jj�s�|j�p�|jj�p�|
|_#n|j|_#|jj�r0|j#dd�|_#z"|
�$|j#d�}|
|d|_%Wnt&�y.Yn0|jj'�r�z|j#d|j#�$|jj'��=Wn*t(�y�t)d|jj't*j+d�Yn0|jj,�r�|jj-du�r�t.�/d	�|j_-t.�0|jj-�t.�1|j#�dS)
NZ
pynexttest�rz\btest_[a-zA-Z0-9_]+\b�#rrz1Couldn't find starting test (%s), using all testsr>i���)2rr�singlerorp�joinr4r1�open�read�strip�OSErrorZfromfile�re�compiler�SAVEDCWD�split�searchrB�grouprr_rrr�copyZexcluderjrD�addZtestdirr�listr<r�indexr0�
IndexError�startrCrIrJrl�	randomize�random_seed�randomZ	randrangeZseedZshuffle)r7r�fpZ	next_testZregexrW�matchZstdtestsZnottests�argZalltests�posr8r8r9�
find_tests�sr*


2









��
zRegrtest.find_testscCs|jD]}t|�qdSr;)rrI)r7r@r8r8r9�
list_testss
zRegrtest.list_testscCsX|D]N}t|tjj�rqt|tj�r0|�|�qt|tj�rt�|�rt	|�
��qdSr;)rA�unittest�loaderZ_FailedTestZ	TestSuite�_list_casesZTestCaserZ
match_testrI�id)r7�suite�testr8r8r9r�s
zRegrtest._list_casesc	Cs�dt_t�|jj|jj�|jD]L}t|j|�}ztj	�
|�}|�|�Wq tjyj|j
�|�Yq 0q |j
r�ttjd�ttt|j
�d�dtjd�t|j
tjd�dS)NFr>r��skipped:)r�verboseZset_match_testsr�match_testsZignore_testsrrr�ZdefaultTestLoaderZloadTestsFromNamer�ZSkipTestr!rBrIrJrlrr^r)r7rMZabstestr�r8r8r9�
list_casess
zRegrtest.list_casesc
Cs�d|j_d|j_d|j_|��|_|��|�d�t|j�}|j�	�|D�]}|j
}|j�|�|j
plg}|jpvg}dd�|D�}dd�|D�}d|j_|jj}|s�|�r
|jjdur�g|j_|jj�|�|jj�|�dd�|jj�}	|�d	|�d
|	�d��n|�d	|�d��t|j|�}||j_|j|dd
�t|t�rL�qPqL|j�rxttt|j�d�d�t|j�|��dS)NTFz'Re-running failed tests in verbose modecSsg|]^}}|�d�d�qS�rQr�r���.0Ztest_full_namerur8r8r9�
<listcomp>A�z/Regrtest.rerun_failed_tests.<locals>.<listcomp>cSsg|]^}}|�d�d�qSr�r�r�r8r8r9r�Br�z
matching: �, zRe-running z in verbose mode (�)z in verbose mode)r&r�z
failed again:)rr��failfastZverbose3�get_tests_resultr'rZr�r%�clearr@r&rB�errors�failuresr��extendr{rrPrArr rIrr^r�display_result)
r7Z
rerun_listrLrMr�r�Zerror_namesZ
failure_namesZorig_match_testsZmatchingr8r8r9�rerun_failed_tests0sD









zRegrtest.rerun_failed_testscCs
|jjrdSt�td|���|jr0td�t|j�|��}|rht�ttt	|�d�d�t
|�|jr�|jjs�t�|j
s�|js�|js�t	|j�dkr�tddd�ttt	|j�d�d	�|jj�r|jjd
d�t�td�|jdd
�D]\}}td|t|�f�q�|j
�r>t�ttt	|j
�d�d�t
|j
�|j�rpt�td�tt	|j�d���t
|j�|j�r�|jj�s�t�ttt	|j�d�d�t
|j�|j�r�t�tdtt	|j�d��t
|j�|j�rt�ttt	|j�d�d�t
|j�dS)Nz== Tests result: %s ==z(Test suite interrupted by signal SIGINT.r�zomitted:rZAllrQ)�endzOK.T)�reversez10 slowest tests:�
z- %s: %szfailed:z%{} altered the execution environment:r�z%s:zre-run testz
run no tests:)rr_rIr�r(r<rr=rr^rrr]r r!Z
print_slowr)�sortrr#�formatr&r$)r7ZomittedrYr�r8r8r9r�\sd���

�


zRegrtest.display_resultcCs�|jjr ddl}|jddd�|_tj��}d}|jjrJ|dt|jj�7}|�	|�d}t
|jd�D�]\}}t�
�}|}|r�d||f}|�||�|jr�d	}	tt��}
|jj|	t�|
d
�|
d}nt|j|�}|�|�t|t�r��q|t|�}t�
�|}|tk�rd|t|�f}nt|t��r.d}tj��D]&}
|
|v�r8|
�d
��r8t�|
��q8|jjrdt||j�rd�q|qd|�r�t|�dS)NrFT)�tracerzRun tests sequentiallyz (timeout: %s)rz%s -- %szDresult = runtest(self.ns, test_name); self.accumulate_result(result))�globals�localsrLz%s in %sztest.) rr�ZTracer*rJ�modules�keysZtimeoutrrZ�	enumeraterr+r,rb�dictr�Zrunctxr�rrPrAr�strr	r
�
startswithrZunloadr�rrI)r7r�Zsave_modulesrvZ
previous_testr`rMr-ra�cmdrrLrY�moduler8r8r9�run_tests_sequential�sJ






zRegrtest.run_tests_sequentialccs6|D]*}|V|jrdS|jjr|jrdSqqdSr;)r r�fail_env_changedr#)r7rrMr8r8r9�
_test_forever�szRegrtest._test_forevercCsxtdt��gtj���R�tdtjdd�dtj�tdt���t�	�}|rZtd|�tdt
�d�t��f�dS)	Nz==T)Zaliasedz	%s-endianz== cwd:z
== CPU count:z== encodings: locale=%s, FS=%sF)
rI�platformZpython_implementationrJ�versionr��	byteorderro�getcwd�	cpu_count�localeZgetpreferredencoding�getfilesystemencoding)r7r�r8r8r9�display_header�s�
��zRegrtest.display_headercCs�g}|jr|�d�n@|jjr0|jr0|�d�n&t|j|j|j|j|jf�sV|�d�|jrf|�d�|st|�d�d�	|�}|j
r�d|j
|f}|S)N�FAILUREzENV CHANGEDzNO TEST RUNZINTERRUPTED�SUCCESSr�z
%s then %s)r rBrr�r#�anyrr!r(r{r')r7rLr8r8r9r��s"�



zRegrtest.get_tests_resultc
Cs�|jjs.|jjs6|jjs6|jjs6|js6|jjs6|��|jjrh|jj\}}}|dkrhd}t	|t
jdd�|jjr~t	d|jj
�|jjr�|�t|j��|_d|_d|_n.t|j�|_d�t|j��|_t|j�d|_|jj�r�d	d
lm}t
jdk�rP|jdu�rPd	dlm}z|�|_Wn4t�yN}zt	d
|���WYd}~n
d}~00z(||�W|jdu�r�|j� �d|_n|jdu�r�|j� �d|_0n|�!�dS)N�zhWARNING: Running tests with --huntrleaks/-R and less than 3 warmup repetitions can give false positives!TrdzUsing random seedrz/{}rr)�run_tests_multiprocessZwin32)�WindowsLoadTrackerz%Failed to create WindowsLoadTracker: )"r�headerr_r]rzrrjr�rkrIrJ�stdoutr�r�Zforeverr�r�rr.r/�iterr�r^Zuse_mprir�r�r5Ztest.libregrtest.win_utilsr�r3�PermissionError�closer�)r7rsrtrurvr�r��errorr8r8r9�	run_tests�sV�����
$

�

zRegrtest.run_testscCs�|jrV|jrJt|jd�� }|�|jd�Wd�qV1s>0Ynt�|j�|jrz|j��}|jdd|j	j
d�t�t�
�|j}tdt|��td|���|j	jr�t�dt���dS)N�w�
T)Zshow_missingZsummary�coverdirzTotal duration: %szTests result: %szleaks %d)r1r0r|�writero�unlinkr*ZresultsZ
write_resultsrr�rIr+r,r-rr�Zrunleaks�system�getpid)r7r�rxZdurationr8r8r9�finalize*s 0
�zRegrtest.finalizec

Cs|jjs|jsdSddlmm}|�d�}dddd�}|jD]L}|�|�|D]8}z ||t|�	|d��7<WqRt
y�YqR0qRq@|��D]\}}|�|t
|��q�tj�tj|jj�}t|d��*}|�|�D]}	|�|	�q�Wd�n1s�0YdS)NrZ
testsuites)rr�r��wb)rrgr2rFrGrHZElementrBrV�getrC�itemsr<r�rorpr{rr�r|Ztostringlistr�)
r7rN�rootZtotalsr��k�vrg�f�sr8r8r9�save_xml_result?s$


 
zRegrtest.save_xml_resultcCst|jjr|jj|_|js`t��rVt�d�|_|jdurBt�d�|_tj�|jd�|_n
t	�
�|_tj�|j�|_dS)NZabs_builddirZsrcdirZbuild)rrnr4�	sysconfigZis_python_buildZget_config_varrorpr{�tempfileZ
gettempdir�abspathr6r8r8r9�set_temp_dirXs


zRegrtest.set_temp_dircCsVtj|jdd�t��}|jdur.d�|�}n
d�|�}|tj7}tj�	|j|�}|S)NT)�exist_okztest_python_worker_{}ztest_python_{})
ro�makedirsr4r�r5r�rZFS_NONASCIIrpr{)r7�pid�test_cwdr8r8r9�create_temp_dirns


zRegrtest.create_temp_dircCszddl}tj�|�|j�d�}td|j�|�|�D]>}tj�|�r^td|�t�	|�q6td|�t�
|�q6dS)Nrz
test_python_*zCleanup %s directoryzRemove directory: %szRemove file: %s)�globrorpr{�escaper4rI�isdirrZrmtreer�)r7r�rpr@r8r8r9�cleanup}szRegrtest.cleanupNc
Ks�|�|�|��|jjr,|��t�d�|��}zFtj|dd��$||j_	|�
||�Wd�n1sn0YWn>ty�}z&tj
tdd�t�|j�WYd}~n
d}~00dS)NrT)r])rm)rwr�rr�rJrmr�rZtemp_cwdrn�_main�
SystemExit�faulthandlerZdump_traceback_later�EXIT_TIMEOUT�code)r7rrrr��excr8r8r9�main�s

.z
Regrtest.maincCs.|jdur|j��Sttd�r*t��dSdS)NrTr)r3rT�hasattrror6r8r8r9rT�s



zRegrtest.getloadavgcCs|jdur$ddlm}||j|j�|jjr4td�|jjt_|jj	t_
t|j�|�|�|jj
rv|�
�t�d�|jjr�|��t�d�|��|��|jjr�|jr�|��|��|��|jr�t�d�|jr�t�d�|jjr�|jr�t�d�t�d�dS)Nr)�run_tests_workerzPress any key to continue...re�r�)r5rir�r�wait�inputr_rZPGOZpgo_extendedZPGO_EXTENDEDrr�r�rJrmr�r�r�Zverbose2r r�r�r�r(r�r#)r7rrrr�r8r8r9r��s8









zRegrtest._main)F)r)N)�__name__�
__module__�__qualname__�__doc__r:r=rPrZrbrwr�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�rTr�r8r8r8r9rs4+
'
I
,;7	
1
	rcKst�jfd|i|��dS)zRun the Python suite.rN)rr�)rrrr8r8r9r��sr�)N),rUr�r�ror�r�r�rJr�r�r+r�Ztest.libregrtest.cmdlinerZtest.libregrtest.runtestrrrrrrr	r
rrr
rrrrZtest.libregrtest.setuprZtest.libregrtest.pgorZtest.libregrtest.utilsrrrrr�rr�rr�r8r8r8r9�<module>s2DA