B
      ›\n  ã               @   s^   d dl mZmZ d dlZd dlZd dlmZ d dlmZ G dd„ dej	ƒZ	e
dkrZe ¡  dS )é    )ÚdivisionÚprint_functionN)Úunittest_support)Úcudac               @   s”   e Zd Z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e ejdk 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.c             C   s:   ddddgt |ƒ }t |¡ d¡ ¡ }dd„ |D ƒ}|S )NZpythonz-mznumba.runtestsz-lzUTF-8c             S   s   g | ]}|  ¡ r|‘qS © )Ústrip)Ú.0Úliner   r   ú8lib/python3.7/site-packages/numba/tests/test_runtests.pyú
<listcomp>   s    z2TestCase.get_testsuite_listing.<locals>.<listcomp>)ÚlistÚ
subprocessZcheck_outputÚdecodeÚ
splitlines)ÚselfÚargsÚcmdÚlinesr   r   r   Úget_testsuite_listing   s    zTestCase.get_testsuite_listingc             C   sF   |   |g¡}x4|d d… D ]$}d ||¡}| j| |¡|d qW d S )Néÿÿÿÿz{!r} not startswith {!r})Úmsg)r   ÚformatÚ
assertTrueÚ
startswith)r   ÚprefixZlistingZlnÚerrmsgr   r   r   Úcheck_listing_prefix   s    zTestCase.check_listing_prefixc             C   sb   |   |¡}|d }|  | d¡¡ t| d¡d ƒ}|  t|ƒt|d |d ƒ¡ |  ||¡ |S )zR
        Check that the reported numbers of tests are at least *minsize*.
        r   ztests foundú r   é   é
   )	r   r   ÚendswithÚintÚsplitÚassertInÚlenÚrangeZassertGreaterEqual)r   r   Úminsizer   Ú	last_lineZ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 |kV  qdS )znumba.cuda.tests.Nr   )r	   r
   r   r   r   ú	<genexpr>,   s    z%TestCase.check_all.<locals>.<genexpr>c             s   s   | ]}d |kV  qdS )znumba.tests.npyufunc.test_Nr   )r	   r
   r   r   r   r*   /   s    )r)   r   Úany)r   Zidsr   r   r   r   Ú	check_all)   s    zTestCase.check_allc             C   s   |   g ¡ d S )N)r,   )r   r   r   r   Útest_default2   s    zTestCase.test_defaultc             C   s   |   dg¡ d S )Nznumba.tests)r,   )r   r   r   r   Útest_all5   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_availabler)   )r   r'   r   r   r   Ú	test_cuda8   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_submodules>   s    


zTestCase.test_cuda_submodulesc             C   s0   |   dgd¡ |   dgd¡ |   ddgd¡ d S )Nznumba.tests.test_utilsé   znumba.tests.test_nested_callsé   é   )r)   )r   r   r   r   Útest_moduleE   s    zTestCase.test_modulec             C   s   |   dgd¡ d S )Nznumba.tests.npyufuncé2   )r)   )r   r   r   r   Útest_subpackageL   s    zTestCase.test_subpackage)r3   é   z1'--random' only supported on Python 3.4 or higherc             C   s   |   dddgd¡ d S )Nz--randomz0.1znumba.tests.npyufuncr4   )r)   )r   r   r   r   Útest_randomO   s    zTestCase.test_randomc                s–   ‡ fdd„}ddg}x||D ]t}|dgƒ}|d|dgƒ}|d|dgƒ}ˆ   ||| ¡ |dgƒ}|d| dgƒ}|d	| dgƒ}ˆ   ||| ¡ qW d S )
Nc                s@   ˆ   | ¡}ˆ  d|d ¡ t|d  ¡ d ƒ}ˆ  |dk¡ |S )Nztests foundr   r   )r   r$   r"   r#   r   )Úarg_listr   Úcount)r   r   r   Ú	get_countV   s
    
z5TestCase.test_include_exclude_tags.<locals>.get_countZlong_runningzlong_running, importantznumba.testsz--tagsz--exclude-tagsz	--tags=%sz--exclude-tags=%s)ZassertEqual)r   r=   ZtagsÚtagZtotalZincludedZexcludedr   )r   r   Útest_include_exclude_tagsU   s    


z"TestCase.test_include_exclude_tagsN)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   r   r)   r,   r-   r.   r1   ÚunittestZskipIfr   r0   r2   r6   r8   ÚsysÚversion_infor:   r?   r   r   r   r   r   
   s   	r   Ú__main__)Z
__future__r   r   rE   r   Znumbar   rD   r   r   r@   Úmainr   r   r   r   Ú<module>   s   b