U
    ,‰dº  ã                   @   sŽ   d dl Z d dlZd dlZd dlZd dlZd dlZd dlmZ d dl	m
Z
mZmZ d dlmZ d dlmZ G dd„ dejƒZedkrŠe ¡  dS )	é    N)Újit)ÚNumbaWarningÚ
deprecatedÚNumbaDeprecationWarning)Úerrors)Úignore_internal_warningsc                   @   sT   e Zd Zdd„ Zdd„ Zdd„ Zdd„ Zd	d
„ Zdd„ Zdd„ Z	dd„ Z
dd„ ZdS )ÚTestBuiltinsc                 C   s(   d}|   |jt¡ |  |t|jƒ¡ d S )NzbFall-back from the nopython compilation path to the object mode compilation path has been detected)ÚassertEqualÚcategoryr   ÚassertInÚstrÚmessage)ÚselfÚwÚmsg© r   ú=/tmp/pip-unpacked-wheel-eu7e0c37/numba/tests/test_warnings.pyÚ!check_objmode_deprecation_warning   s    z.TestBuiltins.check_objmode_deprecation_warningc              	   C   s¶   dd„ }t jdd˜}t  dt¡ tƒ  t|ƒ}|ddƒ |  t|ƒd¡ |  |d	 jt¡ |  	d
t
|d	 jƒ¡ |  |d jt¡ |  	dt
|d jƒ¡ |  |d ¡ W 5 Q R X d S )Nc                 S   s   i }| | S ©Nr   ©ÚxÚyÚar   r   r   Úadd   s    z1TestBuiltins.test_type_infer_warning.<locals>.addT©ÚrecordÚalwaysé   é   é   r   útype inferencezobject mode)ÚwarningsÚcatch_warningsÚsimplefilterr   r   r   r	   Úlenr
   r   r   r   r   ©r   r   r   Úcfuncr   r   r   Útest_type_infer_warning   s    
z$TestBuiltins.test_type_infer_warningc              	      sÌ   t jdt jd‰ ‡ fdd„}tjddš}t dt¡ tƒ  tdd	|ƒ}|ƒ  |  	t
|ƒd
¡ |  	|d jt¡ |  dt|d jƒ¡ |  	|d jt¡ |  dt|d jƒ¡ |  |d ¡ W 5 Q R X d S )Né   ©Zdtypec                      s   ˆ S r   r   r   ©r   r   r   Úreturn_external_array2   s    zDTestBuiltins.test_return_type_warning.<locals>.return_external_arrayTr   r   F)Z_nrtr   r   zreturn typer   z!object mode without forceobj=Truer   )ÚnpÚonesÚfloat32r!   r"   r#   r   r   r   r	   r$   r
   r   r   r   r   ©r   r+   r   r&   r   r*   r   Útest_return_type_warning/   s    ÿz%TestBuiltins.test_return_type_warningc              	      sh   t jdt jd‰ ‡ fdd„}tjdd6}t dt¡ tƒ  t|ƒ}|ƒ  |  	t
|ƒd¡ W 5 Q R X d	S )
z9
        Rerun test_return_type_warning with nrt
        r(   r)   c                      s   ˆ S r   r   r   r*   r   r   r+   P   s    zMTestBuiltins.test_return_type_warning_with_nrt.<locals>.return_external_arrayTr   r   r   N)r,   r-   r.   r!   r"   r#   r   r   r   r	   r$   r/   r   r*   r   Ú!test_return_type_warning_with_nrtJ   s    z.TestBuiltins.test_return_type_warning_with_nrtc              	   C   s\   dd„ }t jdd>}t  dt¡ tƒ  t|dd}|ddƒ |  t|ƒd	¡ W 5 Q R X d S )
