U
    Ã9%eô&  ã                   @   s®   d dl Z d dlZd dlZd dlmZ d dlZd dlZzd dlZW n ek
rX   dZ	Y nX dZ	zd dl
Z
W n ek
r‚   dZY nX dZG dd„ dejƒZedkrªe ¡  dS )é    N)ÚcudaFTc                   @   sÈ   e Zd ZdZddœdd„Zdd„ Zdd	„ Zd
d„ Zdd„ Zdd„ Z	dd„ Z
dd„ Ze e ¡  d¡dd„ ƒZdd„ Zdd„ Zdd„ Zdd„ Zdd „ Zd!d"„ Ze ed#¡d$d%„ ƒZe ed&¡d'd(„ ƒZdS ))ÚTestCasezßThese test cases are meant to test the Numba test infrastructure itself.
    Therefore, the logic used here shouldn't use numba.testing, but only the
    upstream unittest, and run the numba test suite only in a subprocess.N©Úsubp_kwargsc                C   sL   |pi }t jdddgt|ƒ }tj|f|Ž}| d¡ ¡ }dd„ |D ƒ}|S )zX
        Use `subp_kwargs` to pass extra argument to `subprocess.check_output`.
        z-mznumba.runtestsz-lzUTF-8c                 S   s   g | ]}|  ¡ r|‘qS © )Ústrip©Ú.0Úliner   r   úX/var/www/html/Darija-Ai-API/env/lib/python3.8/site-packages/numba/tests/test_runtests.pyÚ
<listcomp>%   s      z2TestCase.get_testsuite_listing.<locals>.<listcomp>)ÚsysÚ
executableÚlistÚ
subprocessÚcheck_outputÚdecodeÚ
splitlines)ÚselfÚargsr   ÚcmdZ	out_bytesÚlinesr   r   r   Úget_testsuite_listing   s    zTestCase.get_testsuite_listingc                 C   sB   |   |g¡}|d d… D ]$}d ||¡}| j| |¡|d qd S )Néÿÿÿÿz{!r} not startswith {!r})Úmsg)r   ÚformatÚ
assertTrueÚ
startswith)r   ÚprefixÚlistingÚlnÚerrmsgr   r   r   Úcheck_listing_prefix(   s    zTestCase.check_listing_prefixc                 C   s`   |   |¡}|d }|  d|k¡ t| d¡d ƒ}|  t|ƒt|d |d ƒ¡ |  ||¡ |S )zR
        Check that the reported numbers of tests are at least *minsize*.
        r   útests foundú r   é   é   )r   r   ÚintÚsplitÚassertInÚlenÚrangeÚassertGreaterEqual)r   r   Úminsizer   Ú	last_lineÚnumberr   r   r   Úcheck_testsuite_size.   s    
zTestCase.check_testsuite_sizec                 C   s@   |   |d¡}|  tdd„ |D ƒƒ¡ |  tdd„ |D ƒƒ¡ d S )Niˆ  c                 s   s   | ]}d |kV  qdS )znumba.cuda.tests.Nr   r   r   r   r   Ú	<genexpr>?   s     z%TestCase.check_all.<locals>.<genexpr>c                 s   s   | ]}d |kV  qdS )znumba.tests.npyufunc.test_Nr   r   r   r   r   r1   A   s   ÿ)r0   r   Úany)r   Zidsr   r   r   r   Ú	check_all<   s
    ÿzTestCase.check_allc                 C   s   t dd„ |ƒS )z|returns a filter on strings starting with 'numba.', useful for
        selecting the 'numba' test names from a test listing.c                 S   s
   |   d¡S )Nznumba.)r   )Úxr   r   r   Ú<lambda>G   ó    z8TestCase._get_numba_tests_from_listing.<locals>.<lambda>)Úfilter)r   r   r   r   r   Ú_get_numba_tests_from_listingD   s    z&TestCase._get_numba_tests_from_listingc                 C   s   |   g ¡ d S )N©r3   ©r   r   r   r   Útest_defaultI   s    zTestCase.test_defaultc                 C   s   |   dg¡ d S )Núnumba.testsr9   r:   r   r   r   Útest_allL   s    zTestCase.test_allc                 C   s"   t  ¡ rdnd}|  dg|¡ d S )Néd   r%   znumba.cuda.tests)r   Úis_availabler0   )r   r-   r   r   r   Ú	test_cudaO   s    zTestCase.test_cudazNO CUDAc                 C   s,   |   d¡ |   d¡ |   d¡ |   d¡ d S )Nznumba.cuda.tests.cudadrvznumba.cuda.tests.cudapyznumba.cuda.tests.nocudaznumba.cuda.tests.cudasim)r"   r:   r   r   r   Útest_cuda_submodulesU   s    


zTestCase.test_cuda_submodulesc                 C   s0   |   dgd¡ |   dgd¡ |   ddgd¡ d S )Nznumba.tests.test_storesliceé   znumba.tests.test_nested_callsé
   é   ©r0   r:   r   r   r   Útest_module\   s    ÿÿzTestCase.test_modulec                 C   s   |   dgd¡ d S )Núnumba.tests.npyufuncé2   rE   r:   r   r   r   Útest_subpackagec   s    zTestCase.test_subpackagec                 C   s   |   dddgd¡ d S )Nz--randomz0.1rG   é   rE   r:   r   r   r   Útest_randomf   s     ÿzTestCase.test_randomc                    sˆ   ‡ fdd„}ddg}|dgƒ}|D ]`}|d|dgƒ}|d|dgƒ}ˆ   ||| ¡ |d| dgƒ}|d	| dgƒ}ˆ   ||| ¡ q"d S )
