[h5py] 48/455: More fixes, h5s unit tests

Ghislain Vaillant ghisvail-guest at moszumanska.debian.org
Thu Jul 2 18:19:16 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 60f77e275d2b0b5badffcc1567b1121caa537a3d
Author: andrewcollette <andrew.collette at gmail.com>
Date:   Wed Jun 11 23:01:26 2008 +0000

    More fixes, h5s unit tests
---
 h5py/h5g.pyx           | 22 +++++++++++++---------
 h5py/h5i.pyx           |  9 ++++-----
 h5py/h5s.pyx           | 26 ++++++++++++++++----------
 h5py/std_defs.pxi      | 14 +++++++++++++-
 h5py/tests/__init__.py |  9 +++++----
 h5py/tests/test_h5g.py | 32 ++++++++++++++++----------------
 setup.py               | 15 ++++++++++++++-
 7 files changed, 81 insertions(+), 46 deletions(-)

diff --git a/h5py/h5g.pyx b/h5py/h5g.pyx
index bfcf12f..0807458 100644
--- a/h5py/h5g.pyx
+++ b/h5py/h5g.pyx
@@ -131,13 +131,18 @@ def get_objname_by_idx(hid_t loc_id, hsize_t idx):
     """ (INT loc_id, INT idx) => STRING object_name
 
         Get the name of a group member given its zero-based index.
+
+        Due to a bug in the HDF5 library, the only possible exception
+        raised by this function is ValueError.
     """
     cdef int size
     cdef char* buf
     buf = NULL
 
+    # This function does not properly raise an exception
     size = H5Gget_objname_by_idx(loc_id, idx, NULL, 0)
-    assert size > 0
+    if size < 0:
+        raise ValueError("Invalid argument")
 
     buf = <char*>emalloc(sizeof(char)*(size+1))
     try:
@@ -156,10 +161,11 @@ def get_objtype_by_idx(hid_t loc_id, hsize_t idx):
             - GROUP
             - DATASET
             - DATATYPE
+
+        Due to a bug in the HDF5 library, the only possible exception 
+        raised by this function is ValueError.
     """
-    # What seems to be a bug in the HDF5 library prevents an error callback
-    # for an out-of-range index, although -1 is returned.  Interestingly,
-    # passing an invalid loc_id does raise an error.
+    # This function does not properly raise an exception
     cdef herr_t retval
     retval = H5Gget_objtype_by_idx(loc_id, idx)
     if retval < 0:
@@ -305,9 +311,9 @@ def py_listnames(hid_t group_id):
     nitems = get_num_objs(group_id)
 
     for i from 0 <= i < nitems:
-        thelist.append(get_objname_by_idx(group_id, i))
+        namelist.append(get_objname_by_idx(group_id, i))
 
-    return thelist
+    return namelist
 
 cdef class _GroupIterator:
 
@@ -353,12 +359,10 @@ def py_exists(hid_t group_id, char* name, int follow_link=1):
 
         Determine if a named member exists in the given group.  If follow_link
         is True (default), symbolic links will be dereferenced. Note this
-        function will not raise an exception, unless the group ID is bad.
+        function will not raise an exception.
     """
     try:
         H5Gget_objinfo(group_id, name, follow_link, NULL)
-    except ValueError:
-        raise
     except:
         return False
     return True
diff --git a/h5py/h5i.pyx b/h5py/h5i.pyx
index 8aaa52c..3d8b4a6 100644
--- a/h5py/h5i.pyx
+++ b/h5py/h5i.pyx
@@ -45,7 +45,8 @@ def get_type(hid_t obj_id):
     """ (INT obj_id) => INT type_code
 
         Determine the type of an arbitrary HDF5 object.  The return value is
-        always one of TYPE_*; if the ID is invalid, TYPE_BADID is returned.
+        always one of the type constants defined in this module. 
+        If the ID is invalid, BADID is returned.
     """
     return <int>H5Iget_type(obj_id)
 
