a
    —§»a‚  ã                   @   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yN   dZY n0 dZzd dl	Z	W n eyv   dZ
Y n0 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
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   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   úS/home/yuhw/wc/pochoir/venv/lib/python3.9/site-packages/numba/tests/test_runtests.pyÚ
<listcomp>$   ó    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|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ÚrangeZ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 |v V  qdS )znumba.cuda.tests.Nr   r   r   r   r   Ú	<genexpr>>   r   z%TestCase.check_all.<locals>.<genexpr>c                 s   s   | ]}d |v V  qdS )znumba.tests.npyufunc.test_Nr   r   r   r   r   r1   @   s   ÿ)r0   r   Úany)r   Úidsr   r   r   r   Ú	check_all;   s
    ÿzTestCase.check_allc                 C   s   |   g ¡ d S )N©r4   ©r   r   r   r   Útest_defaultC   s    zTestCase.test_defaultc                 C   s   |   dg¡ d S )Núnumba.testsr5   r6   r   r   r   Útest_allF   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_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#   r6   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_callsr'   é   ©r0   r6   r   r   r   Útest_moduleV   s    ÿÿzTestCase.test_modulec                 C   s   |   dgd¡ d S )Núnumba.tests.npyufuncé2   r@   r6   r   r   r   Útest_subpackage]   s    zTestCase.test_subpackagec                 C   s   |   g d¢d¡ d S )N)z--randomz0.1rB   é   r@   r6   r   r   r   Útest_random`   s    ÿzTestCase.test_randomc                    s’   ‡ fdd„}ddg}|D ]t}|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   Úcountr6   r   r   Ú	get_counte   s
    
z5TestCase.test_include_exclude_tags.<locals>.get_countZlong_runningzlong_running, importantr8   z--tagsz--exclude-tagsz	--tags=%sz--exclude-tags=%s)ÚassertEqual)r   rI   ÚtagsÚtagÚtotalZincludedZexcludedr   r6   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   s   g | ]}|  d ¡r|‘qS ©znumba.©r   ©r	   Úxr   r   r   r   |   r   z-TestCase.test_check_slice.<locals>.<listcomp>rE   )r   rJ   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   s   g | ]}|  d ¡r|‘qS rP   rQ   rR   r   r   r   r   �   r   zOTestCase.test_check_slicing_equivalent.<locals>.filter_test.<locals>.<listcomp>r   )Úxsr   r   r   Úfilter_test€   s    z;TestCase.test_check_slicing_equivalent.<locals>.filter_testé   rO   z	{},None,3)r   r,   r   ÚextendrJ   Úsorted)r   rX   ÚfullZslicedÚiZ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y4   |  d¡ Y n0 |  dg¡}|  d|¡ |  dg¡}|  d|¡ tt jd�}|  	t j
¡�  | jdg|d	� W d   ƒ n1 s¤0    Y  d S )
NÚgit)ÚstdoutÚstderrzno git availablez-gzGit diff by common ancestorz-g=ancestor)ra   z	-g=ancestr   )r   ÚcallÚDEVNULLÚFileNotFoundErrorÚskipTestr   ZassertNotInr*   Ú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 d   ƒ n1 sx0    Y  t j||d�}|d }g }|d d… D ],}	|	d	 d
 }
|
 ¡ D ]}| |d ¡ qÀq¨g d¢}tjj|g|¢R Ž }tj |¡�s
|  	d¡ t
tj |¡dƒ�}| ¡ }W d   ƒ n1 �s<0    Y  t j||d�}|d d d d
 }
|
 ¡ D ]}| |d ¡ �qp|  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Újobsr>   Ú
parametersÚmatrixZTEST_START_INDEX)rk   rk   ZbuildscriptsZazurezazure-windows.ymlz$'azure-windows.yml' is not availableZstrategyr&   Ú	variablesZ
TEST_COUNT)Úyamlrj   ÚosÚpathÚdirnameÚabspathÚ__file__ÚjoinÚisfilere   ÚopenÚreadÚloadÚvaluesÚappendrJ   r+   ÚsetÚmaxr,   r[   )r   rj   Ú	base_pathZ
azure_pipeÚfÚdataZpipe_ymlZ	templatesZstart_indexesZtmpltro   Ú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   r4   r7   r9   r<   ÚunittestZskipIfr   r;   r=   rA   rD   rF   rN   rV   r^   Z
skipUnlessÚhas_gitpythonri   Ú
has_pyyamlr…   r   r   r   r   r      s(   



r   Ú__main__)rr   r   r   Znumbar   rŠ   r_   ÚImportErrorr‹   rq   rŒ   r   r†   Úmainr   r   r   r   Ú<module>   s$   

 6