๓
สฝ๗Xc           @` s๗  d  d l  m Z m Z m Z d  d l m Z m Z m 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 m Z d  d l m Z y d  d l Z e Z Wn e k
 rว e Z n Xd Z d d  Z d	   Z d
   Z d   Z i e j d 6e j d 6e j d 6e j  d 6Z! i	 d   d 6d   d 6d   d 6d   d 6d   d 6d   d 6d   d 6d   d 6d   d  6Z" i d!   d" 6d#   d$ 6d%   d& 6d'   d( 6Z# i e d 6e d 6e j$ d 6Z% d)   Z& d*   Z' d+   Z( d,   Z) d S(-   i    (   t   divisiont   print_functiont   absolute_import(   t   assert_equalt   assert_raisest   assert_N(   t   _ccallback_c(   t   _test_ccallback(   t   LowLevelCallableg       @c         C` s;   |  t  k r t d   n  | d  k r/ |  d S|  | Sd  S(   Ns	   bad valuei   (   t   ERROR_VALUEt
   ValueErrort   None(   t   at	   user_data(    (    s>   /tmp/pip-build-7oUkmx/scipy/scipy/_lib/tests/test_ccallback.pyt   callback_python   s
    c         C` sX   t  s t j d   n  t j |  t j  } | j } t j   } | j | |  } | S(   Ns   cffi not installed(	   t	   HAVE_CFFIt   noset   SkipTestt   ctypest   castt   c_void_pt   valuet   cffit   FFI(   t   baset	   signaturet   voidpt   addresst   ffit   func(    (    s>   /tmp/pip-build-7oUkmx/scipy/scipy/_lib/tests/test_ccallback.pyt   _get_cffi_func    s    	c          C` s+   t  j d  }  t  j t  j |   t  j  S(   Ng       @(   R   t   c_doubleR   t   pointert   c_voidp(   R   (    (    s>   /tmp/pip-build-7oUkmx/scipy/scipy/_lib/tests/test_ccallback.pyt   _get_ctypes_data.   s    c          C` s4   t  s t j d   n  t j   }  |  j d d  S(   Ns   cffi not installeds   double *g       @(   R   R   R   R   R   t   new(   R   (    (    s>   /tmp/pip-build-7oUkmx/scipy/scipy/_lib/tests/test_ccallback.pyt   _get_cffi_data3   s    t   simplet   nodatat   nonlocalt   cythonc           C` s   t  S(   N(   R   (    (    (    s>   /tmp/pip-build-7oUkmx/scipy/scipy/_lib/tests/test_ccallback.pyt   <lambda>C   s    t   pythonc           C` s
   t  j   S(   N(   R   t   test_get_plus1_capsule(    (    (    s>   /tmp/pip-build-7oUkmx/scipy/scipy/_lib/tests/test_ccallback.pyR)   D   s    t   capsulec           C` s   t  j t d  S(   Nt   plus1_cython(   R   t   from_cythont   _test_ccallback_cython(    (    (    s>   /tmp/pip-build-7oUkmx/scipy/scipy/_lib/tests/test_ccallback.pyR)   E   s    c           C` s   t  j S(   N(   R/   t   plus1_ctypes(    (    (    s>   /tmp/pip-build-7oUkmx/scipy/scipy/_lib/tests/test_ccallback.pyR)   F   s    R   c           C` s   t  t j d  S(   Ns!   double (*)(double, int *, void *)(   R   R/   R0   (    (    (    s>   /tmp/pip-build-7oUkmx/scipy/scipy/_lib/tests/test_ccallback.pyR)   G   s   	R   c           C` s
   t  j   S(   N(   R   t   test_get_plus1b_capsule(    (    (    s>   /tmp/pip-build-7oUkmx/scipy/scipy/_lib/tests/test_ccallback.pyR)   I   s    t	   capsule_bc           C` s   t  j t d  S(   Nt   plus1b_cython(   R   R.   R/   (    (    (    s>   /tmp/pip-build-7oUkmx/scipy/scipy/_lib/tests/test_ccallback.pyR)   J   s    t   cython_bc           C` s   t  j S(   N(   R/   t   plus1b_ctypes(    (    (    s>   /tmp/pip-build-7oUkmx/scipy/scipy/_lib/tests/test_ccallback.pyR)   K   s    t   ctypes_bc           C` s   t  t j d  S(   Ns)   double (*)(double, double, int *, void *)(   R   R/   R5   (    (    (    s>   /tmp/pip-build-7oUkmx/scipy/scipy/_lib/tests/test_ccallback.pyR)   L   s   	t   cffi_bc           C` s
   t  j   S(   N(   R   t   test_get_plus1bc_capsule(    (    (    s>   /tmp/pip-build-7oUkmx/scipy/scipy/_lib/tests/test_ccallback.pyR)   R   s    t
   capsule_bcc           C` s   t  j t d  S(   Nt   plus1bc_cython(   R   R.   R/   (    (    (    s>   /tmp/pip-build-7oUkmx/scipy/scipy/_lib/tests/test_ccallback.pyR)   S   s    t	   cython_bcc           C` s   t  j S(   N(   R/   t   plus1bc_ctypes(    (    (    s>   /tmp/pip-build-7oUkmx/scipy/scipy/_lib/tests/test_ccallback.pyR)   T   s    t	   ctypes_bcc           C` s   t  t j d  S(   Ns1   double (*)(double, double, double, int *, void *)(   R   R/   R<   (    (    (    s>   /tmp/pip-build-7oUkmx/scipy/scipy/_lib/tests/test_ccallback.pyR)   U   s   	t   cffi_bcc          c` su   d   }  xe t  t j    D]Q } xH t  t j    D]4 } x+ t  t j    D] } |  | | | f VqN Wq5 Wq Wd  S(   Nc         ` s    t  |  }  t       t |   }   t k rB   f d   } n t   |  } t      t |    d  d  t t |    t  t |  | d  d  d  S(   Nc         ` s     |  d  S(   Ng       @(    (   t   x(   R   (    s>   /tmp/pip-build-7oUkmx/scipy/scipy/_lib/tests/test_ccallback.pyR)   g   s    g      ๐?g       @g      @(	   t   CALLERSt   FUNCSt
   USER_DATASR   R   R   R   R
   R	   (   t   callerR   R   t   func2(    (   R   s>   /tmp/pip-build-7oUkmx/scipy/scipy/_lib/tests/test_ccallback.pyt   checka   s    
(   t   sortedR@   t   keysRA   RB   (   RE   RC   R   R   (    (    s>   /tmp/pip-build-7oUkmx/scipy/scipy/_lib/tests/test_ccallback.pyt   test_callbacks`   s
    	c          c` su   d   }  xe t  t j    D]Q } xH t  t j    D]4 } x+ t  t j    D] } |  | | | f VqN Wq5 Wq Wd  S(   Nc         ` s๕   t  |  }  t |   } t         t k rB   f d   } n t   |  } t      t t |  t    d  t t |  | d  t    } y |  | d  WnH t k
 r๐ } t |  } t | j	 | k |  t d | k |  n Xd  S(   Nc         ` s     |  d  S(   Ng       @(    (   R?   (   R   (    s>   /tmp/pip-build-7oUkmx/scipy/scipy/_lib/tests/test_ccallback.pyR)      s    g      ๐?s&   double (double, double, int *, void *)(
   R@   RB   t	   BAD_FUNCSR   R   R   R
   t   strR   R   (   RC   R   R   RD   t   llfunct   errt   msg(    (   R   s>   /tmp/pip-build-7oUkmx/scipy/scipy/_lib/tests/test_ccallback.pyRE   |   s     
(   RF   R@   RG   RI   RB   (   RE   RC   R   R   (    (    s>   /tmp/pip-build-7oUkmx/scipy/scipy/_lib/tests/test_ccallback.pyt   test_bad_callbacks{   s
    	c          C` s   t  j }  t  j   } t | d d } t | j d  t t |  | d  t | d d } t | j d  t |  | d  d  d  S(   NR   s   bad signaturei   s   double (double, int *, void *)i   (   R   t   test_call_simpleR+   R   R   R   R   R
   (   RC   R   t
   llcallable(    (    s>   /tmp/pip-build-7oUkmx/scipy/scipy/_lib/tests/test_ccallback.pyt   test_signature_override   s    	c          #` sD     f d       f d   }  x t  j   D] } |  | f Vq+ Wd  S(   Nc         ` s;   |  d k r d S     f d   |  d  } d | Sd  S(   Ni    i   c         ` s     |    S(   N(    (   R?   (   t   callbackRC   (    s>   /tmp/pip-build-7oUkmx/scipy/scipy/_lib/tests/test_ccallback.pyR)   ฎ   s    i   (    (   R   RC   t   res(   RR   (   RC   s>   /tmp/pip-build-7oUkmx/scipy/scipy/_lib/tests/test_ccallback.pyRR   ช   s    c         ` sฑ   t      g   d       f d   } g  t d  D] } t j d |  ^ q; } x | D] } | j   q` Wx | D] } | j   q{ Wt  d  g t |   d  S(   Ni
   c          ` s9   t  j d      f d     }   j |   d  S(   Ng{ฎGแz?c         ` s     |    S(   N(    (   R?   (   RR   RC   (    s>   /tmp/pip-build-7oUkmx/scipy/scipy/_lib/tests/test_ccallback.pyR)   บ   s    (   t   timet   sleept   append(   t   r(   RR   RC   t   countt   results(    s>   /tmp/pip-build-7oUkmx/scipy/scipy/_lib/tests/test_ccallback.pyt   runธ   s    i   t   targetg       @(   R@   t   ranget	   threadingt   Threadt   startt   joinR   t   len(   RC   RZ   t   jt   threadst   thread(   RR   (   RC   RX   RY   s>   /tmp/pip-build-7oUkmx/scipy/scipy/_lib/tests/test_ccallback.pyRE   ฑ   s    
+(   R@   RG   (   RE   RC   (    (   RR   s>   /tmp/pip-build-7oUkmx/scipy/scipy/_lib/tests/test_ccallback.pyt   test_threadsafetyฉ   s    (*   t
   __future__R    R   R   t   numpy.testingR   R   R   RT   R   R   R]   t
   scipy._libR   R/   R   t   scipy._lib._ccallbackR   R   t   TrueR   t   ImportErrort   FalseR	   R   R   R   R"   R$   RO   t   test_call_nodatat   test_call_nonlocalt   test_call_cythonR@   RA   RI   t   test_get_data_capsuleRB   RH   RN   RQ   Re   (    (    (    s>   /tmp/pip-build-7oUkmx/scipy/scipy/_lib/tests/test_ccallback.pyt   <module>   s\   

				













		!	