o
    PZh/                     @   s  d dl Z edkreddedd d ZedkZed Zer7d dlm	Z	 d d	l
mZmZmZmZmZ nd dlm	Z	 d d	lmZmZmZmZm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add Zdd Zdd ZdS )    N__main__zThis module is for import only.zpygame.testsz.test_utils.test_runner)import_submodule)prepare_test_envrun_testcombine_resultsget_test_resultsTEST_RESULTS_START)pformatFc            ,         s  t rtdda  }|dd}|dd}|dd}|dd}|d	d}|d
d|dd|dd}|dtj|dd}	|dd}
|
sYd|	vrY|	d7 }	|rdd|	vrd|	d7 }	nd|	vrl|	d7 }	|	d7 }	|	d7 }	t \}}}t	d}t
}t }|durd|d|g}tj||}|	n|	tjd|  d| | r fdd | D }ng }tt|D ]}||D ]
}| |f  qq|}g }|D ]Y}|d!d"  d#}zt|}W n ty   || Y qw z|j}W n ty   t| d$ || Y qw |D ]}||	v r)td%| d&| d'  nq|| q~~~i }d(i i}|d( }|sF|dure|du rOt }||d)< td*| d+ t| t| |s|	|d< t }|D ]}|t|fi | qrt | }nt rd!d,l!m" nd!d,l#m" d-d.|	gfd/d d0D  	fd1d2}dkrfd3d4} nt$} t }| ||D ]7\}}!\}"}#tj|| d5}$|!\}!	t%|#}%|%r||% ni ||< || |"|#|!|$	|d6 qt | }t&||\}&}'t'|\}(})}*|(|d7< |'|d8< |)|d9< |*|d:< || |s;|(|&kr;t(d;|(|&f |sCt|' n
tt) tt*| |durjt+|d<}+z|+,t*| W |+-  n|+-  w t./| |(|)|* fS )=a  Run the Pygame unit test suite and return (total tests run, fails dict)

    Positional arguments (optional):
    The names of tests to include. If omitted then all tests are run. Test
    names need not include the trailing '_test'.

    Keyword arguments:
    incomplete - fail incomplete tests (default False)
    usesubprocess - run all test suites in the current process
                   (default False, use separate subprocesses)
    dump - dump failures/errors as dict ready to eval (default False)
    file - if provided, the name of a file into which to dump failures/errors
    timings - if provided, the number of times to run each individual test to
              get an average run time (default is run each test once)
    exclude - A list of TAG names to exclude from the run. The items may be
              comma or space separated.
    show_output - show silenced stderr/stdout on errors (default False)
    all - dump all results, not just errors (default False)
    randomize - randomize order of tests (default False)
    seed - if provided, a seed randomizer integer
    multi_thread - if provided, the number of THREADS in which to run
                   subprocessed tests
    time_out - if subprocess is True then the time limit in seconds before
               killing a test (default 30)
    fake - if provided, the name of the fake tests package in the
           run_tests__tests subpackage to run instead of the normal
           Pygame tests
    python - the path to a python executable to run subprocessed tests
             (default sys.executable)
    interactive - allow tests tagged 'interactive'.

    Return value:
    A tuple of total number of tests run, dictionary of error information. The
    dictionary is empty if no errors were recorded.

    By default individual test modules are run in separate subprocesses. This
    recreates normal Pygame usage where pygame.init() and pygame.quit() are
    called only once per program execution, and avoids unfortunate
    interactions between test modules. Also, a time limit is placed on test
    execution, so frozen tests are killed when there time allotment expired.
    Use the single process option if threading is not working properly or if
    tests are taking too long. It is not guaranteed that all tests will pass
    in single process mode.

    Tests are run in a randomized order if the randomize argument is True or a
    seed argument is provided. If no seed integer is provided then the system
    time is used.

    Individual test modules may have a corresponding *_tags.py module,
    defining a __tags__ attribute, a list of tag strings used to selectively
    omit modules from a run. By default only the 'interactive', 'ignore', and
    'subprocess_ignore' tags are ignored. 'interactive' is for modules that
    take user input, like cdrom_test.py. 'ignore' and 'subprocess_ignore' for
    for disabling modules for foreground and subprocess modes respectively.
    These are for disabling tests on optional modules or for experimental
    modules with known problems. These modules can be run from the console as
    a Python program.

    This function can only be called once per Python session. It is not
    reentrant.

    z%run() was already called this sessionTZusesubprocessFdumpfileN	randomizeseedZmulti_thread   Ztime_outx   Zfakepythonexclude interactive)r   subprocess_ignore)r   ignore)r   )Zpython3_ignore)ZSDL2_ignorez^(.+_test)\.py$r   Zrun_tests__testsz%s.%%sz%s.%%s_testc                    s&   g | ]}| d r | p| qS )_test)endswith).0m)fmt1fmt2r   P/var/www/auris/lib/python3.10/site-packages/pygame/tests/test_utils/run_tests.py
