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 )+TestCasezThese 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   M/home/ubuntu/.local/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 )Nz{!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 )Nd   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.npyufunc2   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 sw   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      