σ
jϊ\c           @@  s’  d  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	 d d l
 m Z d d l
 m Z m Z d d l
 m Z d d l Z d d l m Z d	 e	 j e f d
     YZ d e	 j e f d     YZ d e f d     YZ d e f d     YZ d e f d     YZ d e f d     YZ d e f d     YZ d e f d     YZ d e	 j e f d     YZ d e	 j e f d     YZ d e	 j e f d     YZ d e	 j e f d      YZ d! e	 j e f d"     YZ  d# e	 j e f d$     YZ! d% e	 j e f d&     YZ" d' e	 j e f d(     YZ# d)   Z$ e% d* k rd d l& Z& e	 j' e& j(  e	 j)   e j* d+ d,  n  d S(-   s3   Test module for compatibility with plain HDF files.i    (   t   absolute_importN(   t   common(   t   allequal(   t   unittestt   test_filename(   t   PyTablesTestCase(   t   ranget   EnumTestCasec           B@  s#   e  Z d  Z e d  Z d   Z RS(   sj   Test for enumerated datatype.

    See ftp://ftp.hdfgroup.org/HDF5/current/src/unpacked/test/enum.c.

    s   smpl_enum.h5c         C@  sά   |  j  d |  j k  |  j j d  } |  j  t | t j   | j   } t j d d d d d g  } |  j | |  t	 | j
    } g  d d d d d d d d d d g
 D] } | | ^ q² } |  j | |  d  S(   Ns	   /EnumTestt   REDt   GREENt   BLUEt   WHITEt   BLACK(   t
   assertTruet   h5filet   get_nodet
   isinstancet   tablest   Arrayt   get_enumt   Enumt   assertEqualt   listt   read(   t   selft   arrt   enumt   expectedEnumt   datat   namet   expectedData(    (    s;   lib/python2.7/site-packages/tables/tests/test_hdf5compat.pyt   test(   s    )(   t   __name__t
   __module__t   __doc__R   t   h5fnameR   (    (    (    s;   lib/python2.7/site-packages/tables/tests/test_hdf5compat.pyR      s   t   NumericTestCasec           B@  s   e  Z d  Z d   Z RS(   s­   Test for several numeric datatypes.

    See
    ftp://ftp.ncsa.uiuc.edu/HDF/files/hdf5/samples/[fiu]l?{8,16,32,64}{be,le}.c
    (they seem to be no longer available).

    c         C@  s0  |  j  d |  j k  |  j j d  } |  j  t | t j   |  j | j j |  j  |  j | j	 |  j	  |  j | j
 d  | j   } t j d d d d d g d d d d d g d d d d d g d d d d d	 g d d d d	 d
 g d d d	 d
 d g g d |  j } |  j  t j | |   d  S(   Ns
   /TestArrayi   i   i    i   i   i   i   i   i   i	   t   dtype(   i   i   (   R   R   R   R   R   R   R   t   atomt   typet	   byteordert   shapeR   t   numpyt   arrayR   t   areArraysEqual(   R   R   R   R   (    (    s;   lib/python2.7/site-packages/tables/tests/test_hdf5compat.pyR   C   s    $(   R    R!   R"   R   (    (    (    s;   lib/python2.7/site-packages/tables/tests/test_hdf5compat.pyR$   :   s   t   F64BETestCasec           B@  s    e  Z e d   Z d Z d Z RS(   s   smpl_f64be.h5t   float64t   big(   R    R!   R   R#   R'   R(   (    (    (    s;   lib/python2.7/site-packages/tables/tests/test_hdf5compat.pyR-   X   s   t   F64LETestCasec           B@  s    e  Z e d   Z d Z d Z RS(   s   smpl_f64le.h5R.   t   little(   R    R!   R   R#   R'   R(   (    (    (    s;   lib/python2.7/site-packages/tables/tests/test_hdf5compat.pyR0   ^   s   t   I64BETestCasec           B@  s    e  Z e d   Z d Z d Z RS(   s   smpl_i64be.h5t   int64R/   (   R    R!   R   R#   R'   R(   (    (    (    s;   lib/python2.7/site-packages/tables/tests/test_hdf5compat.pyR2   d   s   t   I64LETestCasec           B@  s    e  Z e d   Z d Z d Z RS(   s   smpl_i64le.h5R3   R1   (   R    R!   R   R#   R'   R(   (    (    (    s;   lib/python2.7/site-packages/tables/tests/test_hdf5compat.pyR4   j   s   t   I32BETestCasec           B@  s    e  Z e d   Z d Z d Z RS(   s   smpl_i32be.h5t   int32R/   (   R    R!   R   R#   R'   R(   (    (    (    s;   lib/python2.7/site-packages/tables/tests/test_hdf5compat.pyR5   p   s   t   I32LETestCasec           B@  s    e  Z e d   Z d Z d Z RS(   s   smpl_i32le.h5R6   R1   (   R    R!   R   R#   R'   R(   (    (    (    s;   lib/python2.7/site-packages/tables/tests/test_hdf5compat.pyR7   v   s   t   ChunkedCompoundTestCasec           B@  s#   e  Z d  Z e d  Z d   Z RS(   s»   Test for a more complex and chunked compound structure.

    This is generated by a chunked version of the example in
    ftp://ftp.ncsa.uiuc.edu/HDF/files/hdf5/samples/compound2.c.

    s   smpl_compound_chunked.h5c         C@  s¨  |  j  d |  j k  |  j j d  } |  j  t | t j   |  j | j d d d d d d g  |  j | j d d  |  j | j	 d j
 d  |  j | j d d	  |  j | j	 d j
 d  |  j | j d d
  |  j | j	 d j
 d  |  j | j d d  |  j | j	 d j
 d  |  j | j d d  |  j | j	 d j
 d  |  j | j d d  |  j | j	 d j
 d  xt t |   D]} | | } |  j | d |  |  j | d d  | d } xK t d  D]= } x4 t d  D]& } |  j | | | | | |  qWqξW|  j | d | d d d | d } x, t d  D] } |  j | | | d  qdW|  j | d t d   qWd  S(   Ns   /CompoundChunkedt   a_namet   c_namet   d_namet   e_namet   f_namet   g_nameR6   t   stringt   int16i   i
   t   float32R.   t   uint8s   Hello!gΈλQΈξ?t   placesi   g<,ΤΪ@t   m(    (    (   i   i
   (    (   i
   (    (   R   R   R   R   R   t   TableR   t   colnamest   coltypest	   coldtypesR)   R   t   lent   assertAlmostEqualt   ord(   R   t   tblRD   t   rowt   dRowt   nt   ot   fRow(    (    s;   lib/python2.7/site-packages/tables/tests/test_hdf5compat.pyR      s>    

(
(   R    R!   R"   R   R#   R   (    (    (    s;   lib/python2.7/site-packages/tables/tests/test_hdf5compat.pyR8   |   s   t   ContiguousCompoundTestCasec           B@  s#   e  Z d  Z e d  Z d   Z RS(   sp   Test for support of native contiguous compound datasets.

    This example has been provided by Dav Clark.

    s   non-chunked-table.h5c         C@  s·  |  j  d |  j k  |  j j d  } |  j  t | t j   |  j | j d d d d g  |  j | j d d  |  j | j	 d j
 d  |  j | j d d  |  j | j	 d j
 d  |  j | j d d  |  j | j	 d j
 d  |  j | j d d  |  j | j	 d j
 d  x | j   D]q } |  j | d d	  |  j | d d
  |  j  t | d t j d d	 g d d   |  j | d d  q1W|  j j   d  S(   Ns   /test_var/structure variablet   at   bt   ct   dR.   i   R?   g      @g      @g       @R%   (    (    (   i   (    (   R   R   R   R   R   RE   R   RF   RG   RH   R)   t   iterrowsR   R*   R+   t   close(   R   RL   RM   (    (    s;   lib/python2.7/site-packages/tables/tests/test_hdf5compat.pyR   Ό   s*    "(   R    R!   R"   R   R#   R   (    (    (    s;   lib/python2.7/site-packages/tables/tests/test_hdf5compat.pyRR   ³   s   t    ContiguousCompoundAppendTestCasec           B@  s#   e  Z d  Z e d  Z d   Z RS(   s?   Test for appending data to native contiguous compound datasets.s   non-chunked-table.h5c         C@  sκ   |  j  d |  j k  |  j j   t j d  } t j |  j |  y t j	 | d  |  _ Wn t
 k
 rr d  SX|  j j d  } |  j t j | j d d d d g d f g  |  j t j | j j  |  j j   t j |  d  S(	   Ns   /test_var/structure variables   .h5RS   g      @g      @g       @g      @RV   (   R   R   RX   t   tempfilet   mktempt   shutilt   copyR#   R   t	   open_filet   IOErrorR   t   assertRaisest   HDF5ExtErrort   appendRM   t   ost   remove(   R   t   h5fname_copyRL   (    (    s;   lib/python2.7/site-packages/tables/tests/test_hdf5compat.pyR   α   s    (   R    R!   R"   R   R#   R   (    (    (    s;   lib/python2.7/site-packages/tables/tests/test_hdf5compat.pyRY   ά   s   t   ExtendibleTestCasec           B@  s#   e  Z d  Z e d  Z d   Z RS(   s^   Test for extendible datasets.

    See the example programs in the Introduction to HDF5.

    s   smpl_SDSextendible.h5c         C@  s  |  j  d |  j k  |  j j d  } |  j  t | t j   |  j | j d  |  j | j j	 d  |  j | j
 d  |  j | j d  |  j t |  d  | j   } t j d d d d d g d d d d d g d d d d d g d	 d d d d g d	 d d d d g d	 d d d d g d	 d d d d g d	 d d d d g d	 d d d d g d	 d d d d g g
 d
 | j j	 } |  j  t j | |   d  S(   Ns   /ExtendibleArrayR/   R6   i
   i   i    i   i   i   R%   (   i
   i   (   R   R   R   R   R   t   EArrayR   R(   R&   R'   R)   t   extdimRI   R   R*   R+   R   R,   (   R   R   R   R   (    (    s;   lib/python2.7/site-packages/tables/tests/test_hdf5compat.pyR     s*    '(   R    R!   R"   R   R#   R   (    (    (    s;   lib/python2.7/site-packages/tables/tests/test_hdf5compat.pyRf   ψ   s   t   SzipTestCasec           B@  s#   e  Z d  Z e d  Z d   Z RS(   s>   Test for native HDF5 files with datasets compressed with szip.s   test_szip.h5c         C@  sK   |  j  d |  j k  |  j j d  } d } |  j t | j  |  d  S(   Ns
   /dset_szipsh   Filters(complib='szip', shuffle=False, bitshuffle=False, fletcher32=False, least_significant_digit=None)(   R   R   R   R   t   reprt   filters(   R   R   Rk   (    (    s;   lib/python2.7/site-packages/tables/tests/test_hdf5compat.pyR   "  s    (   R    R!   R"   R   R#   R   (    (    (    s;   lib/python2.7/site-packages/tables/tests/test_hdf5compat.pyRi     s   t   MatlabFileTestCasec           B@  s/   e  Z e d   Z d   Z d   Z d   Z RS(   s   matlab_file.matc         C@  s>   |  j  j t j d  t j d   } |  j | j d  d  S(   Nt   /RS   i   i   (   i   i   (   R   R   t   sixt	   text_typeR   R)   (   R   R+   (    (    s;   lib/python2.7/site-packages/tables/tests/test_hdf5compat.pyt   test_unicode/  s    'c         C@  s,   |  j  j d d  } |  j | j d  d  S(   NRm   RS   i   i   (   i   i   (   R   R   R   R)   (   R   R+   (    (    s;   lib/python2.7/site-packages/tables/tests/test_hdf5compat.pyt   test_string4  s    c         C@  s>   |  j  j t j d  t j d   } |  j | j d  d  S(   NRm   RS   i   i   (   i   i   (   R   R   R*   t   str_R   R)   (   R   R+   (    (    s;   lib/python2.7/site-packages/tables/tests/test_hdf5compat.pyt   test_numpy_str8  s    '(   R    R!   R   R#   Rp   Rq   Rs   (    (    (    s;   lib/python2.7/site-packages/tables/tests/test_hdf5compat.pyRl   ,  s   		t   ObjectReferenceTestCasec           B@  s&   e  Z e d   Z d   Z d   Z RS(   s   test_ref_array1.matc         C@  s)   |  j  j d  } |  j | j d  d  S(   Ns   /ANN/my_arri   i   (   i   i   (   R   R   R   R)   (   R   R+   (    (    s;   lib/python2.7/site-packages/tables/tests/test_hdf5compat.pyt   test_node_var@  s    c         C@  sS   |  j  j d  } |  j t j | d d d t j d d g d t j   d  S(   Ns   /ANN/my_arri    R%   (   R   R   R   R   R,   R*   R+   t   uint64(   R   R+   (    (    s;   lib/python2.7/site-packages/tables/tests/test_hdf5compat.pyt   test_ref_utf_strD  s
    (   R    R!   R   R#   Ru   Rw   (    (    (    s;   lib/python2.7/site-packages/tables/tests/test_hdf5compat.pyRt   =  s   	t    ObjectReferenceRecursiveTestCasec           B@  s/   e  Z e d   Z d   Z d   Z d   Z RS(   s   test_ref_array2.matc         C@  s)   |  j  j d  } |  j | j d  d  S(   Ns   /vari   i   (   i   i   (   R   R   R   R)   (   R   R+   (    (    s;   lib/python2.7/site-packages/tables/tests/test_hdf5compat.pyt   test_varP  s    c         C@  se   |  j  j d  } |  j t j | d d d t j d g d g d g d g g d t j   d  S(   Ns   /vari   i    it   ie   is   R%   (   R   R   R   R   R,   R*   R+   t   uint16(   R   R+   (    (    s;   lib/python2.7/site-packages/tables/tests/test_hdf5compat.pyt   test_ref_strT  s
    $c      
   C@  sy   |  j  j d  } |  j t j | d d d d d t j d g d g d g d g d g d	 g g d
 t j   d  S(   Ns   /vari   i    i   ii   in   is   id   ie   R%   (   R   R   R   R   R,   R*   R+   Rz   (   R   R+   (    (    s;   lib/python2.7/site-packages/tables/tests/test_hdf5compat.pyt   test_double_ref\  s
    0(   R    R!   R   R#   Ry   R{   R|   (    (    (    s;   lib/python2.7/site-packages/tables/tests/test_hdf5compat.pyRx   M  s   		c          C@  sw  t  j   }  d } x^t |  D]P} |  j t  j t   |  j t  j t   |  j t  j t   |  j t  j t   |  j t  j t	   |  j t  j t
   |  j t  j t   |  j t  j t   |  j t  j t   |  j t  j t   |  j t  j t   |  j t  j t   |  j t  j t   |  j t  j t   |  j t  j t   q W|  S(   sC   Return a test suite consisting of all the test cases in the module.i   (   R   t	   TestSuiteR   t   addTestt	   makeSuiteR   R-   R0   R2   R4   R5   R7   R8   RR   RY   Rf   Ri   Rl   Rt   Rx   (   t   theSuitet   nitert   i(    (    s;   lib/python2.7/site-packages/tables/tests/test_hdf5compat.pyt   suited  s&    t   __main__t   defaultTestR   (+   R"   t
   __future__R    Rc   R\   RZ   R*   R   t   tables.testsR   t   tables.tests.commonR   R   R   R   t   TestCaseRn   t	   six.movesR   t   TestFileMixinR   R$   R-   R0   R2   R4   R5   R7   R8   RR   RY   Rf   Ri   Rl   Rt   Rx   R   R    t   syst
   parse_argvt   argvt   print_versionst   main(    (    (    s;   lib/python2.7/site-packages/tables/tests/test_hdf5compat.pyt   <module>   sD   7)%	
