σ
¦Υ\c           @` s  d  d l  m Z m Z m Z d  d l Z d  d l Z d  d l 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 m Z d  d l m Z m Z m Z m Z d  d l m Z d   Z d   Z d	   Z d
   Z d   Z d   Z d e f d     YZ d   Z d   Z  d   Z! d   Z" d   Z# e j$ j% d e j	 e	 g  d    Z& e j$ j' e j( d k d d e j$ j' e j) j* d k d d d     Z+ e j$ j' e j( d k d d e j$ j' e j) j* d k d d d     Z, e j$ j' e j( d k o+e j) j* d k d d d    Z- e j$ j' e j( d k oge j) j* d k d d d    Z. d S(    i    (   t   absolute_importt   divisiont   print_functionN(   t   add(   t   computet   delayed(   t   gett   _dumpst   get_contextt   remote_exception(   t   incc          C` sX   d   }  d   } t  |  } d | k s0 t  d | k sB t  d | k sT t  d S(   s>    Unrelated globals should not be included in serialized bytes c         S` s   t  j |  g  S(   N(   t   npt   array(   t   a(    (    s>   lib/python2.7/site-packages/dask/tests/test_multiprocessing.pyt   unrelated_function   s    c         S` s   |  | S(   N(    (   R   t   b(    (    s>   lib/python2.7/site-packages/dask/tests/test_multiprocessing.pyt   my_small_function   s    R   R   t   numpyN(   R   t   AssertionError(   R   R   R   (    (    s>   lib/python2.7/site-packages/dask/tests/test_multiprocessing.pyt   test_pickle_globals   s    		c           C` s   t  d   d  S(   Nt   12345(   t
   ValueError(    (    (    s>   lib/python2.7/site-packages/dask/tests/test_multiprocessing.pyt   bad"   s    c          C` sh   i t  f d 6}  y t |  d  Wn@ t k
 rc } t | t  sH t  d t |  k sd t  n Xd  S(   Nt   xR   (   R   R   t	   Exceptiont
   isinstanceR   R   t   str(   t   dskt   e(    (    s>   lib/python2.7/site-packages/dask/tests/test_multiprocessing.pyt   test_errors_propagate&   s    c          C` s©   t  d  }  t |  d  } t |  d  } t |  t |  k sH t  t | t   s] t  d t |  k su t  d t |  k s t  d t |  k s₯ t  d  S(   Nt   hellos   traceback-bodyt	   Traceback(   t	   TypeErrorR	   t   typeR   R   R   (   R   R   R   (    (    s>   lib/python2.7/site-packages/dask/tests/test_multiprocessing.pyt   test_remote_exception0   s    c           C` s   d   S(   Nc         S` s   |  d S(   Ni   (    (   R   (    (    s>   lib/python2.7/site-packages/dask/tests/test_multiprocessing.pyt   <lambda>=   t    (    (    (    (    s>   lib/python2.7/site-packages/dask/tests/test_multiprocessing.pyt   make_bad_result<   s    c          C` sV   i t  f d 6}  y t |  d  Wn. t k
 rQ } t |  j d k sR t  n Xd  S(   NR   t   PicklingErrort   AttributeError(   R&   R'   (   R%   R   R   R!   t   __name__R   (   R   R   (    (    s>   lib/python2.7/site-packages/dask/tests/test_multiprocessing.pyt(   test_unpicklable_results_generate_errors@   s
    t   NotUnpickleablec           B` s   e  Z d    Z d   Z RS(   c         C` s   d S(   N(    (    (   t   self(    (    s>   lib/python2.7/site-packages/dask/tests/test_multiprocessing.pyt   __getstate__L   s    c         C` s   t  d   d  S(   Ns   Can't unpickle me(   R   (   R+   t   state(    (    s>   lib/python2.7/site-packages/dask/tests/test_multiprocessing.pyt   __setstate__O   s    (   R(   t
   __module__R,   R.   (    (    (    s>   lib/python2.7/site-packages/dask/tests/test_multiprocessing.pyR*   K   s   	c          C` s»   t    }  d   } i | |  f d 6} y t | d  Wn( t k
 r` } t | t  sa t  n Xi | d f d 6|  d 6} y t | d  Wn( t k
 rΆ } t | t  s· t  n Xd  S(   Nc         S` s   d S(   Ni   (    (   R   (    (    s>   lib/python2.7/site-packages/dask/tests/test_multiprocessing.pyt   fooV   s    R   R   (   R*   R   R   R   R   R   (   R   R0   R   R   (    (    s>   lib/python2.7/site-packages/dask/tests/test_multiprocessing.pyt%   test_unpicklable_args_generate_errorsS   s    		
c          C` s|   t  j   }  t j j d |   U t i t d f d 6d  d k sJ t  t i t d f d 6d  d k sr t  Wd  QXd  S(   Nt   pooli   R   i   (   t   multiprocessingt   Poolt   daskt   configt   setR   R
   R   (   R2   (    (    s>   lib/python2.7/site-packages/dask/tests/test_multiprocessing.pyt   test_reuse_pooli   s    (c        	   C` s^   t  j j d t j d t j  7 t i d d 6t d d f d 6d  d k sT t  Wd  QXd  S(   Nt
   func_dumpst
   func_loadsi   R   i   t   yi   (	   R5   R6   R7   t   picklet   dumpst   loadsR   R   R   (    (    (    s>   lib/python2.7/site-packages/dask/tests/test_multiprocessing.pyt   test_dumps_loadsp   s    "c          C` sO   i d d 6t  d f d 6t d d f d 6}  t |  d d g  d k sK t  d  S(	   Ni   R   R;   i
   t   zi   i   (   i   i   (   R
   R   R   R   (   t   d(    (    s>   lib/python2.7/site-packages/dask/tests/test_multiprocessing.pyt&   test_fuse_doesnt_clobber_intermediatesu   s    *c       	   ` s   d d l  m }  i d d 6t d f d 6t d d f d 6} g    |  d   f d	     t | d d
 t Wd  QXt    d k s t  d  S(   Ni    (   t   Callbacki   R   R;   i
   R@   t   pretaskc         ` s     j  |   S(   N(   t   append(   t   keyt   args(   t   keys(    s>   lib/python2.7/site-packages/dask/tests/test_multiprocessing.pyR#   ~   R$   t   optimize_graphi   (   t   dask.callbacksRC   R
   R   R   t   Falset   lenR   (   RC   RA   (    (   RH   s>   lib/python2.7/site-packages/dask/tests/test_multiprocessing.pyt   test_optimize_graph_falsez   s    *t   randomc         ` s     f d   } d } t  j j d d  < t g  t |  D] } t | d t   ^ q;  \ } Wd  QXt t |   | k s t  d  S(   Nc           ` s    t    f d   t d  D  S(   Nc         3` s!   |  ] }   j  d  d  Vq d S(   i    i'  N(   t   randint(   t   .0t   i(   RN   (    s>   lib/python2.7/site-packages/dask/tests/test_multiprocessing.pys	   <genexpr>   s    i   (   t   tuplet   range(    (   RN   (    s>   lib/python2.7/site-packages/dask/tests/test_multiprocessing.pyt   f   s    i
   t	   schedulert	   processest   pure(	   R5   R6   R7   R   RS   R   RK   RL   R   (   RN   RT   t   NRQ   t   results(    (   RN   s>   lib/python2.7/site-packages/dask/tests/test_multiprocessing.pyt   test_random_seeds   s
    =t   win32t   reasons*   Windows doesn't support different contextsi   s+   Python 2 doesn't support different contextsc          C` s~   d   }  d d l  } d | j d <zJ t j j i d d 6  t i |  f d 6d  } Wd QX| sk t  Wd | j d =Xd S(	   sν    The 'multiprocessing.context' config is used to create the pool.

    We assume default is 'fork', and therefore test for 'spawn'.  If default
    context is changed this test will need to be modified to be different than
    that.
    c          S` s   d d  l  }  d |  j k S(   Ni    t   FAKE_MODULE_FOR_TEST(   t   syst   modules(   R^   (    (    s>   lib/python2.7/site-packages/dask/tests/test_multiprocessing.pyt   check_for_pytest   s    i    Ni   R]   t   spawns   multiprocessing.contextR   (   R^   R_   R5   R6   R7   R   R   (   R`   R^   t   result(    (    s>   lib/python2.7/site-packages/dask/tests/test_multiprocessing.pyt&   test_custom_context_used_python3_posix   s    	c           C` s   t    t j  d  k s t  t j j i d d 6 # t    t j  d  k sV t  Wd QXt j j i d d 6 # t    t j  d  k s t  Wd QXd S(   sq    get_context() respects configuration.

    If default context is changed this test will need to change too.
    t
   forkservers   multiprocessing.contextNRa   (   R   R3   t   NoneR   R5   R6   R7   (    (    (    s>   lib/python2.7/site-packages/dask/tests/test_multiprocessing.pyt$   test_get_context_using_python3_posixͺ   s
    	$s*   Python 3 POSIX supports different contextsc           C` s   t  i t d f d 6d  d k s( t  t j t  M t j j i d d 6 - t  i t d f d 6d  d k sz t  Wd QXWd QXd S(   sΆ    On Python 2/Windows, setting 'multiprocessing.context' doesn't explode.

    Presumption is it's not used since unsupported, but mostly we care about
    not breaking anything.
    i   R   i   Rd   s   multiprocessing.contextN(	   R   R
   R   t   pytestt   warnst   UserWarningR5   R6   R7   (    (    (    s>   lib/python2.7/site-packages/dask/tests/test_multiprocessing.pyt%   test_custom_context_ignored_elsewhereΊ   s    (c        
   C` sd   t    t k s t  t j t  : t j j i d d 6  t    t k sT t  Wd QXWd QXd S(   s@    On Python 2/Windows, get_context() always returns same context.Rd   s   multiprocessing.contextN(	   R   R3   R   Rg   Rh   Ri   R5   R6   R7   (    (    (    s>   lib/python2.7/site-packages/dask/tests/test_multiprocessing.pyt   test_get_context_always_defaultΘ   s    (/   t
   __future__R    R   R   R^   R3   t   operatorR   R<   RN   R   R   Rg   R5   R   R   t   dask.multiprocessingR   R   R   R	   t   dask.utils_testR
   R   R   R   R"   R%   R)   t   objectR*   R1   R8   R?   RB   RM   t   markt   parametrizeRZ   t   skipift   platformt   version_infot   majorRc   Rf   Rj   Rk   (    (    (    s>   lib/python2.7/site-packages/dask/tests/test_multiprocessing.pyt   <module>   sH   "			
									'**