<listcomp>   s   & zrun.<locals>.<listcomp>r   Z_tagsz has no tags: ignoringz	skipping z (tag 'z')Z__meta__Zrandom_seedz
RANDOM SEED USED: 
)proc_in_time_or_killz	--exclude,c                    s   g | ]}  |rd | qS )z--)get)r   field)kwdsr   r   r      s    )r   
incompleteZ
unbuffered	verbosityc                    s:   t d|    dt| g }| |f|dfS )Nzloading z-m)envwd)printtest_runner_mod)modulecmd)option_pythonoption_time_outpass_on_argsr"   test_envworking_dirr   r   sub_test   s   zrun.<locals>.sub_testc                    s   t jj| |d dS )NF)Zstop_on_errorZnum_workers)pygamethreadstmap)fargs)option_multi_threadr   r   r7      s   zrun.<locals>.tmapz.py)return_code
raw_returnr.   	test_filer2   r3   r-   Ztotal_testscombinedZtotal_errorsZtotal_failureszKSomething went wrong in the Test Machinery:
total: %d != untrusty_total: %dw)0was_runRuntimeErrorcopyr$   popsys
executabler   recompiletest_pkg_nametempfilemkdtempjoinospathenvironsortedlistdirfindallappendr   ImportErrorZ__tags__AttributeErrorr+   timerandomr   shuffleupdater   is_pygame_pkgZ!pygame.tests.test_utils.async_subr"   Ztest.test_utils.async_submapr	   r   count_resultsAssertionErrorr
   r   openwritecloseshutilrmtree),r9   r&   optionsZoption_usesubprocessZoption_dumpZoption_fileZoption_randomizeZoption_seedZoption_fakeZoption_excludeZoption_interactiveZmain_dirZtest_subdirZfake_test_subdirZTEST_MODULE_REZtest_mods_pkg_nameZworking_dir_tempZtest_modulesr8   matchtmpnameZtag_module_nameZ
tag_moduletagstagresultsZmeta_resultsmetatr-   r4   r7   r.   r;   r<   r=   Ztest_resultsZuntrusty_totalr>   totalZn_errorsZ
n_failuresZresults_filer   )
r   r   r&   r:   r/   r0   r1   r"   r2   r3   r   run)   s  B














rl   c                 C   sf   d } }}|   D ]#}|ddr|d7 }|d7 }q
||d 7 }||d 7 }||d 7 }q
|||fS )Nr   r;   r   Z	num_testsZ
num_errorsZnum_failures)valuesr$   )rh   rk   errorsZfailuresresultr   r   r   r[   G  s   

r[   c                  O   s.   t | i |\}}|rtd td dS )zRun the tests, and if there are failures, exit with a return code of 1.

    This is needed for various buildbots to recognise that the tests have
    failed.
    r   r   N)rl   rD   exit)r9   kwargsrk   Zfailsr   r   r   run_and_exitU  s   
rr   ) rD   __name__rA   rK   splitrH   rY   r,   Zpygame.tests.test_utilsr   Z#pygame.tests.test_utils.test_runnerr   r   r   r	   r
   Ztest.test_utilsZtest.test_utils.test_runnerr5   Zpygame.threadsrL   rF   r`   rI   rU   rV   pprintr   r@   rl   r[   rr   r   r   r   r   <module>   s4       