@@ -54,19 +55,17 @@ 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 identifier is valid but is not associated with a name, returns
+        the identifier is invalid or is not associated with a name, returns
         None.
     """
     cdef int namelen
     cdef char* name
 
     namelen = <int>H5Iget_name(obj_id, NULL, 0)
+    assert namelen >= 0
     if namelen == 0:
         return None
 
-    if namelen < 0:
-        raise RuntimeError("Failed to raise exception at get_name")
-
     name = <char*>emalloc(sizeof(char)*(namelen+1))
     try:
         H5Iget_name(obj_id, name, namelen+1)
diff --git a/h5py/h5s.pyx b/h5py/h5s.pyx
index 432a4d9..4cc6795 100644
--- a/h5py/h5s.pyx
+++ b/h5py/h5s.pyx
@@ -64,8 +64,8 @@ def close(hid_t space_id):
 def create(int class_code):
     """ (INT class_code) => INT new_space_id
 
-        Create a new HDF5 dataspace object, of the given class.  Legal values
-        are CLASS_SCALAR and CLASS_SIMPLE.
+        Create a new HDF5 dataspace object, of the given class.  
+        Legal values are SCALAR and SIMPLE.
     """
     return H5Screate(<H5S_class_t>class_code)
 
@@ -127,6 +127,7 @@ def offset_simple(hid_t space_id, object offset=None):
         the offsets on all axes will be set to 0.
     """
     cdef int rank
+    cdef int i
     cdef hssize_t *dims
     dims = NULL
 
@@ -136,12 +137,16 @@ def offset_simple(hid_t space_id, object offset=None):
 
         rank = H5Sget_simple_extent_ndims(space_id)
         
-        if offset is None:
-            dims = NULL
-        else:
-            require_tuple(offset, 0, rank, "offset")
-            dims = <hssize_t*>emalloc(sizeof(hssize_t)*rank)
+        require_tuple(offset, 1, rank, "offset")
+        dims = <hssize_t*>emalloc(sizeof(hssize_t)*rank)
+        if(offset is not None):
             convert_tuple(offset, <hsize_t*>dims, rank)
+        else:
+            # The HDF5 docs say passing in NULL resets the offset to 0.  
+            # Instead it raises an exception.  Imagine my surprise. We'll 
+            # do this manually.
+            for i from 0<=i<rank:
+                dims[i] = 0
 
         H5Soffset_simple(space_id, dims)
 
@@ -189,7 +194,7 @@ def get_simple_extent_npoints(hid_t space_id):
 def get_simple_extent_type(hid_t space_id):
     """ (INT space_id) => INT class_code
 
-        Class code is either CLASS_SCALAR or CLASS_SIMPLE.
+        Class code is either SCALAR or SIMPLE.
     """
     return <int>H5Sget_simple_extent_type(space_id)
 
@@ -208,7 +213,7 @@ def set_extent_simple(hid_t space_id, object dims_tpl, object max_dims_tpl=None)
         Reset the dataspace extent, via a tuple of new dimensions.  Every
         element of dims_tpl must be a positive integer.  You can also specify
         the maximum dataspace size, via the tuple max_dims.  The special
-        integer SPACE_UNLIMITED, as an element of max_dims, indicates an
+        integer UNLIMITED, as an element of max_dims, indicates an
         unlimited dimension.
     """
     cdef int rank
@@ -240,7 +245,7 @@ def set_extent_none(hid_t space_id):
 
         Remove the dataspace extent; class changes to h5s.CLASS_NO_CLASS.
     """
-    H5Sset_extent_non(space_id)
+    H5Sset_extent_none(space_id)
 
 # === General selection operations ============================================
 
@@ -361,6 +366,7 @@ def select_elements(hid_t space_id, object coord_list, int op=H5S_SELECT_SET):
 
         Select elements using a list of points.  List entries should be
         <rank>-length tuples containing point coordinates.
