a
    þ
þ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                   @   s\   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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   úb/var/www/html/stable-diffusion-webui/venv/lib/python3.9/site-packages/numba/tests/test_warnings.pyÚ!check_objmode_deprecation_warning   s    z.TestBuiltins.check_objmode_deprecation_warningc                 C   s(   d}|   |jt¡ |  |t|jƒ¡ d S )Nz0The 'nopython' keyword argument was not suppliedr	   r   r   r   r   Ú$check_nopython_kwarg_missing_warning   s    z1TestBuiltins.check_nopython_kwarg_missing_warningc                 C   sØ   dd„ }t jdd°}t  dt¡ tƒ  t|ƒ}|ddƒ |  t|ƒd¡ |  |d	 ¡ |  |d j	t¡ |  
d
t|d jƒ¡ |  |d j	t¡ |  
dt|d jƒ¡ |  |d ¡ W d   ƒ n1 sÊ0    Y  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   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
 ¡ |  	|d jt¡ |  dt|d jƒ¡ |  	|d jt¡ |  dt|d jƒ¡ |  |d ¡ W d   ƒ n1 sà0    Y  d S )Nr"   ©Zdtypec                      s   ˆ S r   r   r   ©r   r   r   Úreturn_external_array=   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-   r   Útest_return_type_warning:   s     ÿz%TestBuiltins.test_return_type_warningc                    s‚   t jdt jd‰ ‡ fdd„}tjddF}t dt¡ tƒ  tdd|ƒ}|ƒ  |  	t
|ƒd	¡ W d
  ƒ n1 st0    Y  d
S )z9
        Rerun test_return_type_warning with nrt
        r"   r,   c                      s   ˆ S r   r   r   r-   r   r   r.   ^   s    zMTestBuiltins.test_return_type_warning_with_nrt.<locals>.return_external_arrayTr   r   )Znopythonr   N)r/   r0   r1   r%   r&   r'   r   r   r   r
   r(   r2   r   r-   r   Ú!test_return_type_warning_with_nrtX   s    z.TestBuiltins.test_return_type_warning_with_nrtc                 C   sp   dd„ }t jddH}t  dt¡ tƒ  t|dd}|ddƒ |  t|ƒd	¡ W d   ƒ n1 sb0    Y  d S )
Nc                 S   s   g }| | S r   r   r   r   r   r   r   k   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_forceobjj   s    
z*TestBuiltins.test_no_warning_with_forceobjc                 C   sl  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 ¡ |  
|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 d   ƒ n1 s^0    Y  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_loopy   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>†   ó    z3TestBuiltins.test_loop_lift_warn.<locals>.<genexpr>é   )r   r   r    r#   zWITH loopliftingr!   zWITHOUT loopliftingr$   z-compiled in object mode without forceobj=Truezbut has lifted loops)r%   r&   r'   r   r   r/   r0   r1   r   Újoinr
   r(   r   r   r   r   r   r   )r   r9   r   r   r*   r   r   r   r   Útest_loop_lift_warnx   s,    ÿz TestBuiltins.test_loop_lift_warnc                 C   s¤   t dƒdd„ ƒ}tjddt}t d¡ tƒ  |ƒ  |  t|ƒd¡ |  |d jt¡ |  	d	t
|d jƒ¡ |  	dt
|d jƒ¡ W d   ƒ n1 s–0    Y  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   rB   )r   r%   r&   r'   r   r
   r(   r   ÚDeprecationWarningr   r   r   )r   rB   r   r   r   r   Útest_deprecated¢   s    

zTestBuiltins.test_deprecatedc                 C   s  t  t j¡}| dd¡6 t t  d¡¡ t t  d¡¡ tƒ  W d   ƒ n1 sT0    Y  tjddˆ}t d¡ tƒ  | 	¡  |  
t|ƒd¡ |  
|d jt¡ |  
|d	 jt¡ |  dt|d jƒ¡ |  dt|d	 jƒ¡ W d   ƒ n1 sø0    Y  d S )
NrA   é
   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ÚerrrL   r   r   r   Ú!test_disable_performance_warningsÈ   s    ò
z.TestBuiltins.test_disable_performance_warningsN)Ú__name__Ú
__module__Ú__qualname__r   r   r+   r3   r4   r5   r@   rD   rH   rZ   r   r   r   r   r      s   *r   Ú__main__)rT   rM   rO   r%   Únumpyr/   ZunittestZnumbar   Znumba.core.errorsr   r   r   Z
numba.corer   Znumba.tests.supportr   ZTestCaser   r[   Úmainr   r   r   r   Ú<module>   s    a