U
    9%e                     @   s   d Z ddlZddlZddlmZmZ ddlmZ ddl	m
Z
 ddlmZ dd Zd	d
 Zdd Ze Zde_dd Zdd ZG dd deZG dd deZedkre  dS )z!
Testing object mode specifics.

    N)compile_isolatedFlags)jit)utils)TestCasec                 C   s   | d }|d S )N   y              @ )ntmpr   r   [/var/www/html/Darija-Ai-API/env/lib/python3.8/site-packages/numba/tests/test_object_mode.pycomplex_constant   s    r   c                 C   s   | d S )Nl         4LEh*r-P3OF r   r	   r   r   r   long_constant   s    r   c                 C   s   | d d = d S Nr   xr   r   r   delitem_usecase   s    r   Tc                 C   sB   d}t | D ]0}t |D ]"}t | | D ]}||| 7 }q(qq|S Nr   )range)r   yr	   ijkr   r   r   loop_nest_3    s    r   c                 C   s   | S r   r   r   r   r   r   array_of_object*   s    r   c                   @   sD   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S )TestObjectModec                 C   s0   t }t|dtd}|j}| |d|d d S Nr   flags   )r   r   forceobjentry_pointassertPreciseEqualselfpyfunccrescfuncr   r   r   test_complex_constant0   s    z$TestObjectMode.test_complex_constantc                 C   s0   t }t|dtd}|j}| |d|d d S r   )r   r   r    r!   r"   r#   r   r   r   test_long_constant6   s    z!TestObjectMode.test_long_constantc                    sh   t tdtd}|j | dd dd fdd} fdd}tt| tt| dS )	zm
        Test bug that decref the iterator early.
        If the bug occurs, a segfault should occur
        r   r      c                      s    dd d S Nr*   r   r   )r%   r   r   	bm_pyfuncF   s    z0TestObjectMode.test_loop_nest.<locals>.bm_pyfuncc                      s    dd d S r+   r   r   )r'   r   r   bm_cfuncI   s    z/TestObjectMode.test_loop_nest.<locals>.bm_cfuncN)r   r   r    r!   assertEqualprintr   Z	benchmark)r$   r&   r,   r-   r   )r'   r%   r   test_loop_nest<   s    zTestObjectMode.test_loop_nestc                 C   s.   t t}tt gd }| ||| d S )N
   )r   r   nparrayobjectZassertIs)r$   r'   Zobjarrr   r   r   test_array_of_objectO   s    z#TestObjectMode.test_array_of_objectc              	   C   s   t dddd }| |dddg | |dddg | |dddg | t}|dd W 5 Q R X | d	t|j dS )
z6
        Test handling of the `in` comparison
        Tr    c                 S   s   | |kS r   r   )r   r   r   r   r   fooX   s    z2TestObjectMode.test_sequence_contains.<locals>.foo   r      Nzis not iterable)r   
assertTrueassertFalseassertRaises	TypeErrorZassertInstr	exception)r$   r7   Zraisesr   r   r   test_sequence_containsT   s    
z%TestObjectMode.test_sequence_containsc              	   C   sX   t }t|dtd}|j}dddg}|| | |g  | t |d W 5 Q R X d S )Nr   r      r   r*   *   )r   r   r    r!   r"   r<   r=   )r$   r%   r&   r'   lr   r   r   test_deliteme   s    
zTestObjectMode.test_delitemc                    sT   dd  t dd fdd}d}||}||}| |t| | || d S )Nc                  W   s   | S r   r   r   r   r   r   consumerq   s    z8TestObjectMode.test_starargs_non_tuple.<locals>.consumerTr6   c                    s    |  S r   r   r   rE   r   r   r7   t   s    z3TestObjectMode.test_starargs_non_tuple.<locals>.fooZijo)r   Zpy_funcr.   tuple)r$   r7   arggotexpectr   rF   r   test_starargs_non_tuplep   s    
z&TestObjectMode.test_starargs_non_tupleN)
__name__
__module____qualname__r(   r)   r0   r5   r@   rD   rK   r   r   r   r   r   .   s   r   c                   @   s0   e Zd ZdZdd Zdd Zdd Zdd	 Zd
S )TestObjectModeInvalidRewritezM
    Tests to ensure that rewrite passes didn't affect objmode lowering.
    c                 C   s   |  |j | |j |S r   )r:   Z
signaturesr;   Znopython_signatures)r$   Zdispr   r   r   _ensure_objmode   s    z,TestObjectModeInvalidRewrite._ensure_objmodec                    s>   dd   fdd}t |}| |d|d | | dS )zo
        Test code based on user submitted issue at
        https://github.com/numba/numba/issues/2159
        c                 S   s   | S r   r   r   r   r   r   test0   s    zQTestObjectModeInvalidRewrite.test_static_raise_in_objmode_fallback.<locals>.test0c                    s   | dkrt   | S r   )
ValueErrorr   rQ   r   r   test1   s    zQTestObjectModeInvalidRewrite.test_static_raise_in_objmode_fallback.<locals>.test1r1   N)r   r.   rP   )r$   rT   compiledr   rS   r   %test_static_raise_in_objmode_fallback   s
    zBTestObjectModeInvalidRewrite.test_static_raise_in_objmode_fallbackc                    sV   dd   fdd}t |}tdgtdgf}| || ||  | | dS )zo
        Test code based on user submitted issue at
        https://github.com/numba/numba/issues/2169
        c                 S   s   | S r   r   r   r   r   r   rQ      s    zSTestObjectModeInvalidRewrite.test_static_setitem_in_objmode_fallback.<locals>.test0c                    s&   t | } d|d<  |  |  S )Nr8   r   )r2   Zasarraysum)Za1Za2rS   r   r   test   s    
zRTestObjectModeInvalidRewrite.test_static_setitem_in_objmode_fallback.<locals>.testrA   r   N)r   r2   r3   r.   rP   )r$   rX   rU   argsr   rS   r   'test_static_setitem_in_objmode_fallback   s    zDTestObjectModeInvalidRewrite.test_static_setitem_in_objmode_fallbackc                 C   sD   d}|d7 }i }dt i}t||| |d }tdd|}|  dS )zG
        Test issue https://github.com/numba/numba/issues/3355
        zdef func():
z    np.array([1,2,3])
r2   funcTr6   N)r2   execr   )r$   Z	func_textZloc_varsZcustom_globalsr[   Zjittedr   r   r   test_dynamic_func_objmode   s    z6TestObjectModeInvalidRewrite.test_dynamic_func_objmodeN)rL   rM   rN   __doc__rP   rV   rZ   r]   r   r   r   r   rO      s
   rO   __main__)r^   numpyr2   ZunittestZnumba.core.compilerr   r   Znumbar   Z
numba.corer   Znumba.tests.supportr   r   r   r   r    Zforce_pyobjectr   r   r   rO   rL   mainr   r   r   r   <module>   s"   
Q@