[h5py] 76/455: Unit tests improved, misc bug fixes

Ghislain Vaillant ghisvail-guest at moszumanska.debian.org
Thu Jul 2 18:19:19 UTC 2015


This is an automated email from the git hooks/post-receive script.

ghisvail-guest pushed a commit to annotated tag 1.3.0
in repository h5py.

commit 110ab50f10a93987a6abc4d289c69bda050dbb25
Author: andrewcollette <andrew.collette at gmail.com>
Date:   Tue Jul 15 03:26:05 2008 +0000

    Unit tests improved, misc bug fixes
---
 h5py/h5d.pyx           |  4 ++-
 h5py/h5t.pyx           |  2 +-
 h5py/tests/common.py   | 46 ++++++++++++-------------
 h5py/tests/test_h5a.py | 69 ++++++++++++++++++-------------------
 h5py/tests/test_h5d.py | 65 ++++++++++++++++++++++++-----------
 h5py/tests/test_h5f.py | 28 +++++++--------
 h5py/tests/test_h5g.py | 92 ++++++++++++++++++++++----------------------------
 h5py/tests/test_h5i.py | 18 +++++-----
 h5py/tests/test_h5p.py |  7 ++--
 h5py/tests/test_h5s.py |  4 +--
 h5py/tests/test_h5t.py | 85 ++++++++++++++++++++++++++++++++++++++++++++--
 setup.py               |  2 +-
 12 files changed, 255 insertions(+), 167 deletions(-)

diff --git a/h5py/h5d.pyx b/h5py/h5d.pyx
index cb1e31f..5112ec3 100644
--- a/h5py/h5d.pyx
+++ b/h5py/h5d.pyx
@@ -20,6 +20,7 @@ from h5s cimport H5S_ALL, H5S_UNLIMITED, H5S_SCALAR, H5S_SIMPLE, \
                     H5Sget_simple_extent_ndims, H5Sget_select_npoints
 from numpy cimport import_array, PyArray_DATA
 from utils cimport  check_numpy_read, check_numpy_write, \
+                    require_tuple, \
                     convert_tuple, \
                     emalloc, efree
 
@@ -244,7 +245,8 @@ cdef class DatasetID(ObjectID):
     def get_offset(self):
         """ () => LONG offset
 
-            Get the offset of this dataset in the file, in bytes.
+            Get the offset of this dataset in the file, in bytes, or -1 if
+            it can't be determined.
         """
         return H5Dget_offset(self.id)
 
diff --git a/h5py/h5t.pyx b/h5py/h5t.pyx
index 6112a42..01a5172 100644
--- a/h5py/h5t.pyx
+++ b/h5py/h5t.pyx
@@ -992,7 +992,7 @@ cdef class TypeEnumID(TypeCompositeID):
         cdef long long val
         ptype = 0
 
-        if index < 0:
+        if idx < 0:
             raise ValueError("Index must be non-negative.")
 
         H5Tget_member_value(self.id, idx, &val)
diff --git a/h5py/tests/common.py b/h5py/tests/common.py
index bcb3192..8aafcab 100644
--- a/h5py/tests/common.py
+++ b/h5py/tests/common.py
@@ -10,43 +10,39 @@
 # 
 #-
 
+import unittest
 import tempfile
 import os
+from os.path import join, dirname
 import shutil
 from h5py import h5f, h5p
+import h5py
 
-class HCopy(object):
+DATADIR = join(dirname(h5py.__file__), 'tests/data')
 
-    """
-        Use:
-
-        from __future__ import with_statement
+class TestBase(unittest.TestCase):
 
-        with HCopy(filename) as fid:
-            fid.frob()
-            obj = h5g.open(fid, whatever)
-            ...
     """
