o
    'ѹg,                     @   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   ]/Users/admin/.pyenv/versions/3.10.0/lib/python3.10/site-packages/numba/tests/test_runtests.py
<listcomp>%   s    z2TestCase.get_testsuite_listing.<locals>.<listcomp>N)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 )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         N)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   r2   )znumba.tests.npyufunc.test_Nr   r	   r   r   r   r3   A   s    )r1   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>N)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r6   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_availabler1   )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
      r1   r<   r   r   r   test_module\   s   zTestCase.test_modulec                 C   s   |  dgd d S )Nnumba.tests.npyufunc2   rG   r<   r   r   r   test_subpackagec   s   zTestCase.test_subpackagec                 C   s   |  g dd d S )N)z--randomz0.1rI      rG   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_countZlong_runningzlong_running, importantr>   z--tagsz--exclude-tagsz	--tags=%sz--exclude-tags=%s)assertEqual)r   rP   tagstotaltagZincludedZ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:   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}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   rV   z{}:3z--tagZalways_testr&   c                 S   s   g | ]}t |qS r   )rW   )r
   r7   r   r   r   r      s    z;TestCase.test_check_sharding_equivalent.<locals>.<listcomp>rD   )r   r,   r   r   r:   appendrW   r-   r+   rQ   r*   removeassertNotIn	itertoolscombinationsZassertFalseupdate)r   ZshardediZsubsetslisttmpZalways_runningZsharded_setsZshardtestabZsum_of_partsr7   Z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)rm   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|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jobsrD   
parametersmatrixZTEST_START_INDEX)rw   rw   ZbuildscriptsZazurezazure-windows.ymlz$'azure-windows.yml' is not availableZstrategyr&   	variablesZ
TEST_COUNT)yamlrv   ospathdirnameabspath__file__joinisfilerq   openreadloadvaluesr]   rQ   r+   rW   maxr,   sorted)r   rv   	base_pathZ
azure_pipefdataZpipe_ymlZ	templatesZstart_indexesZtmpltr{   setupZwinpathZazure_windowsZwindows_ymlZ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)()<   )rm   timeoutz(Detected compilation during test listingr   znumba.test('-l')rk   )rs   r   rt   r   r   r   r   STDOUTr*   	exceptionrl   r   
check_callro   )r   codeZraisesr   r   r   r   test_no_compilation_on_list   s    
z$TestCase.test_no_compilation_on_list)__name__
__module____qualname____doc__r   r#   r1   r6   r:   r=   r?   rB   unittestZskipIfr   rA   rC   rH   rK   rM   rU   r[   ri   Z
skipUnlesshas_gitpythonru   
has_pyyamlr   r   r   r   r   r   r      s.    

-


+r   __main__)r~   r   r   Znumbar   r   r`   rj   ImportErrorr   r}   r   r   r   mainr   r   r   r   <module>   s0      