U
    iâË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	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   s6   z$tƒ }t |¡}|  |¡ |V  W 5 |   |¡ X d S ©N)ÚremoveHandlerr   ÚloggingÚStreamHandlerÚ
addHandler)ÚlÚhandlerÚbuffer© r   úT/home/sam/Atlas/atlas_env/lib/python3.8/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ƒ�N}tj |j	¡}|  
|tjd ¡ |  
tjdd … |¡ |  |jtjk¡ W 5 Q R X |  
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    

z,TestJitModule.test_create_temp_jitted_modulec              	   C   sl   z6t tjƒ}ttjƒ}t| jƒ� tdƒ‚W 5 Q R X W n0 tk
rf   |  tj|¡ |  tj|¡ Y nX 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	k¡ |  t |j¡¡ d\}}|  | |¡|j |¡¡ |  | ||¡|j ||¡¡ |  | |¡|j |¡¡ W 5 Q R X d S )N)g333333û?gffffff@)r   r   ZassertIsInstanceÚincr   Z
DispatcherÚaddZinc_addr   ZmeanÚnpÚinspectÚisclassZFoor   Zpy_func)r   r"   ÚxÚyr   r   r   Útest_jit_moduleH   s     
ÿÿ
ÿzTestJitModule.test_jit_modulec              	   C   s<   dddddœ}t | jf|Ž�}|  |jj|¡ W 5 Q R X 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   sZ   d}ddddœ}t f d|i|—Ž�.}|  |jj|¡ |  |jjddd dœ¡ W 5 Q R X 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)r/   r1   r2   r   )r0   Zforceobjr2   )r   r   r'   r3   r&   )r   r   r4   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|Ž�B}ˆ  ¡ ‰ dd |j	¡d |¡g}|  
t‡ fdd	„|D ƒƒ¡ W 5 Q R X W 5 Q R X d S )
Núnumba.core.decoratorsTr.   )r/   r1   zAuto decorating functionzfrom module {}zwith jit and options: {}c                 3   s   | ]}|ˆ kV  qd S r   r   )Ú.0Úi©Úlogsr   r   Ú	<genexpr>‰   s     z?TestJitModule.test_jit_module_logging_output.<locals>.<genexpr>)r   Ú	getLoggerÚsetLevelÚDEBUGr   r   r   ÚgetvalueÚformatr   r   Úall)r   Úloggerr4   r"   Úexpectedr   r:   r   Útest_jit_module_logging_output|   s     
ÿ
ÿ
þz,TestJitModule.test_jit_module_logging_outputc              
   C   sT   t  d¡}| t j¡ t|ƒ�,}t| jƒ� |  | ¡ d¡ W 5 Q R X W 5 Q R X d S )Nr7   Ú )	r   r=   r>   ÚINFOr   r   r   r   r@   )r   rC   r;   r   r   r   Útest_jit_module_logging_level‹   s
    

z+TestJitModule.test_jit_module_logging_levelN)r   Ú
__module__Ú__qualname__r   r#   r%   r-   r5   r6   rE   rH   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   

