σ
\K]c           @` sΫ   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 Z d  d l	 m
 Z d  d l m Z d  d l m Z d d l m Z m Z d d l Td	 e f d
     YZ e d k rΧ e j   n  d S(   i    (   t   print_functiont   absolute_importt   divisionN(   t   unittest_support(   t   TypingError(   t   registryi   (   t   TestCaset   tag(   t   *t   TestDispatcherPicklingc           B` s
  e  Z d    Z e j d    Z d   Z e d  d    Z e d  d    Z	 e d  d    Z
 d   Z d   Z d	   Z d
   Z d   Z d   Z d   Z d   Z d   Z d   Z d   Z d   Z e d  d    Z e d  d    Z d   Z RS(   c         O` s2   x+ t  t j d  D] } | | | |  q Wd  S(   Ni   (   t   ranget   picklet   HIGHEST_PROTOCOL(   t   selft   metht   argst   kwargst   proto(    (    s9   lib/python2.7/site-packages/numba/tests/test_serialize.pyt   run_with_protocols   s    c         c` sE   t  j d } | j } t | j    | _ z	 d  VWd  | | _ Xd  S(   Nt   cpu(   R   t   dispatcher_registryt   targetdescrt   type(   R   t   dispatcher_clst	   old_descr(    (    s9   lib/python2.7/site-packages/numba/tests/test_serialize.pyt   simulate_fresh_target   s    		c         ` sa       f d   } | |  t  j | |  }  j    t  j |  } | |  Wd  QXd  S(   Nc         ` sN   t   t  r4 t  t  r4  j  |     n  j |        d  S(   N(   t
   isinstanceR   t
   issubclasst	   Exceptiont   assertRaisest   assertPreciseEqual(   t   func(   R   t   expected_resultR   (    s9   lib/python2.7/site-packages/numba/tests/test_serialize.pyt   check_result$   s    (   R   t   dumpsR   t   loads(   R   R   R   R    R   R!   t   pickledt   new_func(    (   R   R    R   s9   lib/python2.7/site-packages/numba/tests/test_serialize.pyt
   check_call#   s    
t	   importantc         C` s6   |  j  |  j t d d  |  j  |  j t d d  d  S(   Ni   i   i   g333333σ?gΝΜΜΜΜΜ@(   i   i   (   g333333σ?gΝΜΜΜΜΜ@(   R   R&   t   add_with_sig(   R   (    (    s9   lib/python2.7/site-packages/numba/tests/test_serialize.pyt   test_call_with_sig2   s    c         C` sO   |  j  |  j t d d
  |  j  |  j t d d  |  j  |  j t d d  d  S(   Ni   i   i   g      @g333333σ?g333333@t   abct   at   bc(   i   i   (   g333333σ?g333333@(   R+   R,   (   R   R&   t   add_without_sig(   R   (    (    s9   lib/python2.7/site-packages/numba/tests/test_serialize.pyt   test_call_without_sig8   s    c         C` sB   |  j  |  j t d d  |  j  |  j t t t   t   f  d  S(   Ng      @g333333σ?g333333@(   g333333σ?g333333@(   R   R&   t   add_nopythonR   t   object(   R   (    (    s9   lib/python2.7/site-packages/numba/tests/test_serialize.pyt   test_call_nopython?   s    c         C` s   |  j  |  j t t d  d  S(   Ni   i   (   i   i   (   R   R&   t   add_nopython_failR   (   R   (    (    s9   lib/python2.7/site-packages/numba/tests/test_serialize.pyt   test_call_nopython_failE   s    c         C` s   |  j  |  j t d d  d  S(   Ng      @g      @(   g      @(   R   R&   t   get_global_objmode(   R   (    (    s9   lib/python2.7/site-packages/numba/tests/test_serialize.pyt   test_call_objmode_with_globalI   s    c         C` s)   t  d  } |  j |  j | d d  d  S(   Ni   i   i   i   (   i   i   (   t   closureR   R&   (   R   t   inner(    (    s9   lib/python2.7/site-packages/numba/tests/test_serialize.pyt   test_call_closureL   s    c         K` s,   t  d |  } |  j |  j | d d  d  S(   Ng      @g      @g      @(   g      @(   t   closure_with_globalsR   R&   (   R   t   jit_argsR7   (    (    s9   lib/python2.7/site-packages/numba/tests/test_serialize.pyt   check_call_closure_with_globalsP   s    c         C` s   |  j  d t  d  S(   Nt   nopython(   R;   t   True(   R   (    (    s9   lib/python2.7/site-packages/numba/tests/test_serialize.pyt'   test_call_closure_with_globals_nopythonT   s    c         C` s   |  j  d t  d  S(   Nt   forceobj(   R;   R=   (   R   (    (    s9   lib/python2.7/site-packages/numba/tests/test_serialize.pyt&   test_call_closure_with_globals_objmodeW   s    c         C` s)   t  d  } |  j |  j | d d  d  S(   Ng      @g      &@g      @g      @(   g      @g      @(   t   closure_calling_other_functionR   R&   (   R   R7   (    (    s9   lib/python2.7/site-packages/numba/tests/test_serialize.pyt(   test_call_closure_calling_other_functionZ   s    c         C` s)   t  d  } |  j |  j | d d  d  S(   Ng      @g       @g      @(   g      @(   t   closure_calling_other_closureR   R&   (   R   R7   (    (    s9   lib/python2.7/site-packages/numba/tests/test_serialize.pyt'   test_call_closure_calling_other_closure^   s    c         C` s   |  j  |  j t d d  d  S(   Ni$   i   (   i   (   R   R&   t   dyn_func(   R   (    (    s9   lib/python2.7/site-packages/numba/tests/test_serialize.pyt   test_call_dyn_funcb   s    c         C` s   |  j  |  j t d d  d  S(   Ni$   i   (   i   (   R   R&   t   dyn_func_objmode(   R   (    (    s9   lib/python2.7/site-packages/numba/tests/test_serialize.pyt   test_call_dyn_func_objmodef   s    c         C` s)   t  d  } |  j |  j t  | d  d  S(   Ng        (   g        (   t   get_renamed_moduleR   R&   (   R   t   expected(    (    s9   lib/python2.7/site-packages/numba/tests/test_serialize.pyt   test_renamed_modulej   s    c         C` s6   |  j  |  j t d d  |  j  |  j t d d  d  S(	   Ni.   i   i   y              π?i   (   i   i   y      @      π?(   y              π?i   (   R   R&   t   generated_add(   R   (    (    s9   lib/python2.7/site-packages/numba/tests/test_serialize.pyt   test_call_generatedq   s    
c         C` sJ   t  d  } t j |  } d j t     } t j t j d | g  d S(   s}   
        Check that reconstructing doesn't depend on resources already
        instantiated in the original process.
        g      @s±   if 1:
            import pickle

            data = {pickled!r}
            func = pickle.loads(data)
            res = func(4.0)
            assert res == 8.0, res
            s   -cN(	   RC   R   R"   t   formatt   localst
   subprocessR&   t   syst
   executable(   R   R   R$   t   code(    (    s9   lib/python2.7/site-packages/numba/tests/test_serialize.pyt   test_other_processw   s    c         C` s{  t  d  } t j |  } t  d  } t j |  } t j |  } t j |  } t j |  } |  j | |  |  j | d d  d  | j   |  j | d d  d  |  j | |  |  j | d d  d  t  d  } | d	 d
  t j |  } ~ t j	   t j |  } t j |  } |  j | |  |  j | d d  d  | j   |  j | d d  d  d S(   sΌ   
        Check that deserializing the same function multiple times re-uses
        the same dispatcher object.

        Note that "same function" is intentionally under-specified.
        i   i   i   i   i
   i   i   i   i*   i+   i   i   N(
   R6   R   R"   R#   t   assertIst   assertEqualt   disable_compilet   assertIsNott   gct   collect(   R   R   R$   t   func2t   pickled2t   ft   gt   h(    (    s9   lib/python2.7/site-packages/numba/tests/test_serialize.pyt
   test_reuse   s0    


c         C` s#   d } t  j t j d | g  d S(   sN   
        The imp module was deprecated in v3.4 in favour of importlib
        s  if 1:
            import pickle
            import warnings
            with warnings.catch_warnings(record=True) as w:
                warnings.simplefilter('always', DeprecationWarning)
                from numba import njit
                @njit
                def foo(x):
                    return x + 1
                foo(1)
                serialized_foo = pickle.dumps(foo)
            for x in w:
                if 'serialize.py' in x.filename:
                    assert "the imp module is deprecated" not in x.msg
        s   -cN(   RP   R&   RQ   RR   (   R   RS   (    (    s9   lib/python2.7/site-packages/numba/tests/test_serialize.pyt   test_imp_deprecation―   s    (   t   __name__t
   __module__R   t
   contextlibt   contextmanagerR   R&   R   R)   R.   R1   R3   R5   R8   R;   R>   R@   RB   RD   RF   RH   RK   RM   RT   R`   Ra   (    (    (    s9   lib/python2.7/site-packages/numba/tests/test_serialize.pyR	      s*   														&t   __main__(   t
   __future__R    R   R   Rd   RY   R   RP   RQ   t   numbaR   t   unittestt   numba.errorsR   t   numba.targetsR   t   supportR   R   t   serialize_usecasesR	   Rb   t   main(    (    (    s9   lib/python2.7/site-packages/numba/tests/test_serialize.pyt   <module>   s   
΄