-    def __init__(self, filename):
-        self.filename = filename
-        self.tmpname = None
+        Base test for unit test classes which deal with a particular
+        HDF5 file.  These should declare a class-level attribute HDFNAME
+        representing the appropriate file.  This should be a basename; the
+        TestBase class will figure out the correct directory.
+    """
 
-    def __enter__(self):
-        self.tmpname = tempfile.mktemp('.hdf5')
-        shutil.copy(self.filename, self.tmpname)
+    def __init__(self, *args, **kwds):
+        unittest.TestCase.__init__(self, *args, **kwds)
+        self.HDFNAME = join(DATADIR, self.HDFNAME) # resolve absolute location
+
+    def setUp(self):
+        newname = tempfile.mktemp('.hdf5')
+        shutil.copy(self.HDFNAME, newname)
 
         plist = h5p.create(h5p.FILE_ACCESS)
         plist.set_fclose_degree(h5f.CLOSE_STRONG)
-        self.fid = h5f.open(self.tmpname, h5f.ACC_RDWR)
-        return self.fid
+        self.fid = h5f.open(newname, h5f.ACC_RDWR, accesslist=plist)
+        self.fname = newname
 
-    def __exit__(self, *args):
+    def tearDown(self):
         self.fid.close()
-        os.unlink(self.tmpname)
-
-def errstr(arg1, arg2, msg=''):
-    """ Used to mimic assertEqual-style auto-repr, where assertEqual doesn't
-        work (i.e. for Numpy arrays where all() must be used)
-    """
-    return msg+'%s != %s' % (repr(arg1), repr(arg2))
+        os.unlink(self.fname)
 
diff --git a/h5py/tests/test_h5a.py b/h5py/tests/test_h5a.py
index 94df76e..3dfc919 100644
--- a/h5py/tests/test_h5a.py
+++ b/h5py/tests/test_h5a.py
@@ -9,20 +9,17 @@
 # $Date$
 # 
 #-
-from __future__ import with_statement
 
-import unittest
 from numpy import array, ndarray, dtype, all, ones
-import os
 
-from common import HCopy, errstr
+from common import TestBase
 
-import h5py
-from h5py import h5, h5a, h5f, h5g, h5i, h5t, h5s
+from h5py import *
 from h5py.h5 import H5Error
 
+# === attributes.hdf5 description ===
 
-HDFNAME = os.path.join(os.path.dirname(h5py.__file__), 'tests/data/attributes.hdf5')
+HDFNAME = 'attributes.hdf5'
 OBJECTNAME = 'Group'
 ATTRIBUTES = {  'String Attribute': ("This is a string.", dtype('S18'), ()),
                 'Integer': (42, dtype('<i4'), ()),
@@ -31,15 +28,17 @@ ATTRIBUTES = {  'String Attribute': ("This is a string.", dtype('S18'), ()),
 ATTRIBUTES_ORDER = ['String Attribute', 'Integer', 'Integer Array', 'Byte']
 NEW_ATTRIBUTES = {'New float': ( 3.14, dtype('<f4'), ()) }
 
-class TestH5A(unittest.TestCase):
+class TestH5A(TestBase):
+
+    HDFNAME = HDFNAME
 
     def setUp(self):
-        self.fid = h5f.open(HDFNAME, h5f.ACC_RDONLY)
+        TestBase.setUp(self)
         self.obj = h5g.open(self.fid, OBJECTNAME)
 
     def tearDown(self):
         self.obj._close()
-        self.fid.close()
+        TestBase.tearDown(self)
 
     def is_attr(self, attr):
         return (h5i.get_type(attr) == h5i.ATTR)
@@ -48,26 +47,25 @@ class TestH5A(unittest.TestCase):
 
     def test_create_write(self):
 
-        with HCopy(HDFNAME) as fid:
-            obj = h5g.open(fid, OBJECTNAME)
-            for name, (value, dt, shape) in NEW_ATTRIBUTES.iteritems():
-                arr_ref = array(value, dtype=dt)
-                arr_fail = ones((15,15), dtype=dt)
+        obj = h5g.open(self.fid, OBJECTNAME)
+        for name, (value, dt, shape) in NEW_ATTRIBUTES.iteritems():
+            arr_ref = array(value, dtype=dt)
+            arr_fail = ones((15,15), dtype=dt)
 
-                space = h5s.create(h5s.SCALAR)
-                htype = h5t.py_create(dt)
+            space = h5s.create(h5s.SCALAR)
+            htype = h5t.py_create(dt)
 
-                attr = h5a.create(obj, name, htype, space)
-                self.assert_(self.is_attr(attr))
-                attr.write(arr_ref)
-                self.assertRaises(ValueError, attr.write, arr_fail)
+            attr = h5a.create(obj, name, htype, space)
+            self.assert_(self.is_attr(attr))
+            attr.write(arr_ref)
+            self.assertRaises(ValueError, attr.write, arr_fail)
 
-                attr = h5a.open_name(obj, name)
-                dt = attr.dtype
-                shape = attr.shape
-                arr_val = ndarray(shape, dtype=dt)
-                attr.read(arr_val)
-                self.assert_(all(arr_val == arr_ref), errstr(arr_val, arr_ref))
+            attr = h5a.open_name(obj, name)
+            dt = attr.dtype
+            shape = attr.shape
+            arr_val = ndarray(shape, dtype=dt)
+            attr.read(arr_val)
+            self.assert_(all(arr_val == arr_ref))
 
     def test_open_idx(self):
         for idx, name in enumerate(ATTRIBUTES_ORDER):
@@ -86,15 +84,15 @@ class TestH5A(unittest.TestCase):
         self.assert_(not self.is_attr(attr))
 
     def test_delete(self):
-        with HCopy(HDFNAME) as fid:
-            obj = h5g.open(fid, OBJECTNAME)
 
-            attr = h5a.open_name(obj, ATTRIBUTES_ORDER[0])
-            self.assert_(self.is_attr(attr))
-            del attr
+        obj = h5g.open(self.fid, OBJECTNAME)
+
+        attr = h5a.open_name(obj, ATTRIBUTES_ORDER[0])
+        self.assert_(self.is_attr(attr))
+        del attr
 
-            h5a.delete(obj, ATTRIBUTES_ORDER[0])
-            self.assertRaises(H5Error, h5a.open_name, obj, ATTRIBUTES_ORDER[0])
+        h5a.delete(obj, ATTRIBUTES_ORDER[0])
+        self.assertRaises(H5Error, h5a.open_name, obj, ATTRIBUTES_ORDER[0])
 
 
     # === Attribute I/O =======================================================
@@ -111,8 +109,7 @@ class TestH5A(unittest.TestCase):
             self.assertEqual(attr.dtype, dt)
 
             attr.read(arr_holder)
-            self.assert_( all(arr_holder == arr_reference),
-                errstr(arr_reference, arr_holder, 'Attr "%s"):\n' % name, ))
+            self.assert_( all(arr_holder == arr_reference) )
 
     # write is done by test_create_write
 
diff --git a/h5py/tests/test_h5d.py b/h5py/tests/test_h5d.py
index 96b721f..54c977f 100644
--- a/h5py/tests/test_h5d.py
+++ b/h5py/tests/test_h5d.py
@@ -9,18 +9,14 @@
 # $Date$
 # 
 #-
-from __future__ import with_statement
 
-import unittest
-import os
 import numpy
-from common import HCopy
+from common import TestBase
 
-import h5py
-from h5py import h5f, h5d, h5i, h5s, h5t, h5p
+from h5py import *
 from h5py.h5 import H5Error
 
-HDFNAME = os.path.join(os.path.dirname(h5py.__file__), 'tests/data/smpl_compound_chunked.hdf5')
+HDFNAME = 'smpl_compound_chunked.hdf5'
 DTYPE = numpy.dtype([('a_name','>i4'),
                      ('c_name','|S6'),
                      ('d_name', numpy.dtype( ('>i2', (5,10)) )),
@@ -38,22 +34,23 @@ for i in range(SHAPE[0]):
     basearray[i]["f_name"][:] = numpy.array((1024.9637*i,)*10)
     basearray[i]["g_name"] = 109
 
-class TestH5D(unittest.TestCase):
+class TestH5D(TestBase):
+
+    HDFNAME = HDFNAME
 
     def setUp(self):
-        self.fid = h5f.open(HDFNAME, h5f.ACC_RDONLY)
+        TestBase.setUp(self)
         self.dset = h5d.open(self.fid, "CompoundChunked")
 
     def tearDown(self):
         self.dset._close()
-        self.fid.close()
+        TestBase.tearDown(self)
 
     def test_open_close(self):
-        with HCopy(HDFNAME) as fid:
-            dset = h5d.open(fid, "CompoundChunked")
-            self.assertEqual(h5i.get_type(dset), h5i.DATASET)
-            dset._close()
-            self.assertEqual(h5i.get_type(dset), h5i.BADID)
+        dset = h5d.open(self.fid, "CompoundChunked")
+        self.assertEqual(h5i.get_type(dset), h5i.DATASET)
+        dset._close()
+        self.assertEqual(h5i.get_type(dset), h5i.BADID)
 
     def test_read(self):
         array = numpy.ndarray(SHAPE, dtype=DTYPE)
@@ -62,6 +59,18 @@ class TestH5D(unittest.TestCase):
         for name in DTYPE.fields:
             self.assert_(numpy.all(array[name] == basearray[name]), "%s::\n%s\n!=\n%s" % (name, array[name], basearray[name]))
 
+    def test_write(self):
+        root = h5g.open(self.fid, '/')
+        dt = numpy.dtype('<i4')
+        space = h5s.create_simple((10,20))
+        htype = h5t.py_create(dt)
+        arr = 5*numpy.ones((10,20),dtype=dt)
+        dset = h5d.create(root, 'NewDataset', htype, space)
+        dset.write(h5s.ALL, h5s.ALL, arr)
+        arr2 = numpy.ndarray((10,20), dtype=dt)
+        dset.read(h5s.ALL, h5s.ALL, arr2)
+        self.assert_((arr == arr2).all())
+
     def test_get_space(self):
         space = self.dset.get_space()
         self.assertEqual(space.get_simple_extent_dims(), SHAPE)
@@ -70,10 +79,28 @@ class TestH5D(unittest.TestCase):
         status = self.dset.get_space_status()
         self.assert_(status > 0)
 
-    # Chunked datasets have no offset.  New test dset needed.
-    #
-    #def test_get_offset(self):
-    #    pass
+    def test_create_offset(self):
+        root = h5g.open(self.fid, '/')
+        space = h5s.create_simple((10,20))
+        htype = h5t.STD_I32LE
+        dset = h5d.create(root, 'NewDataset', htype, space)
+        del dset
+        dset = h5d.open(root, 'NewDataset')
+        self.assertEqual(dset.dtype, htype.dtype)
+        self.assertEqual(dset.shape, space.shape)
+        dset.get_offset()
+        self.dset.get_offset()
+
+    def test_extend(self):
+        plist = h5p.create(h5p.DATASET_CREATE)
+        plist.set_chunk((1,20))
+        root = h5g.open(self.fid, '/')
+        space = h5s.create_simple((10,20),(15,20))
+        htype = h5t.STD_I32LE
+        dset = h5d.create(root, 'NewDataset', htype, space, plist=plist)
+        self.assertEqual(dset.shape, (10,20))
+        dset.extend((15,20))
+        self.assertEqual(dset.shape, (15,20))
 
     def test_get_storage_size(self):
         self.assert_(self.dset.get_storage_size() >= 0)
diff --git a/h5py/tests/test_h5f.py b/h5py/tests/test_h5f.py
index cb2d1c4..800c7a8 100644
--- a/h5py/tests/test_h5f.py
+++ b/h5py/tests/test_h5f.py
@@ -10,26 +10,22 @@
 # 
 #-
 
-import unittest
-import tempfile
+import numpy
 import os
+import tempfile
+from common import TestBase
 
-import h5py
-from h5py import h5f, h5i, h5p
+from h5py import *
 from h5py.h5 import H5Error
 
-HDFNAME = os.path.join(os.path.dirname(h5py.__file__), 'tests/data/attributes.hdf5')
-
-class TestH5F(unittest.TestCase):
+HDFNAME = 'attributes.hdf5'
 
-    def setUp(self):
-        self.fid = h5f.open(HDFNAME, h5f.ACC_RDONLY)
+class TestH5F(TestBase):
 
-    def tearDown(self):
-        self.fid.close()
+    HDFNAME = HDFNAME
 
     def test_open_close(self):
-        fid = h5f.open(HDFNAME, h5f.ACC_RDONLY)
+        fid = h5f.open(self.HDFNAME, h5f.ACC_RDONLY)
         self.assertEqual(h5i.get_type(fid), h5i.FILE)
         fid.close()
         self.assertEqual(h5i.get_type(fid), h5i.BADID)
@@ -63,10 +59,10 @@ class TestH5F(unittest.TestCase):
             except OSError:
                 pass
 
-        self.assert_(h5f.is_hdf5(HDFNAME))
+        self.assert_(h5f.is_hdf5(self.fname))
 
     def test_get_filesize(self):
-        self.assertEqual(self.fid.get_filesize(), os.stat(HDFNAME).st_size)
+        self.assertEqual(self.fid.get_filesize(), os.stat(self.fname).st_size)
 
     def test_get_create_plist(self):
         cplist = self.fid.get_create_plist()
@@ -80,7 +76,7 @@ class TestH5F(unittest.TestCase):
         self.assert_(self.fid.get_freespace() >= 0)
 
     def test_get_name(self):
-        self.assertEqual(h5f.get_name(self.fid), HDFNAME)
+        self.assertEqual(h5f.get_name(self.fid), self.fname)
 
     def test_get_obj_count(self):
         self.assert_(h5f.get_obj_count(self.fid, h5f.OBJ_ALL) >= 0)
@@ -92,7 +88,7 @@ class TestH5F(unittest.TestCase):
         self.assertRaises(H5Error, h5f.get_obj_ids, -1, h5f.OBJ_ALL)
 
     def test_py(self):
-        self.assertEqual(self.fid.name, HDFNAME)
+        self.assertEqual(self.fid.name, self.fname)
 
 
 
diff --git a/h5py/tests/test_h5g.py b/h5py/tests/test_h5g.py
index 1f3f6fc..7510f79 100644
--- a/h5py/tests/test_h5g.py
+++ b/h5py/tests/test_h5g.py
@@ -9,32 +9,28 @@
 # $Date$
 # 
 #-
-from __future__ import with_statement
 
-import unittest
-import tempfile
-import os
+from common import TestBase
 
-import h5py
-from h5py import h5f, h5g, h5i
+from h5py import *
 from h5py.h5 import H5Error
 
-from common import HCopy
-
-HDFNAME = os.path.join(os.path.dirname(h5py.__file__), 'tests/data/attributes.hdf5')
+HDFNAME = 'attributes.hdf5'
 OBJECTNAME = 'Group'
 TEST_GROUPS = ['Subgroup1','Subgroup2','Subgroup3']
 NEW_LINK_NAME = 'Link name'
 
-class TestH5G(unittest.TestCase):
+class TestH5G(TestBase):
+
+    HDFNAME = HDFNAME
 
     def setUp(self):
-        self.fid = h5f.open(HDFNAME, h5f.ACC_RDONLY)
+        TestBase.setUp(self)
         self.obj = h5g.open(self.fid, OBJECTNAME)
 
     def tearDown(self):
         self.obj._close()
-        self.fid.close()
+        TestBase.tearDown(self)
 
     def is_grp(self, item):
         return h5i.get_type(item) == h5i.GROUP
@@ -50,49 +46,45 @@ class TestH5G(unittest.TestCase):
 
     def test_create(self):
 
-        with HCopy(HDFNAME) as fid:
-
-            obj = h5g.open(fid, OBJECTNAME)
-            grp = h5g.create(obj, 'New group')
-            grp._close()
-            self.assert_('New group' in obj)
-
-    def test_link_unlink_move_linkval(self):
+        obj = h5g.open(self.fid, OBJECTNAME)
+        grp = h5g.create(obj, 'New group')
+        grp._close()
+        self.assert_('New group' in obj)
 
-        with HCopy(HDFNAME) as fid:
+    def test_link_A(self):
 
-            obj = h5g.open(fid, OBJECTNAME)
+        obj = h5g.open(self.fid, OBJECTNAME)
 
-            # symlink
-            obj.link(TEST_GROUPS[1], NEW_LINK_NAME, h5g.LINK_SOFT)
-            self.assertEqual(obj.get_objinfo(NEW_LINK_NAME, follow_link=False).type, h5g.LINK)
-            self.assertEqual(obj.get_linkval(NEW_LINK_NAME), TEST_GROUPS[1])
+        # symlink
+        obj.link(TEST_GROUPS[1], NEW_LINK_NAME, h5g.LINK_SOFT)
+        self.assertEqual(obj.get_objinfo(NEW_LINK_NAME, follow_link=False).type, h5g.LINK)
+        self.assertEqual(obj.get_linkval(NEW_LINK_NAME), TEST_GROUPS[1])
 
-        with HCopy(HDFNAME) as fid:
+    def test_link_B(self):
 
-            obj = h5g.open(fid, OBJECTNAME)
+        obj = h5g.open(self.fid, OBJECTNAME)
 
-            # local link
-            obj.link(TEST_GROUPS[1], NEW_LINK_NAME, h5g.LINK_HARD)
-            self.assert_( NEW_LINK_NAME in obj )
+        # local link
+        obj.link(TEST_GROUPS[1], NEW_LINK_NAME, h5g.LINK_HARD)
+        self.assert_( NEW_LINK_NAME in obj )
 
-            # test local unlink
-            obj.unlink(NEW_LINK_NAME)
-            self.assert_(not NEW_LINK_NAME in obj)
+        # test local unlink
+        obj.unlink(NEW_LINK_NAME)
+        self.assert_(not NEW_LINK_NAME in obj)
 
-            # remote link
-            rgrp = h5g.open(obj, TEST_GROUPS[0])
-            obj.link(TEST_GROUPS[0], NEW_LINK_NAME, h5g.LINK_HARD, rgrp)
-            self.assert_( NEW_LINK_NAME in rgrp )
-        
-            # remote unlink
-            rgrp.unlink(NEW_LINK_NAME)
-            self.assert_( not NEW_LINK_NAME in rgrp )
+        # remote link
+        rgrp = h5g.open(obj, TEST_GROUPS[0])
+        obj.link(TEST_GROUPS[0], NEW_LINK_NAME, h5g.LINK_HARD, rgrp)
+        self.assert_( NEW_LINK_NAME in rgrp )
+    
+        # remote unlink
+        rgrp.unlink(NEW_LINK_NAME)
+        self.assert_( not NEW_LINK_NAME in rgrp )
 
-            # move
-            obj.move( TEST_GROUPS[2], NEW_LINK_NAME)
-            self.assert_(NEW_LINK_NAME in obj)
-            self.assert_(not TEST_GROUPS[2] in obj)
+        # move
+        obj.move( TEST_GROUPS[2], NEW_LINK_NAME)
+        self.assert_(NEW_LINK_NAME in obj)
+        self.assert_(not TEST_GROUPS[2] in obj)
 
 
     def test_get_num_objs(self):
@@ -150,12 +142,10 @@ class TestH5G(unittest.TestCase):
 
     def test_get_set_comment(self):
 
-        with HCopy(HDFNAME) as fid:
-
-            obj = h5g.open(fid, OBJECTNAME)
+        obj = h5g.open(self.fid, OBJECTNAME)
 
-            obj.set_comment(TEST_GROUPS[0], "This is a comment.")
-            self.assertEqual(obj.get_comment(TEST_GROUPS[0]), "This is a comment.")
+        obj.set_comment(TEST_GROUPS[0], "This is a comment.")
+        self.assertEqual(obj.get_comment(TEST_GROUPS[0]), "This is a comment.")
 
 
     def test_py_contains(self):
diff --git a/h5py/tests/test_h5i.py b/h5py/tests/test_h5i.py
index 0615384..418aebb 100644
--- a/h5py/tests/test_h5i.py
+++ b/h5py/tests/test_h5i.py
@@ -9,26 +9,26 @@
 # $Date$
 # 
 #-
-import unittest
-import os
 
-import h5py
-from h5py import h5f, h5g, h5i, h5t
+from common import TestBase
+
+from h5py import *
 from h5py.h5 import H5Error
 
-HDFNAME = os.path.join(os.path.dirname(h5py.__file__), 'tests/data/attributes.hdf5')
+HDFNAME = 'attributes.hdf5'
 OBJECTNAME = 'Group'
 
-class TestH5I(unittest.TestCase):
+class TestH5I(TestBase):
+
+    HDFNAME = HDFNAME
 
     def setUp(self):
-        self.fid = h5f.open(HDFNAME, h5f.ACC_RDONLY)
+        TestBase.setUp(self)
         self.obj = h5g.open(self.fid, OBJECTNAME)
 
     def tearDown(self):
         self.obj._close()
-        self.fid.close()
-
+        TestBase.tearDown(self)
 
     def test_get_type(self):
         self.assertEqual(h5i.get_type(self.fid), h5i.FILE)
diff --git a/h5py/tests/test_h5p.py b/h5py/tests/test_h5p.py
index 813756b..9e75d05 100644
--- a/h5py/tests/test_h5p.py
+++ b/h5py/tests/test_h5p.py
@@ -12,8 +12,11 @@
 
 import unittest
 
-import h5py
-from h5py import h5p, h5i
+from h5py import *
+from h5py.h5 import H5Error
+
+HDFNAME = 'attributes.hdf5'
 
 class TestH5P(unittest.TestCase):
     pass
+
diff --git a/h5py/tests/test_h5s.py b/h5py/tests/test_h5s.py
index 521f9b4..72c8d78 100644
--- a/h5py/tests/test_h5s.py
+++ b/h5py/tests/test_h5s.py
@@ -12,8 +12,7 @@
 
 import unittest
 
-import h5py
-from h5py import h5s, h5i
+from h5py import *
 from h5py.h5 import H5Error
 
 spaces = [(10,10), (1,1), (1,), ()]
@@ -21,7 +20,6 @@ max_spaces = [(10,10), (3,4), (h5s.UNLIMITED,), ()]
 
 class TestH5S(unittest.TestCase):
 
-
     def test_create_close(self):
         sid = h5s.create(h5s.SCALAR)
         self.assertEqual(h5i.get_type(sid), h5i.DATASPACE)
diff --git a/h5py/tests/test_h5t.py b/h5py/tests/test_h5t.py
index 413b182..784e1ae 100644
--- a/h5py/tests/test_h5t.py
+++ b/h5py/tests/test_h5t.py
@@ -11,10 +11,11 @@
 #-
 
 import unittest
+import tempfile
+import os
 from numpy import dtype
 
-import h5py
-from h5py import h5t, h5i
+from h5py import *
 from h5py.h5 import H5Error
 
 kind_map = {'i': h5t.TypeIntegerID, 'u': h5t.TypeIntegerID, 'f': h5t.TypeFloatID,
@@ -45,6 +46,30 @@ class TestH5T(unittest.TestCase):
         
         self.assertRaises(ValueError, h5t.create, h5t.ARRAY, 4)
     
+    def test_open_commit_committed(self):
+        plist = h5p.create(h5p.FILE_ACCESS)
+        plist.set_fclose_degree(h5f.CLOSE_STRONG)
+        fname = tempfile.mktemp('.hdf5')
+        fid = h5f.create(fname, h5f.ACC_TRUNC, accesslist=plist)
+        try:
+            root = h5g.open(fid, '/')
+            htype = h5t.STD_I32LE.copy()
+            self.assert_(not htype.committed())
+            htype.commit(root, "NamedType")
+            self.assert_(htype.committed())
+            del htype
+            htype = h5t.open(root, "NamedType")
+            self.assert_(htype.equal(h5t.STD_I32LE))
+        finally:
+            fid.close()
+            os.unlink(fname)
+
+    def test_close(self):
+        htype = h5t.STD_I32LE.copy()
+        self.assert_(htype)
+        htype._close()
+        self.assert_(not htype)
+
     def test_copy(self):
 
         for x in simple_types:
@@ -120,7 +145,61 @@ class TestH5T(unittest.TestCase):
         self.assertEqual(htype.get_order(), h5t.ORDER_BE)
         self.assertEqual(htype.get_sign(), h5t.SGN_NONE)
 
-    
+    def test_setget_tag(self):
+        htype = h5t.create(h5t.OPAQUE, 40)
+        htype.set_tag("FOOBAR")
+        self.assertEqual(htype.get_tag(), "FOOBAR")
+        
+    def test_array(self):
+        htype = h5t.array_create(h5t.STD_I32LE,(4,5))
+        self.assertEqual(htype.get_array_ndims(), 2)
+        self.assertEqual(htype.get_array_dims(), (4,5))
+        self.assertEqual(htype.dtype, dtype(('<i4',(4,5))))
+
+    def test_enum(self):
+        names = ("A", "B", "Name3", "Name with space", " 12A-d878dd&%2 0-1!** ")
+        values = (1,2,3.0, -999, 30004.0)
+        valuedict = {}
+        htype = h5t.enum_create(h5t.STD_I32LE)
+
+        for idx, (name, value) in enumerate(zip(names, values)):
+            htype.enum_insert(name, value)
+            valuedict[name] = value
+            self.assertEqual(htype.get_member_value(idx), value)
+
+        for name, value in valuedict.iteritems():
+            self.assertEqual(htype.enum_valueof(name), value)
+            self.assertEqual(htype.enum_nameof(value), name)
+
+        self.assertEqual(htype.get_nmembers(), len(names))
+
+    def test_compound(self):
+        names = ("A", "B", "Name3", "Name with space", " 12A-d878dd&%2 0-1!** ")
+        types = (h5t.STD_I8LE, h5t.IEEE_F32BE, h5t.STD_U16BE, h5t.C_S1.copy(), h5t.FORTRAN_S1.copy())
+        types[3].set_size(8)
+        types[4].set_size(8)
+        classcodes = (h5t.INTEGER, h5t.FLOAT, h5t.INTEGER, h5t.STRING, h5t.STRING)
+        
+        # Align all on 128-bit (16-byte) boundaries
+        offsets = tuple(x*16 for x in xrange(len(names)))
+        total_len = 16*len(names)
+        htype = h5t.create(h5t.COMPOUND, total_len)
+
+        for idx, name in enumerate(names):
+            htype.insert(name, offsets[idx], types[idx])
+        
+        for idx, name in enumerate(names):
+            self.assertEqual(htype.get_member_name(idx), name)
+            self.assertEqual(htype.get_member_class(idx), classcodes[idx])
+            self.assertEqual(htype.get_member_index(name), idx)
+            self.assertEqual(htype.get_member_offset(idx), offsets[idx])
+            self.assert_(htype.get_member_type(idx).equal(types[idx]))
+
+        self.assertEqual(htype.get_size(), total_len)
+        htype.pack()
+        self.assert_(htype.get_size() < total_len)
+        self.assertEqual(htype.get_nmembers(), len(names))
+
     # === Tests for py_create =================================================
 
     def test_py_create_simple(self):
diff --git a/setup.py b/setup.py
index 192d344..b89f5c5 100644
--- a/setup.py
+++ b/setup.py
@@ -118,7 +118,7 @@ for arg in sys.argv[:]:
             API_VERS = (1,6)
         elif api == '18':
             API_VERS = (1,8)
-            warn('1.8.X API is only partially implemented')
+            warn('1.8.X API is still under development')
         else:
             fatal('Unrecognized API version "%s" (only "16", "18" currently allowed)' % api)
         sys.argv.remove(arg)

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/debian-science/packages/h5py.git



More information about the debian-science-commits mailing list