U
    e                     @   s   d dl Z d dlZd dlZd dlmZ d dlmZ d dlmZ zd dl	Z	dZ
W n   dZ
Y nX edddZdZG d	d
 d
eZdS )    N)inline)	safe_type)
CythonTestTF)forcequietd   c                   @   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d Zdd Zee ddd ZdS )
TestInlinec                 C   sJ   t |  tt| _tjdr0tjdd}nt	j
dd}|| jd< d S )NZTEST_TMPr   Zcython_inline_)prefixlib_dir)r   setUpdict	test_kwds
_call_kwdsospathisdirjointempfilemkdtemp)selfr
    r   A/tmp/pip-unpacked-wheel-7k3cqui1/Cython/Build/Tests/TestInline.pyr      s    

zTestInline.setUpc                 C   s   |  td| jd d S )N
return 1+2   )r   assertEqualr   r   r   r   r   r   test_simple   s    zTestInline.test_simplec                 C   s"   |  tddg d| jd d S )NZ
            cimport cython
            return cython.typeof(a), cython.typeof(b)
        g      ?)ab)doublezlist object)r   r   r   r   r   r   
test_types   s     zTestInline.test_typesc                 C   s    d}d}|  td| jd d S )N      
return a+br   )r%   r   )r   r   r    r   r   r   test_locals%   s    zTestInline.test_localsc                 C   s   |  td| jtd  d S )Nreturn global_value + 1r#   )r'   )r   r   r   global_valuer   r   r   r   test_globals*   s    zTestInline.test_globalsc                 C   s"   |  td| jtddg d d S )NQ
            a = 1
            cdef double b = 2
            cdef c = []
        r#   g       @)r   r    c)r*   )r   r   r   r   r   r   r   r   test_no_return-   s
    zTestInline.test_no_returnc                 C   s$   t d| jd }| |dd d S )Ndef foo(x): return x * xfoo   1   )r-   )r   r   r   )r   r.   r   r   r   test_def_node4   s    zTestInline.test_def_nodec                 C   s,   G dd dt }tdd }| || d S )Nc                   @   s   e Zd ZdS )z'TestInline.test_class_ref.<locals>.TypeN)__name__
__module____qualname__r   r   r   r   Type9   s   r5   )objectr   r   )r   r5   tpr   r   r   test_class_ref8   s    zTestInline.test_class_refc                 C   s0   dd l }tdddi| j}| t|t d S )Nr   l
        b = cy.declare(float, a)
        c = cy.declare(cy.pointer(cy.float), &b)
        return b
        r   r   )r9   )Zcythonr   r   r   typefloat)r   cyr    r   r   r   	test_pure>   s    zTestInline.test_purec                 C   s$   |  tddddgddidd d S )	Nzreturn sum(x)r#   r$   r   ZboundscheckF)xZcython_compiler_directives   r   r   r   r   r   r   test_compiler_directivesG   s    z#TestInline.test_compiler_directivesc                 C   sb   d}|  t|ddd ddd |  t|ddd ddd |  t|ddd ddd d S )Nzdef f(int a, int b): return a/br$   )Zlanguage_levelf   r   g      @r@   )r   Zinline_divcoder   r   r   test_lang_versionO   s    zTestInline.test_lang_versionc                 C   s   d}|  t|d ddd |  t|d ddd |  t|d ddd	 |  t|d ddd t|d }|  |ddd |  |ddd d S )
Nz!def f(int a, int b): return a * brB   rC   r$   
   r      r?      r@   )r   Zinline_mulcoderB   r   r   r   test_repeated_use_   s    zTestInline.test_repeated_usezNumPy is not availablec                 C   sJ   dd l }|d}d|d< | t|d | td	d|i| jd d S )
Nr   )rE      rE   )r   r   z&numpy.ndarray[numpy.float64_t, ndim=2]return a[0,0]r   g      $@)rJ   )numpyZndarrayr   r   r   r   )r   rK   r   r   r   r   
test_numpyj   s
    
zTestInline.test_numpyN)r2   r3   r4   r   r   r"   r&   r)   r,   r1   r8   r=   rA   rD   rH   unittestZskipIf	has_numpyrL   r   r   r   r   r      s   		r   )r   r   rM   ZCython.Shadowr   ZCython.Build.Inliner   ZCython.TestUtilsr   rK   rN   r   r   r(   r   r   r   r   r   <module>   s   