Nc                    s@   ˆ   | ¡}ˆ  d|d ¡ t|d  ¡ d ƒ}ˆ  |dk¡ |S )Nr#   r   r   )r   r)   r'   r(   r   )Úarg_listr   Úcountr:   r   r   Ú	get_countk   s
    
z5TestCase.test_include_exclude_tags.<locals>.get_countZlong_runningzlong_running, importantr<   z--tagsz--exclude-tagsz	--tags=%sz--exclude-tags=%s)ÚassertEqual)r   rN   ÚtagsÚtotalÚtagZincludedÚexcludedr   r:   r   Útest_include_exclude_tagsj   s    
z"TestCase.test_include_exclude_tagsc                 C   s    |   g ¡}|   ddg¡}|   ddg¡}t|  |¡ƒ}t|  |¡ƒ}t|  |¡ƒ}|  tt|ƒt|ƒ ƒt|ƒd ¡ |  t|ƒt|ƒ¡ |  t|ƒt|ƒ¡ d S )Nú-jz0:2z1:2r&   )r   Úsetr8   Z
assertLessÚabsr*   )r   ZtmpAllZtmp1Ztmp2ZlAllÚl1Úl2r   r   r   Útest_check_shard€   s    
$zTestCase.test_check_shardc                 C   sJ  t ƒ }tdƒD ].}|  dd |¡g¡}|  |¡•}| |¡ q|  ddg¡}t|  |¡ƒ}|  t|ƒd¡ dd„ |D ƒ}tt|ƒƒD ] }|  	t|| ƒt|| ƒ¡ q„|D ]0}|D ]&}	|  
|	|¡ | |	¡ |  |	|¡ q²qªt |d	¡D ]\}
}|  |
|@ ¡ qètƒ }|D ]}| |¡ q
| |¡ t|  |  g ¡¡ƒ}|  	||¡ d S )
Né   rU   z{}:3z--tagZalways_testr%   c                 S   s   g | ]}t |ƒ‘qS r   )rV   )r	   r4   r   r   r   r   Ÿ   s     z;TestCase.test_check_sharding_equivalent.<locals>.<listcomp>rB   )r   r+   r   r   r8   ÚappendrV   r,   r*   rO   r)   ÚremoveÚassertNotInÚ	itertoolsÚcombinationsZassertFalseÚupdate)r   ZshardedÚiZsubsetÚslistÚtmpZalways_runningZsharded_setsZshardÚtestÚaÚbZsum_of_partsr4   Zfull_listingr   r   r   Útest_check_sharding_equivalent   s4    

ÿz'TestCase.test_check_sharding_equivalentzRequires gitpythonc              	   C   s    zt jdt jt jd W n tk
r6   |  d¡ Y nX |  dg¡}|  d|¡ |  dg¡}|  d|¡ tt jd}|  	t j
¡ | jdg|d	 W 5 Q R X d S )
NÚgit)ÚstdoutÚstderrzno git availablez-gzGit diff by common ancestorz-g=ancestor)rk   z	-g=ancestr   )r   ÚcallÚDEVNULLÚFileNotFoundErrorÚskipTestr   r^   r)   ÚdictÚassertRaisesÚCalledProcessError)r   Zoutsr   r   r   r   Útest_gitdiff¼   s    þ
zTestCase.test_gitdiffzRequires pyyamlc              	   C   s´  ddl m} tj tj t¡¡}tj |ddd¡}tj |¡sH|  	d¡ t
tj |¡dƒ}| ¡ }W 5 Q R X t j||d}|d }g }|d d… D ],}	|	d	 d
 }
|
 ¡ D ]}| |d ¡ q¬q”dddddg}tjj|f|žŽ }tj |¡sø|  	d¡ t
tj |¡dƒ}| ¡ }W 5 Q R X t j||d}|d d d d
 }
|
 ¡ D ]}| |d ¡ qH|  t|ƒtt|ƒƒ¡ t|ƒd }t|ƒ•}|  t|ƒ|¡ |  ||d d ¡ d S )Nr   )ÚLoaderz..zazure-pipelines.ymlz&'azure-pipelines.yml' is not availableÚrtÚjobsrB   Ú
parametersÚmatrixZTEST_START_INDEXZbuildscriptsZazurezazure-windows.ymlz$'azure-windows.yml' is not availableZstrategyr%   Ú	variablesZ
TEST_COUNT)Úyamlrt   ÚosÚpathÚdirnameÚabspathÚ__file__ÚjoinÚisfilero   ÚopenÚreadÚloadÚvaluesr\   rO   r*   rV   Úmaxr+   Úsorted)r   rt   Ú	base_pathZ
azure_pipeÚfÚdataZpipe_ymlZ	templatesZstart_indexesZtmpltrx   ÚsetupZwinpathZazure_windowsZwindows_ymlZlim_start_indexÚexpectedr   r   r   Útest_azure_configÑ   s:    


zTestCase.test_azure_config)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   r"   r0   r3   r8   r;   r=   r@   ÚunittestZskipIfr   r?   rA   rF   rI   rK   rT   rZ   rh   Z
skipUnlessÚhas_gitpythonrs   Ú
has_pyyamlr   r   r   r   r   r      s*   
-


r   Ú__main__)r{   r   r   Znumbar   r’   r_   ri   ÚImportErrorr“   rz   r”   r   rŽ   Úmainr   r   r   r   Ú<module>   s&   

 g