[h5py] 11/455: More tests, nasty bug in h5t, README

Ghislain Vaillant ghisvail-guest at moszumanska.debian.org
Thu Jul 2 18:19:12 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 b45b721d1eb27aea42d44ff95a64dc9b9a522aa8
Author: andrewcollette <andrew.collette at gmail.com>
Date:   Wed May 7 05:53:22 2008 +0000

    More tests, nasty bug in h5t, README
---
 README.txt                                 |   5 +-
 h5py/h5i.pyx                               |  14 +++-
 h5py/h5t.pyx                               |   3 +-
 h5py/tests/__init__.py                     |   5 +-
 h5py/tests/data/smpl_compound_chunked.hdf5 | Bin 0 -> 7768 bytes
 h5py/tests/test_h5d.py                     | 121 +++++++++++++++++++++++++++++
 h5py/tests/test_h5i.py                     |  40 ++++++++++
 7 files changed, 181 insertions(+), 7 deletions(-)

diff --git a/README.txt b/README.txt
index fe8533b..ee8d7d7 100755
--- a/README.txt
+++ b/README.txt
@@ -107,10 +107,13 @@ Requires
 --------
 - Unix-like environment (created/tested on 32-bit Intel linux)
 - Numpy_ 1.0.3 or higher
-- HDF5_ 1.6.5 or higher (1.8 is untested)
+- HDF5_ 1.6.5 or higher (1.8 support experimental)
 - Pyrex_ 0.9.6.4 or higher
 - gcc (to compile Python extensions)
 
+You might also need to install "libc6-dev" if it's not included by default
+with your OS.  If you get compile-time errors about "limits.h", this is why.
+
 .. _Numpy: http://numpy.scipy.org/
 .. _HDF5: http://hdf.ncsa.uiuc.edu/
 .. _Pyrex: http://www.cosc.canterbury.ac.nz/greg.ewing/python/Pyrex/
diff --git a/h5py/h5i.pyx b/h5py/h5i.pyx
index a4ff4d9..14efe4d 100755
--- a/h5py/h5i.pyx
+++ b/h5py/h5i.pyx
@@ -31,9 +31,14 @@ TYPE_DATASPACE = H5I_GROUP
 TYPE_DATASET = H5I_DATASET
 TYPE_ATTR = H5I_ATTR
 TYPE_REFERENCE = H5I_REFERENCE
+TYPE_GENPROP_CLS = H5I_GENPROP_CLS
+TYPE_GENPROP_LST = H5I_GENPROP_LST
+TYPE_DATATYPE = H5I_DATATYPE
+
 TYPE_MAPPER = { H5I_BADID: 'BAD ID', H5I_FILE: 'FILE', H5I_GROUP: 'GROUP',
                  H5I_DATASET: 'DATASET', H5I_ATTR: 'ATTRIBUTE', 
-                 H5I_REFERENCE: 'REFERENCE' }
+                 H5I_REFERENCE: 'REFERENCE', H5I_GENPROP_CLS: 'PROPERTY LIST CLASS',
+                 H5I_GENPROP_LST: 'PROPERTY LIST', H5I_DATATYPE: 'DATATYPE' }
 TYPE_MAPPER = DDict(TYPE_MAPPER)
 
 # === Introspection API =======================================================
@@ -53,15 +58,16 @@ def get_name(hid_t obj_id):
 
         Determine (a) name of an HDF5 object.  Because an object has as many
         names as there are hard links to it, this may not be unique.  If the
