σ
ίΖχXc           @@  s©  d  d l  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
 Z d  d l Z e j d k s e j d k r₯ d  d l Z n; y d  d l Z Wn( e k
 rί e d e j d    n Xy e j e	 d	   \ Z Z Wn e k
 re Z n' Xe Z e j e  e j e  [ [ d
 e j f d     YZ e g  e j j d  d  d !D] Z e  e  ^ qu Z! e d d d   Z# d S(   i    (   t   absolute_importN(   t   contextmanager(   t   unichri   i   i   s=   unittest2 is required to run the test suite with python-%d.%di·  t   TestCasec           B@  s   e  Z d  Z e d    Z e d    Z d d d d  Z d   Z d   Z	 e
 e j d  sl d	   Z n  d d d
  Z d   Z RS(   s(   
        Base class for unit tests.
    c         C@  s   t  j d d  |  _ d  S(   Nt   prefixs
   h5py-test_(   t   tempfilet   mkdtempt   tempdir(   t   cls(    (    s/   /tmp/pip-build-X4mzal/h5py/h5py/tests/common.pyt
   setUpClass9   s    c         C@  s   t  j |  j  d  S(   N(   t   shutilt   rmtreeR   (   R   (    (    s/   /tmp/pip-build-X4mzal/h5py/h5py/tests/common.pyt   tearDownClass=   s    s   .hdf5t    c         C@  s1   | d  k r |  j } n  t j | | d |  j S(   Nt   dir(   t   NoneR   R   t   mktemp(   t   selft   suffixR   R   (    (    s/   /tmp/pip-build-X4mzal/h5py/h5py/tests/common.pyR   A   s    c         C@  s   t  j |  j   d  |  _ d  S(   Nt   w(   t   h5pyt   FileR   t   f(   R   (    (    s/   /tmp/pip-build-X4mzal/h5py/h5py/tests/common.pyt   setUpF   s    c         C@  s+   y |  j  r |  j  j   n  Wn n Xd  S(   N(   R   t   close(   R   (    (    s/   /tmp/pip-build-X4mzal/h5py/h5py/tests/common.pyt   tearDownI   s
    	t   assertSameElementsc         C@  s°   xS | D]K } t  } x# | D] } | | k r t } q q W| s t d |   q q WxS | D]K } t  } x# | D] } | | k rp t } qp qp W| s] t d |   q] q] Wd  S(   Ns    Item '%s' appears in a but not bs    Item '%s' appears in b but not a(   t   Falset   Truet   AssertionError(   R   t   at   bt   xt   matcht   y(    (    s/   /tmp/pip-build-X4mzal/h5py/h5py/tests/common.pyR   R   s    c         C@  sϋ  | d k r d } n  | d k r* d } n
 d | } t j |  sR t j |  r― |  j t j |  os t j |  d | | | f  |  j | | | k  d | | f  d S|  j | j | j k d | j | j | f  |  j | j | j k d | j | j | f  | j j d k	 rmxΥ | j j D]: } d	 | | f } |  j | | | | d
 | d | q,Wn | j j d k rΐ|  j t j	 t j
 | d | d  | k   d | | f  n7 |  j t j	 | d | d k  d | j j | f  d S(   sΉ    Make sure dset and arr have the same shape, dtype and contents, to
            within the given precision.

            Note that dset may be a NumPy array or an HDF5 dataset.
        gρhγ΅ψδ>R   s    (%s)s&   Scalar/array mismatch ("%r" vs "%r")%ss"   Scalars differ by more than %.3f%sNs   Shape mismatch (%s vs %s)%ss   Dtype mismatch (%s vs %s)%ss   [FIELD %s] %st   messaget	   precisiont   iR   .s!   Arrays differ by more than %.3f%ss"   Arrays are not equal (dtype %s) %s(   R%   R   (   R   t   npt   isscalart   assert_t   shapet   dtypet   namest   assertArrayEqualt   kindt   allt   abst   str(   R   t   dsett   arrR#   R$   t   n(    (    s/   /tmp/pip-build-X4mzal/h5py/h5py/tests/common.pyR,   c   s<    		
+'c         C@  s{   d } y | | } Wn t k
 r5 } t |  } n X| d k rY |  j | | |  n |  j |   | | Wd QXd S(   s   Apply slicing arguments "s" to both dset and arr.
        
        Succeeds if the results of the slicing are identical, or the
        exception raised is of the same type for both.
        
        "arr" must be a Numpy array; "dset" may be a NumPy array or dataset.
        N(   R   t	   Exceptiont   typeR,   t   assertRaises(   R   R1   R2   t   st   exct
   arr_resultt   e(    (    s/   /tmp/pip-build-X4mzal/h5py/h5py/tests/common.pyt   assertNumpyBehavior   s    N(   t   __name__t
   __module__t   __doc__t   classmethodR	   R   R   R   R   R   t   hasattrt   utR   R   R,   R;   (    (    (    s/   /tmp/pip-build-X4mzal/h5py/h5py/tests/common.pyR   3   s   		0t   .R   c         c@  so   t  j d d |  d t 6 } | j } | d k	 rM | j |  | j   n  Wd QX| Vt j | d t	 d S(   sμ   
    Context manager which yields the path to a closed temporary file with the
    suffix `suffix`. The file will be deleted on exiting the context. An
    additional argument `text` can be provided to have the file contain `text`.
    s   w+tR   t   deleteNt   ignore_errors(
   R   t   NamedTemporaryFileR   t   nameR   t   writet   flushR
   R   R   (   R   t   textt	   test_filet	   file_name(    (    s/   /tmp/pip-build-X4mzal/h5py/h5py/tests/common.pyt   closed_tempfile©   s    	(   i   i   (   i   i   ($   t
   __future__R    t   syst   osR
   R   t
   contextlibR   t   sixR   t   numpyR&   R   t   version_infot   unittestRA   t	   unittest2t   ImportErrort   mkstempt   testfilet   fnamet   UnicodeErrorR   t   UNICODE_FILENAMESR   R   t   unlinkR   t   tuplet   __version__t   splitR%   t   intt   NUMPY_RELEASE_VERSIONR   RL   (    (    (    s/   /tmp/pip-build-X4mzal/h5py/h5py/tests/common.pyt   <module>
   s:   
t8