Nc                 S   s   g }| | S r   r   r   r   r   r   r   ]   s    z7TestBuiltins.test_no_warning_with_forceobj.<locals>.addTr   r   )Zforceobjr   r   r   )r!   r"   r#   r   r   r   r	   r$   r%   r   r   r   Útest_no_warning_with_forceobj\   s    
z*TestBuiltins.test_no_warning_with_forceobjc              	   C   sH  dd„ }t jdd(}t  dt¡ tƒ  tjdtjd}t|ƒ}||ƒ d 	d	d
„ |D ƒ¡}| j
t|ƒd|d |  
|d jt¡ |  dt|d jƒ¡ |  dt|d jƒ¡ |  
|d jt¡ |  dt|d jƒ¡ |  dt|d jƒ¡ |  
|d jt¡ |  dt|d jƒ¡ |  dt|d jƒ¡ |  |d ¡ W 5 Q R X d S )Nc                 S   s,   i }t | jd ƒD ]}| |  d9  < qd S )Nr   r   )ÚrangeÚshape)r   r   Úir   r   r   Údo_loopk   s    z1TestBuiltins.test_loop_lift_warn.<locals>.do_loopTr   r   r(   r)   Ú
c                 s   s   | ]}d |j › V  qdS )z----------
N)r   )Ú.0r   r   r   r   Ú	<genexpr>x   s     z3TestBuiltins.test_loop_lift_warn.<locals>.<genexpr>)r   r   r    zWITH loopliftingr   zWITHOUT loopliftingr   z-compiled in object mode without forceobj=Truezbut has lifted loopsr   )r!   r"   r#   r   r   r,   r-   r.   r   Újoinr	   r$   r
   r   r   r   r   )r   r6   r   r   r&   r   r   r   r   Útest_loop_lift_warnj   s*    ÿz TestBuiltins.test_loop_lift_warnc              	   C   s   t dƒdd„ ƒ}tjddj}t d¡ tƒ  |ƒ  |  t|ƒd¡ |  |d jt¡ |  	d	t
|d jƒ¡ |  	dt
|d jƒ¡ W 5 Q R X d S )
NÚfooc                   S   s   d S r   r   r   r   r   r   Úbar’   s    z)TestBuiltins.test_deprecated.<locals>.barTr   r   r   r   r=   )r   r!   r"   r#   r   r	   r$   r
   ÚDeprecationWarningr   r   r   )r   r=   r   r   r   r   Útest_deprecated‘   s    

zTestBuiltins.test_deprecatedc              	   C   sÞ   t  t j¡}| dd¡, t t  d¡¡ t t  d¡¡ tƒ  W 5 Q R X tjdd~}t d¡ tƒ  | 	¡  |  
t|ƒd¡ |  
|d jt¡ |  
|d	 jt¡ |  dt|d jƒ¡ |  dt|d	 jƒ¡ W 5 Q R X d S )
Nr<   é
   ZsameTr   r   r   r   r   )r   ZWarningsFixerr   r"   r!   Úwarnr   r   r#   Úflushr	   r$   r
   r   r   r   )r   Zwfixr   r   r   r   Útest_warnings_fixer    s    
z TestBuiltins.test_warnings_fixerc           	      C   sŒ   d}d}d}d|||f }t  tjd|g¡}| ¡ \}}|  |j|¡ ttj	ƒ}d|d< t jtjd|g|d}| ¡ \}}|  |j|¡ d S )	Né7   éc   z3'parallel=True' was specified but no transformationa0  if 1:
            import warnings
            from numba.tests.error_usecases import foo
            import numba
            from numba.tests.support import ignore_internal_warnings
            with warnings.catch_warnings(record=True) as w:
                warnings.simplefilter('always')
                ignore_internal_warnings()
                foo()
            for x in w:
                if x.category == numba.errors.NumbaPerformanceWarning:
                    if "%s" in str(x.message):
                        exit(%s)
            exit(%s)
        z-cÚ1Z"NUMBA_DISABLE_PERFORMANCE_WARNINGS)Úenv)
Ú
subprocessÚPopenÚsysÚ
executableÚcommunicater	   Ú
returncodeÚdictÚosÚenviron)	r   Znot_found_ret_codeZfound_ret_codeÚexpectedZparallel_codeÚpopenÚoutÚerrrG   r   r   r   Ú!test_disable_performance_warnings·   s    ò
z.TestBuiltins.test_disable_performance_warningsN)Ú__name__Ú
__module__Ú__qualname__r   r'   r0   r1   r2   r;   r?   rC   rU   r   r   r   r   r      s   'r   Ú__main__)rO   rH   rJ   r!   Znumpyr,   ZunittestZnumbar   Znumba.core.errorsr   r   r   Z
numba.corer   Znumba.tests.supportr   ZTestCaser   rV   Úmainr   r   r   r   Ú<module>   s    P