ó
ßüÚ\c           @   s¯   d  d l  Z  e  j d ƒ Z e  j d ƒ Z d  d l m Z m Z d  d l m Z d „  Z	 d „  Z
 d „  Z d	 „  Z d  d
 l m Z d  d l j Z e d e ƒ d „  ƒ Z d S(   iÿÿÿÿNt   netCDF4t   numpy(   t   deserializet	   serialize(   t   tmpfilec         C   sÐ   t  j |  d d ƒµ } | j d d ƒ | j d t j d ƒ } t j d ƒ | (| j d ƒ } | j d ƒ } | j d t j d ƒ } t j d ƒ d | (| j d	 t j d ƒ } t j d ƒ d
 | (Wd  QXd  S(   Nt   modet   wt   xi   t   groups   group/group1s   group/yi   s   group/group1/zi   (   R   (   R   (   R   (   R    t   Datasett   createDimensiont   createVariablet   npt   int32t   aranget   createGroup(   t   fnt   dst   vt   gt   g2t   v2t   v3(    (    sF   lib/python2.7/site-packages/distributed/protocol/tests/test_netcdf4.pyt   create_test_dataset   s    c          C   sê   t  ƒ  Û }  t |  ƒ t j |  d d ƒ³ } t t | ƒ Œ  } | j ƒ  | j ƒ  k s^ t ‚ t | t j ƒ sv t ‚ | j	 d j
 d k s’ t ‚ | j	 d j t j k s± t ‚ | j	 d t j d ƒ k j ƒ  sÚ t ‚ Wd  QXWd  QXd  S(   NR   t   rR   i   (   R   (   R   R   R    R	   R   R   t   filepatht   AssertionErrort
   isinstancet	   variablest
   dimensionst   dtypeR   R   R   t   all(   R   t   fR   (    (    sF   lib/python2.7/site-packages/distributed/protocol/tests/test_netcdf4.pyt"   test_serialize_deserialize_dataset   s    
c          C   s¼   t  ƒ  ­ }  t |  ƒ t j |  d d ƒ… } | j d } t t | ƒ Œ  } t | t j ƒ se t	 ‚ | j
 d k sz t	 ‚ | j | j k s’ t	 ‚ | | k j ƒ  s¬ t	 ‚ Wd  QXWd  QXd  S(   NR   R   R   (   R   (   R   R   R    R	   R   R   R   R   t   VariableR   R   R   R   (   R   R    R   t   y(    (    sF   lib/python2.7/site-packages/distributed/protocol/tests/test_netcdf4.pyt#   test_serialize_deserialize_variable(   s    
c          C   s—  t  ƒ  ˆ}  t |  ƒ t j |  d d ƒ`} x¨ d d g D]š } | | } t t | ƒ Œ  } t | t j ƒ su t ‚ | j	 | j	 k s t ‚ t
 | j ƒ t
 | j ƒ k s± t ‚ t
 | j ƒ t
 | j ƒ k s; t ‚ q; W| j d | d j d | d j d g } x | D]w } t t | ƒ Œ  } t | t j ƒ s<t ‚ | j d k sQt ‚ | j | j k sit ‚ | | k j ƒ  st ‚ qWWd  QXWd  QXd  S(	   NR   R   R   s   group/group1R   R#   t   z(   R   (   R   R   R    R	   R   R   R   t   GroupR   t   namet   listt   groupsR   R"   R   R   R   (   R   R    t   pathR   t   ht   varsR   R#   (    (    sF   lib/python2.7/site-packages/distributed/protocol/tests/test_netcdf4.pyt    test_serialize_deserialize_group4   s&    

$(
(   t   gen_clustert   clientc   	      c   s   t  ƒ   } t | ƒ t j | d d ƒY } | j d } t j | d d ƒ} |  j | ƒ } | V} | | k j ƒ  s€ t	 ‚ Wd  QXWd  QXd  S(   NR   R   R   t   chunksi   (
   R   R   R    R	   R   t   dat
   from_arrayt   computeR   R   (	   t   ct   st   at   bR   R    t   dsetR   R#   (    (    sF   lib/python2.7/site-packages/distributed/protocol/tests/test_netcdf4.pyt   test_netcdf4_serializeT   s    
(   t   pytestt   importorskipR    R   t   distributed.protocolR   R   t   distributed.utilsR   R   R!   R$   R-   t   distributed.utils_testR.   t
   dask.arrayt   arrayR1   t   TrueR9   (    (    (    sF   lib/python2.7/site-packages/distributed/protocol/tests/test_netcdf4.pyt   <module>   s   				