o
    i(                     @   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 | | d S | | w N)r   loggingStreamHandler
addHandlerremoveHandler)lbufferhandler r   j/var/www/html/eduruby.in/lip-sync/lip-sync-env/lib/python3.10/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,}tj|j	}| 
|tjd  | 
tjdd  | | |jtjv  W d    n1 s>w   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   

z,TestJitModule.test_create_temp_jitted_modulec                 C   sp   zt tj}ttj}t| j td1 sw   Y  W d S  ty7   | tj| | tj| Y d S w )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    d S 1 shw   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   sV   ddddd}t | jfi |}| |jj| W d    d S 1 s$w   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   sp   d}dddd}t dd|i|}| |jj| | |jjddd d W d    d S 1 s1w   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   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|H t| jfi |&}   dd|j	d|g}| 
t fdd	|D  W d    n1 sGw   Y  W d    d S W d    d S 1 s_w   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>   s    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|.}t| j | | d W d    n1 s(w   Y  W d    d S W d    d S 1 s@w   Y  d S )Nr8    )	r   r>   r?   INFOr   r   r   r   rA   )r   rD   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   rF   rI   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    

