a
    —§»a(  ã                   @   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	Z	d dl
mZmZ d dlmZ ejdd„ ƒZG dd„ dee	jƒZdS )	é    N)ÚStringIO)ÚSerialMixinÚcreate_temp_module)Ú
dispatcherc              	   c   s@   z.t ƒ }t |¡}|  |¡ |V  W |  |¡ n|  |¡ 0 d S ©N)r   ÚloggingÚStreamHandlerÚ
addHandlerÚremoveHandler)ÚlÚbufferÚhandler© r   úU/home/yuhw/wc/pochoir/venv/lib/python3.9/site-packages/numba/tests/test_jit_module.pyÚcaptured_logs   s    

r   c                   @   sH   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
dS )ÚTestJitModulezí
from numba import jit_module

def inc(x):
    return x + 1

def add(x, y):
    return x + y

def inc_add(x):
    y = inc(x)
    return add(x, y)

import numpy as np
mean = np.mean

class Foo(object):
    pass

jit_module({jit_options})
c                 C   s¦   t tjƒ}ttjƒ}t| jƒ�X}tj |j	¡}|  
|tjd ¡ |  
tjdd … |¡ |  |jtjv ¡ W d   ƒ n1 s|0    Y  |  
tj|¡ |  
tj|¡ d S )Nr   é   )ÚlistÚsysÚpathÚdictÚmodulesr   Úsource_linesÚosÚdirnameÚ__file__ÚassertEqualÚ
assertTrueÚ__name__)ÚselfÚsys_path_originalÚsys_modules_originalÚtest_moduleZtemp_module_dirr   r   r   Útest_create_temp_jitted_module1   s    

0z,TestJitModule.test_create_temp_jitted_modulec                 C   s~   zJt tjƒ}ttjƒ}t| jƒ� tdƒ‚W d   ƒ n1 s>0    Y  W n. tyx   |  tj|¡ |  tj|¡ Y n0 d S )NzSomething went wrong!)	r   r   r   r   r   r   r   Ú
ValueErrorr   )r   r    r!   r   r   r   Ú-test_create_temp_jitted_module_with_exception=   s    

*z;TestJitModule.test_create_temp_jitted_module_with_exceptionc                 C   sÜ   t | jƒ�¾}|  |jtj¡ |  |jtj¡ |  |jtj¡ |  |j	t
j	u ¡ |  t |j¡¡ d\}}|  | |¡|j |¡¡ |  | ||¡|j ||¡¡ |  | |¡|j |¡¡ W d   ƒ n1 sÎ0    Y  d S )N)g333333û?gffffff@)r   r   ZassertIsInstanceÚincr   Z
DispatcherÚaddZinc_addr   ÚmeanÚnpÚinspectÚisclassZFoor   Zpy_func)r   r"   ÚxÚyr   r   r   Útest_jit_moduleH   s     
ÿÿ
ÿzTestJitModule.test_jit_modulec                 C   sT   dddddœ}t | jfi |¤Ž� }|  |jj|¡ W d   ƒ n1 sF0    Y  d S )NTFÚnumpy)ÚnopythonÚnogilÚerror_modelÚboundscheck)r   r   r   r&   Útargetoptions)r   Újit_optionsr"   r   r   r   Útest_jit_module_jit_optionsY   s    ý
ÿz)TestJitModule.test_jit_module_jit_optionsc                 C   sn   d}ddddœ}t f d|i|¤Ž�8}|  |jj|¡ |  |jjddd dœ¡ W d   ƒ n1 s`0    Y  d S )Nz�
from numba import jit, jit_module

@jit(nogil=True, forceobj=True)
def inc(x):
    return x + 1

def add(x, y):
    return x + y

jit_module({jit_options})
Tr/   F)r0   r2   r3   r   )r1   Zforceobjr3   )r   r   r'   r4   r&   )r   r   r5   r"   r   r   r   Ú$test_jit_module_jit_options_overridec   s    þ
ÿ
ÿÿz2TestJitModule.test_jit_module_jit_options_overridec              	      sº   t  d¡}| t j¡ dddœ}t|ƒ�~‰ t| jfi |¤Ž�L}ˆ  ¡ ‰ dd |j	¡d |¡g}|  
t‡ fdd	„|D ƒƒ¡ W d   ƒ n1 sŽ0    Y  W d   ƒ n1 s¬0    Y  d S )
Núnumba.core.decoratorsTr/   )r0   r2   zAuto decorating functionzfrom module {}zwith jit and options: {}c                 3   s   | ]}|ˆ v V  qd S r   r   )Ú.0Úi©Úlogsr   r   Ú	<genexpr>‰   ó    z?TestJitModule.test_jit_module_logging_output.<locals>.<genexpr>)r   Ú	getLoggerÚsetLevelÚDEBUGr   r   r   ÚgetvalueÚformatr   r   Úall)r   Úloggerr5   r"   Úexpectedr   r;   r   Útest_jit_module_logging_output|   s     
ÿ

ÿ
þz,TestJitModule.test_jit_module_logging_outputc              	   C   s|   t  d¡}| t j¡ t|ƒ�J}t| jƒ�  |  | ¡ d¡ W d   ƒ n1 sP0    Y  W d   ƒ n1 sn0    Y  d S )Nr8   Ú )	r   r?   r@   ÚINFOr   r   r   r   rB   )r   rE   r<   r   r   r   Útest_jit_module_logging_level‹   s
    

z+TestJitModule.test_jit_module_logging_levelN)r   Ú
__module__Ú__qualname__r   r#   r%   r.   r6   r7   rG   rJ   r   r   r   r   r      s   
r   )r   r   r*   Ú
contextlibr/   r)   r   Úior   ZunittestZnumba.tests.supportr   r   Z
numba.corer   Úcontextmanagerr   ZTestCaser   r   r   r   r   Ú<module>   s   

