o
    ºi,  ã                   @   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y+   dZ	Y nw dZ	zd dl
Z
W n ey?   dZY nw dZG dd„ dejƒZedkrUe ¡  dS 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)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   sP   |pi }t jdddgt|ƒ }tj|fi |¤Ž}| d¡ ¡ }dd„ |D ƒ}|S )zX
        Use `subp_kwargs` to pass extra argument to `subprocess.check_output`.
        z-mznumba.runtestsz-lúUTF-8c                 S   s   g | ]}|  ¡ r|‘qS © )Ústrip©Ú.0Úliner   r   úV/home/ubuntu/veenaModal/venv/lib/python3.10/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   ÚcmdÚ	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|v ¡ 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   ó    | ]}d |v V  qdS )znumba.cuda.tests.Nr   r	   r   r   r   Ú	<genexpr>?   s   € z%TestCase.check_all.<locals>.<genexpr>c                 s   r3   )znumba.tests.npyufunc.test_Nr   r	   r   r   r   r4   A   s   € ÿ)r2   r   Úany)r   Ú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   s   
 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©r7   ©r   r   r   r   Útest_defaultI   s   zTestCase.test_defaultc                 C   s   |   dg¡ d S )Núnumba.testsr<   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_availabler2   )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é
   é   ©r2   r=   r   r   r   Útest_module\   s   ÿÿzTestCase.test_modulec                 C   s   |   dgd¡ d S )Núnumba.tests.npyufuncé2   rH   r=   r   r   r   Útest_subpackagec   s   zTestCase.test_subpackagec                 C   s   |   g d¢d¡ d S )N)z--randomz0.1rJ   é   rH   r=   r   r   r   Útest_randomf   s   ÿzTestCase.test_randomc                    sˆ   ‡ fdd„}ddg}|dgƒ}|D ]0}|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_countÚlong_runningzlong_running, importantr?   z--tagsz--exclude-tagsz	--tags=%sz--exclude-tags=%s)ÚassertEqual)r   rQ   ÚtagsÚtotalÚtagÚ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   Úsetr;   Ú
assertLessÚabsr,   )r   ÚtmpAllÚtmp1Útmp2ÚlAllÚl1Úl2r   r   r   Útest_check_shard€   s   
$zTestCase.test_check_shardc                 C   sJ  t ƒ }tdƒD ]}|  dd |¡g¡}g |  |¡¢}| |¡ q|  ddg¡}t|  |¡ƒ}|  t|ƒd¡ dd„ |D ƒ}tt|ƒƒD ]}|  	t|| ƒt|| ƒ¡ qC|D ]}|D ]}	|  
|	|¡ | |	¡ |  |	|¡ qZqVt |d	¡D ]\}
}|  |
|@ ¡ qutƒ }|D ]}| |¡ q†| |¡ t|  |  g ¡¡ƒ}|  	||¡ d S )
Né   rZ   z{}:3z--tagÚalways_testr'   c                 S   s   g | ]}t |ƒ‘qS r   )r[   )r
   r8   r   r   r   r   Ÿ   s    z;TestCase.test_check_sharding_equivalent.<locals>.<listcomp>rE   )r   r-   r   r   r;   Úappendr[   r.   r,   rS   r+   ÚremoveÚassertNotInÚ	itertoolsÚcombinationsÚassertFalseÚupdate)r   ÚshardedÚiÚsubsetÚslistÚtmpÚalways_runningÚsharded_setsÚshardÚtestÚaÚbÚsum_of_partsr8   Úfull_listingr   r   r   Útest_check_sharding_equivalent   s6   
ý
ÿz'TestCase.test_check_sharding_equivalentzRequires gitpythonc                 C   s´   zt jdt jt jd W n ty   |  d¡ Y nw |  dg¡}|  d|¡ |  dg¡}|  d|¡ tt jd}|  	t j
¡ | jdg|d	 W d   ƒ d S 1 sSw   Y  d S )
NÚgit©ÚstdoutÚstderrzno git availablez-gzGit diff by common ancestorz-g=ancestor)r   z	-g=ancestr   )r   ÚcallÚDEVNULLÚFileNotFoundErrorÚskipTestr   ri   r+   ÚdictÚassertRaisesÚCalledProcessError)r   Ú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 |¡s$|  	d¡ t
tj |¡dƒ}| ¡ }W d   ƒ n1 s<w   Y  t j||d}|d }g }|d d… D ]}	|	d	 d
 }
|
 ¡ D ]	}| |d ¡ q`qTg d¢}tjj|g|¢R Ž }tj |¡s„|  	d¡ t
tj |¡dƒ}| ¡ }W d   ƒ n1 sœw   Y  t j||d}|d d d d
 }
|
 ¡ D ]	}| |d ¡ q¶|  t|ƒtt|ƒƒ¡ t|ƒd }g t|ƒ¢}|  t|ƒ|¡ |  ||d d ¡ d S )Nr   )ÚLoaderú..zazure-pipelines.ymlz&'azure-pipelines.yml' is not availableÚrtÚjobsrE   Ú
parametersÚmatrixÚTEST_START_INDEX)rŠ   rŠ   ÚbuildscriptsÚazurezazure-windows.ymlz$'azure-windows.yml' is not availableÚstrategyr'   Ú	variablesÚ
TEST_COUNT)Úyamlr‰   ÚosÚpathÚdirnameÚabspathÚ__file__ÚjoinÚisfilerƒ   ÚopenÚreadÚloadÚvaluesrg   rS   r,   r[   Úmaxr-   Úsorted)r   r‰   Ú	base_pathÚ
azure_pipeÚfÚdataÚpipe_ymlÚ	templatesÚstart_indexesÚtmpltrŽ   ÚsetupÚwinpathÚazure_windowsÚwindows_ymlÚlim_start_indexÚexpectedr   r   r   Útest_azure_configÑ   s@   

ÿÿ

ÿzTestCase.test_azure_configc                 C   s”   d}|   tj¡}tjd| d¡g}tj|tjdd W d   ƒ n1 s%w   Y  |  d|j	j
 d¡¡ tjd| d¡g}tj|tjtjd	 d S )
NaJ  if 1:
        from unittest import mock
        from llvmlite import binding as llvm
        error = RuntimeError("Detected compilation during test listing")
        with mock.patch.object(llvm.ExecutionEngine, 'finalize_object',
                               side_effect=error):
            import numba
            {0}
        z-cznumba.njit(lambda:0)()é<   )r   Útimeoutz(Detected compilation during test listingr   znumba.test('-l')r}   )r…   r   r†   r   r   r   r   ÚSTDOUTr+   Ú	exceptionr~   r   Ú
check_callr   )r   ÚcodeÚraisesr   r   r   r   Útest_no_compilation_on_listý   s    þþÿ
þz$TestCase.test_no_compilation_on_list)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   r$   r2   r7   r;   r>   r@   rC   ÚunittestÚskipIfr   rB   rD   rI   rL   rN   rY   rd   r{   Ú
skipUnlessÚhas_gitpythonrˆ   Ú
has_pyyamlr±   r¹   r   r   r   r   r      s.    

-


+r   Ú__main__)r–   r   r   Únumbar   r¾   rj   r|   ÚImportErrorrÁ   r•   rÂ   r   rº   Úmainr   r   r   r   Ú<module>   s0    ÿÿ  ÿ