-        object does not have a name (transient datatypes, etc.), the 
-        return value is None.
+        object does not have a name (transient datatypes, etc.), OR IF THE
+        IDENTIFIER IS INVALID, the  return value is None.  Raises H5Error
+        if there is an internal error.
     """
     cdef size_t namelen
     cdef char* name
 
     namelen = H5Iget_name(obj_id, NULL, 0)
     if namelen < 0:
-        raise H5TypeError("Failed to determine name of object %d" % obj_id)
+        raise H5Error("Failed to determine name of object %d" % obj_id)
     if namelen == 0:
         return None
 
diff --git a/h5py/h5t.pyx b/h5py/h5t.pyx
index e6c5095..24494cc 100755
--- a/h5py/h5t.pyx
+++ b/h5py/h5t.pyx
@@ -818,7 +818,8 @@ def py_dtype_to_h5t(numpy.dtype dtype_in):
         # Otherwise it's just a compound type
         else:
             type_out = create(H5T_COMPOUND, length)
-            for name, (dt, offset) in dtype_in.fields.iteritems():
+            for name in dtype_in.names:
+                dt, offset = dtype_in.fields[name]
                 tmp = py_dtype_to_h5t(dt)
                 try:
                     insert(type_out, name, offset, tmp)
diff --git a/h5py/tests/__init__.py b/h5py/tests/__init__.py
index db747ff..8385af8 100755
--- a/h5py/tests/__init__.py
+++ b/h5py/tests/__init__.py
@@ -15,10 +15,13 @@ import sys
 import test_h5a
 import test_h5f
 import test_h5g
+import test_h5i
+import test_h5d
 
 from h5py import h5a, h5f, h5g, h5d, h5s, h5i, h5z, h5p
 
-TEST_CASES = (test_h5a.TestH5A, test_h5f.TestH5F, test_h5g.TestH5G)
+TEST_CASES = (test_h5a.TestH5A, test_h5f.TestH5F, test_h5g.TestH5G,
+              test_h5i.TestH5I, test_h5d.TestH5D)
 
 def buildsuite(cases):
 
diff --git a/h5py/tests/data/smpl_compound_chunked.hdf5 b/h5py/tests/data/smpl_compound_chunked.hdf5
new file mode 100644
index 0000000..e386791
Binary files /dev/null and b/h5py/tests/data/smpl_compound_chunked.hdf5 differ
diff --git a/h5py/tests/test_h5d.py b/h5py/tests/test_h5d.py
new file mode 100644
index 0000000..96701ed
--- /dev/null
+++ b/h5py/tests/test_h5d.py
@@ -0,0 +1,121 @@
+#+
+# 
+# This file is part of h5py, a low-level Python interface to the HDF5 library.
+# 
+# Copyright (C) 2008 Andrew Collette
+# http://h5py.alfven.org
+# License: BSD  (See LICENSE.txt for full license)
+# 
+# $Date$
+# 
+#-
+
+import unittest
+import os
+import numpy
+
+import h5py
+from h5py import h5f, h5d, h5i, h5s, h5t, h5p
+from h5py.errors import DatasetError
+
+HDFNAME = os.path.join(os.path.dirname(h5py.__file__), 'tests/data/smpl_compound_chunked.hdf5')
+DTYPE = numpy.dtype([('a_name','>i4'),
+                     ('c_name','|S6'),
+                     ('d_name', numpy.dtype( ('>i2', (5,10)) )),
+                     ('e_name', '>f4'),
+                     ('f_name', numpy.dtype( ('>f8', (10,)) )),
+                     ('g_name', '<u1')])
+SHAPE = (6,)
+
+basearray = numpy.ndarray(SHAPE, dtype=DTYPE)
+for i in range(SHAPE[0]):
+    basearray[i]["a_name"] = i,
+    basearray[i]["c_name"] = "Hello!"
+    basearray[i]["d_name"][:] = numpy.sum(numpy.indices((5,10)),0) + i # [:] REQUIRED for some stupid reason
+    basearray[i]["e_name"] = 0.96*i
+    basearray[i]["f_name"][:] = numpy.array((1024.9637*i,)*10)
+    basearray[i]["g_name"] = 109
+
+class TestH5D(unittest.TestCase):
+
+    def setUp(self):
+        self.fid = h5f.open(HDFNAME, h5f.ACC_RDONLY)
+        self.did = h5d.open(self.fid, "CompoundChunked")
+
+    def tearDown(self):
+        h5d.close(self.did)
+        h5f.close(self.fid)
+
+    def test_open_close(self):
+        h5d.close(self.did)
+        self.assertEqual(h5i.get_type(self.did), h5i.TYPE_BADID)
+        self.did = h5d.open(self.fid, "CompoundChunked")
+        self.assertEqual(h5i.get_type(self.did), h5i.TYPE_DATASET)
+
+        self.assertRaises(DatasetError, h5d.open, self.fid, "Something else")
+        self.assertRaises(DatasetError, h5d.close, -1)
+
+    def test_read(self):
+        array = numpy.ndarray(SHAPE, dtype=DTYPE)
+
+        h5d.read(self.did, h5s.SPACE_ALL, h5s.SPACE_ALL, array)
+        for name in DTYPE.fields:
+            self.assert_(numpy.all(array[name] == basearray[name]), "%s::\n%s\n!=\n%s" % (name, array[name], basearray[name]))
+
+        self.assertRaises(DatasetError, h5d.read, -1, h5s.SPACE_ALL, h5s.SPACE_ALL, array)
+
+    def test_get_space(self):
+        sid = h5d.get_space(self.did)
+        try:
+            shape = h5s.get_simple_extent_dims(sid)
+            self.assertEqual(shape, SHAPE)
+        finally:
+            h5s.close(sid)
+        self.assertRaises(DatasetError, h5d.get_space, -1)
+
+    def test_get_type(self):
+        # We're not testing datatype conversion here; that's for test_h5t
+        tid = h5d.get_type(self.did)
+        try:
+            self.assertEqual(h5i.get_type(tid), h5i.TYPE_DATATYPE)
+        finally:
+            h5t.close(tid)
+        self.assertRaises(DatasetError, h5d.get_type, -1)
+
+    def test_get_create_plist(self):
+        pid = h5d.get_create_plist(self.did)
+        try:
+            self.assertEqual(h5i.get_type(pid), h5i.TYPE_GENPROP_LST)
+        finally:
+            h5p.close(pid)
+
+        self.assertRaises(DatasetError, h5d.get_create_plist, -1)
+
+    def test_py_shape(self):
+        self.assertEqual(h5d.py_shape(self.did), SHAPE)
+        self.assertRaises(DatasetError, h5d.py_shape, -1)
+
+    def test_py_rank(self):
+        self.assertEqual(h5d.py_rank(self.did), 1)
+        self.assertRaises(DatasetError, h5d.py_rank, -1)
+
+    def test_py_dtype(self):
+        self.assertEqual(type(h5d.py_dtype(self.did)), numpy.dtype)
+        self.assertRaises(DatasetError, h5d.py_dtype, -1)
+        
+        
+
+
+
+
+
+
+
+
+
+
+
+
+    
+
+
diff --git a/h5py/tests/test_h5i.py b/h5py/tests/test_h5i.py
new file mode 100644
index 0000000..e0a44b0
--- /dev/null
+++ b/h5py/tests/test_h5i.py
@@ -0,0 +1,40 @@
+#+
+# 
+# This file is part of h5py, a low-level Python interface to the HDF5 library.
+# 
+# Copyright (C) 2008 Andrew Collette
+# http://h5py.alfven.org
+# License: BSD  (See LICENSE.txt for full license)
+# 
+# $Date$
+# 
+#-
+import unittest
+import os
+
+import h5py
+from h5py import h5f, h5g, h5i
+from h5py.errors import H5Error
+
+HDFNAME = os.path.join(os.path.dirname(h5py.__file__), 'tests/data/attributes.hdf5')
+OBJECTNAME = 'Group'
+
+class TestH5I(unittest.TestCase):
+
+    def setUp(self):
+        self.fid = h5f.open(HDFNAME, h5f.ACC_RDONLY)
+        self.obj = h5g.open(self.fid, OBJECTNAME)
+
+    def tearDown(self):
+        h5g.close(self.obj)
+        h5f.close(self.fid)
+
+    def test_get_type(self):
+        self.assertEqual(h5i.get_type(self.fid), h5i.TYPE_FILE)
+        self.assertEqual(h5i.get_type(self.obj), h5i.TYPE_GROUP)
+        self.assertEqual(h5i.get_type(-1), h5i.TYPE_BADID)
+
+    def test_get_name(self):
+        self.assertEqual(h5i.get_name(self.obj), '/Group')
+        self.assertEqual(h5i.get_name(-1), None)
+

-- 
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