+        A zero-length list is apparently not allowed.
     """
     cdef size_t nelements       # Number of point coordinates
     cdef hsize_t *coords        # Contiguous 2D array nelements x rank x sizeof(hsize_t)
diff --git a/h5py/std_defs.pxi b/h5py/std_defs.pxi
index 6623c1c..13aeb16 100644
--- a/h5py/std_defs.pxi
+++ b/h5py/std_defs.pxi
@@ -1,5 +1,17 @@
+#+
+# 
+# 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$
+# 
+#-
+
 # "Boilerplate" includes which are so common I don't want to repeat them
-# in every file.
+# in every file.  These include all basic HDF5 and C typedefs.
 
 from h5 cimport hid_t, hbool_t, herr_t, htri_t, hsize_t, \
                 hssize_t, haddr_t, hvl_t
diff --git a/h5py/tests/__init__.py b/h5py/tests/__init__.py
index 8c0fd37..0b2c914 100644
--- a/h5py/tests/__init__.py
+++ b/h5py/tests/__init__.py
@@ -12,13 +12,14 @@
 
 import unittest
 import sys
-import test_h5a, test_h5f, test_h5i, test_h5d
+import test_h5a, test_h5f, test_h5i, test_h5d, \
+        test_h5g, test_h5, test_h5s, test_h5p
 
 from h5py import h5a, h5f, h5g, h5d, h5s, h5i, h5z, h5p#, highlevel
 
-TEST_CASES = (test_h5a.TestH5A, test_h5f.TestH5F, #test_h5g.TestH5G,
-              test_h5i.TestH5I, test_h5d.TestH5D)#, test_h5.TestH5,
-              #test_h5p.TestH5P)
+TEST_CASES = (test_h5a.TestH5A, test_h5f.TestH5F, test_h5g.TestH5G,
+              test_h5i.TestH5I, test_h5d.TestH5D, test_h5.TestH5,
+              test_h5s.TestH5S, test_h5p.TestH5P)
 
 def buildsuite(cases):
 
diff --git a/h5py/tests/test_h5g.py b/h5py/tests/test_h5g.py
index 7159d56..08a1d80 100644
--- a/h5py/tests/test_h5g.py
+++ b/h5py/tests/test_h5g.py
@@ -16,7 +16,7 @@ import os
 
 import h5py
 from h5py import h5f, h5g, h5i
-from h5py.errors import GroupError
+from h5py.h5e import H5Error
 
 from common import getcopy, deletecopy
 
@@ -45,8 +45,8 @@ class TestH5G(unittest.TestCase):
             h5g.close(gid)
             self.assert_(not self.is_grp(gid))
         
-        self.assertRaises(GroupError, h5g.open, self.obj, 'Some other group')
-        self.assertRaises(GroupError, h5g.close, -1)
+        self.assertRaises(H5Error, h5g.open, self.obj, 'Some other group')
+        self.assertRaises(ValueError, h5g.close, -1)
 
     def test_create(self):
         fid, filename = getcopy(HDFNAME)
@@ -55,7 +55,7 @@ class TestH5G(unittest.TestCase):
         gid = h5g.create(obj, 'New group')
         h5g.close(gid)
         self.assert_(h5g.py_exists(obj, 'New group'))
-        self.assertRaises(GroupError, h5g.create, obj, 'New group')
+        self.assertRaises(H5Error, h5g.create, obj, 'New group')
 
         deletecopy(fid, filename)
 
@@ -95,10 +95,10 @@ class TestH5G(unittest.TestCase):
         self.assert_(h5g.py_exists(obj, NEW_LINK_NAME))
         self.assert_(not h5g.py_exists(obj, TEST_GROUPS[2]))
 
-        self.assertRaises(GroupError, h5g.move, obj, 'Ghost group', 'blah')
-        self.assertRaises(GroupError, h5g.unlink, obj, 'Some other name')
-        self.assertRaises(GroupError, h5g.link, obj, 'Ghost group', 'blah') 
-        self.assertRaises(GroupError, h5g.get_linkval, -1, "foobar")
+        self.assertRaises(H5Error, h5g.move, obj, 'Ghost group', 'blah')
+        self.assertRaises(H5Error, h5g.unlink, obj, 'Some other name')
+        self.assertRaises(H5Error, h5g.link, obj, 'Ghost group', 'blah') 
+        self.assertRaises(ValueError, h5g.get_linkval, -1, "foobar")
 
         h5g.close(obj)
 
@@ -107,7 +107,7 @@ class TestH5G(unittest.TestCase):
     def test_get_num_objs(self):
 
         self.assertEqual(h5g.get_num_objs(self.obj), 3)
-        self.assertRaises(GroupError, h5g.get_num_objs, -1)
+        self.assertRaises(ValueError, h5g.get_num_objs, -1)
 
     def test_objname_objtype(self):
 
@@ -115,8 +115,8 @@ class TestH5G(unittest.TestCase):
             self.assertEqual(h5g.get_objname_by_idx(self.obj, idx), name)
             self.assertEqual(h5g.get_objtype_by_idx(self.obj, idx), h5g.GROUP)
 
-        self.assertRaises(GroupError, h5g.get_objname_by_idx, self.obj, -1)
-        self.assertRaises(GroupError, h5g.get_objtype_by_idx, self.obj, -1)
+        self.assertRaises(ValueError, h5g.get_objname_by_idx, self.obj, -1)
+        self.assertRaises(ValueError, h5g.get_objtype_by_idx, self.obj, -1)
 
     def test_get_objinfo(self):
 
@@ -128,7 +128,7 @@ class TestH5G(unittest.TestCase):
         retval.mtime
         retval.linklen
 
-        self.assertRaises(GroupError, h5g.get_objinfo, self.obj, 'Something else')
+        self.assertRaises(ValueError, h5g.get_objinfo, self.obj, 'Something else')
 
 
     def test_iterate(self):
@@ -170,15 +170,15 @@ class TestH5G(unittest.TestCase):
         h5g.set_comment(obj, TEST_GROUPS[0], "This is a comment.")
         self.assertEqual(h5g.get_comment(obj, TEST_GROUPS[0]), "This is a comment.")
 
-        self.assertRaises(GroupError, h5g.set_comment, -1, "foo", "bar")
-        self.assertRaises(GroupError, h5g.get_comment, -1, "foo")
+        self.assertRaises(ValueError, h5g.set_comment, -1, "foo", "bar")
+        self.assertRaises(ValueError, h5g.get_comment, -1, "foo")
 
         deletecopy(fid, filename)
 
     def test_py_listnames(self):
 
         self.assertEqual(h5g.py_listnames(self.obj), TEST_GROUPS)
-        self.assertRaises(GroupError, h5g.py_listnames, -1)
+        self.assertRaises(ValueError, h5g.py_listnames, -1)
 
     def test_py_iternames(self):
 
@@ -186,7 +186,7 @@ class TestH5G(unittest.TestCase):
         self.assertEqual(list(iterator), TEST_GROUPS)
         #self.assertRaises(StopIteration, iterator.next()) bug in unittest
         
-        self.assertRaises(GroupError, h5g.py_iternames, -1)
+        self.assertRaises(ValueError, h5g.py_iternames, -1)
 
     def test_py_exists(self):
 
diff --git a/setup.py b/setup.py
index 2c0e01c..39bfbe7 100644
--- a/setup.py
+++ b/setup.py
@@ -44,6 +44,8 @@ from distutils.core import setup
 from distutils.extension import Extension
 import os
 import sys
+import shutil
+import fnmatch
 
 # Distutils tries to use hard links when building source distributions, which 
 # fails under a wide variety of network filesystems under Linux.
@@ -90,17 +92,28 @@ class dev(Command):
     description = "Developer commands (--doc, --readme=<file>)"
     user_options = [('doc','d','Rebuild documentation'),
                     ('readme=','r','Rebuild HTML readme file'),
-                    ('inspect', 'i', 'Don\'t use this.')]
+                    ('clean', 'c', 'Remove built files and Pyrex temp files.')]
     boolean_options = ['doc', 'inspect']
 
     def initialize_options(self):
         self.doc = False
         self.readme = False
+        self.clean = False
 
     def finalize_options(self):
         pass
 
     def run(self):
+        if self.clean:
+            try:
+                shutil.rmtree('build')
+            except OSError:
+                pass
+            fnames = [os.path.join('h5py',x) for x in os.listdir('h5py') if 
+                      (fnmatch.fnmatch(x,'h5*.c') or fnmatch.fnmatch(x, '*.dep'))]
+            for name in fnames:
+                os.remove(name)
+
         if self.doc:
             buildobj = self.distribution.get_command_obj('build')
             buildobj.run()

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