o
    8ήc                     @   s   d dl Z d dlZd dlZd dlm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rQe  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
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 )'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-lzUTF-8c                 S   s   g | ]}|  r|qS  )strip.0liner   r   @/tmp/pip-target-vg8gfxp4/lib/python/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   r2   )znumba.tests.npyufunc.test_Nr   r   r   r   r   r3   @   s    )r1   r   any)r   idsr   r   r   r   	check_all;   s
   zTestCase.check_allc                 C   s   |  g  d S )Nr6   r   r   r   r   test_defaultC      zTestCase.test_defaultc                 C   s   |  dg d S )Nnumba.testsr7   r8   r   r   r   test_allF   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_cudaI   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#   r8   r   r   r   test_cuda_submodulesO   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   r8   r   r   r   test_moduleV   s   zTestCase.test_modulec                 C   s   |  dgd d S )Nnumba.tests.npyufunc2   rD   r8   r   r   r   test_subpackage]   s   zTestCase.test_subpackagec                 C   s   |  g dd d S )N)z--randomz0.1rF      rD   r8   r   r   r   test_random`   s   zTestCase.test_randomc                    s    fdd}ddg}|D ]:}|dg}|d|dg}|d|dg}  |||  |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   countr8   r   r   	get_counte   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   rM   tagstagtotalincludedexcludedr   r8   r   test_include_exclude_tagsd   s   

z"TestCase.test_include_exclude_tagsc                 C   s0   |  ddg}dd |D }| t|d d S )N-jz0,5,1c                 S      g | ]	}| d r|qS znumba.r   r	   xr   r   r   r   |       z-TestCase.test_check_slice.<locals>.<listcomp>rI   )r   rO   r+   )r   tmplr   r   r   test_check_slicez   s   zTestCase.test_check_slicec                 C   sb   dd }||  g }g }tdD ]}|  dd|g}||| q| t|t| d S )Nc                 S   s   dd | D S )Nc                 S   rW   rX   rY   rZ   r   r   r   r      r\   zOTestCase.test_check_slicing_equivalent.<locals>.filter_test.<locals>.<listcomp>r   )xsr   r   r   filter_test   r:   z;TestCase.test_check_slicing_equivalent.<locals>.filter_test   rV   z	{},None,3)r   r,   r   extendrO   sorted)r   ra   fullslicedisubsetr   r   r   test_check_slicing_equivalent   s   z&TestCase.test_check_slicing_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)rl   z	-g=ancestr   )r   callDEVNULLFileNotFoundErrorskipTestr   assertNotInr*   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jobsrA   
parametersmatrixTEST_START_INDEX)rx   rx   buildscriptsazurezazure-windows.ymlz$'azure-windows.yml' is not availablestrategyr&   	variables
TEST_COUNT)yamlrw   ospathdirnameabspath__file__joinisfilerp   openreadloadvaluesappendrO   r+   setmaxr,   rd   )r   rw   	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_config)__name__
__module____qualname____doc__r   r#   r1   r6   r9   r<   r?   unittestskipIfr   r>   r@   rE   rH   rJ   rU   r_   ri   
skipUnlesshas_gitpythonrv   
has_pyyamlr   r   r   r   r   r      s*    



r   __main__)r   r   r   numbar   r   rj   ImportErrorr   r   r   r   r   mainr   r   r   r   <module>   s,     6