[h5py] 07/455: h5f/h5g unit tests, h5g bugfix
Ghislain Vaillant
ghisvail-guest at moszumanska.debian.org
Thu Jul 2 18:19:11 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 e2f07f80ac299e4c0db02d6ce5d01c3037c0b849
Author: andrewcollette <andrew.collette at gmail.com>
Date: Tue May 6 04:34:04 2008 +0000
h5f/h5g unit tests, h5g bugfix
---
h5py/__init__.py | 5 +
h5py/h5f.pyx | 2 +-
h5py/h5g.pxd | 2 +-
h5py/h5g.pyx | 16 +++-
h5py/tests/__init__.py | 7 +-
h5py/tests/data/attributes.hdf5 | Bin 2240 -> 4536 bytes
h5py/tests/test_h5f.py | 67 +++++++++++++
h5py/tests/test_h5g.py | 206 ++++++++++++++++++++++++++++++++++++++++
meta/gen_attributes.c | 5 +
9 files changed, 301 insertions(+), 9 deletions(-)
diff --git a/h5py/__init__.py b/h5py/__init__.py
index ef1e563..1ac9ca4 100755
--- a/h5py/__init__.py
+++ b/h5py/__init__.py
@@ -12,13 +12,18 @@
# h5py module __init__
+__doc__ = \
"""
This is the h5py package, a Python interface to the NCSA HDF5
scientific data format.
+ Version %s
+
See the docstring for the "version" module for a longer introduction.
"""
import h5, h5f, h5g, h5s, h5t, h5d, h5a, h5p, h5z, h5i, highlevel, errors
import tests
import version
+
+__doc__ = __doc__ % version.version
diff --git a/h5py/h5f.pyx b/h5py/h5f.pyx
index 11b61a0..aee1835 100755
--- a/h5py/h5f.pyx
+++ b/h5py/h5f.pyx
@@ -46,7 +46,7 @@ CLOSE_STRONG = H5F_CLOSE_STRONG
CLOSE_DEFAULT = H5F_CLOSE_DEFAULT
CLOSE_MAPPER = {H5F_CLOSE_WEAK: 'WEAK', H5F_CLOSE_SEMI: 'SEMI',
H5F_CLOSE_STRONG: 'STRONG', H5F_CLOSE_DEFAULT: 'DEFAULT'}
-CLOSE_MAPER = DDict(CLOSE_MAPPER)
+CLOSE_MAPPER = DDict(CLOSE_MAPPER)
# === File operations =========================================================
diff --git a/h5py/h5g.pxd b/h5py/h5g.pxd
index b100327..689b53d 100755
--- a/h5py/h5g.pxd
+++ b/h5py/h5g.pxd
@@ -34,7 +34,7 @@ cdef extern from "hdf5.h":
ctypedef struct H5G_stat_t:
unsigned long fileno[2]
unsigned long objno[2]
- unsigned nlink
+ unsigned int nlink
H5G_obj_t type # new in HDF5 1.6
time_t mtime
size_t linklen
diff --git a/h5py/h5g.pyx b/h5py/h5g.pyx
index a1abea4..770278f 100755
--- a/h5py/h5g.pyx
+++ b/h5py/h5g.pyx
@@ -57,7 +57,7 @@ cdef class GroupStat:
"""
cdef public object fileno # will be a 2-tuple
cdef public object objno # will be a 2-tuple
- cdef public int nlink
+ cdef public unsigned int nlink
cdef public int type
cdef public time_t mtime
cdef public size_t linklen
@@ -222,7 +222,7 @@ def get_objinfo(hid_t loc_id, char* name, int follow_link=1):
statobj = GroupStat()
statobj.fileno = (stat.fileno[0], stat.fileno[1])
statobj.objno = (stat.objno[0], stat.objno[1])
- statobj.nlink = <int>stat.nlink
+ statobj.nlink = stat.nlink
statobj.type = <int>stat.type
statobj.mtime = stat.mtime
statobj.linklen = stat.linklen
@@ -259,7 +259,9 @@ def iterate(hid_t loc_id, char* name, object func, object data=None, int startid
You can also start at an arbitrary member by specifying its
(zero-based) index. The return value is the index of the last
- group member processed.
+ group member successfully processed; if there are three elements
+ (indices 0, 1, 2) and the last one raises StopIteration, the return
+ value is 1.
Your function:
1. Should accept three arguments: the (INT) id of the group, the
@@ -278,11 +280,14 @@ def iterate(hid_t loc_id, char* name, object func, object data=None, int startid
retval = H5Giterate(loc_id, name, &i, <H5G_iterate_t>iter_cb_helper, int_tpl)
+ if retval == 1: # user bailed out
+ i = i -1
+
if retval < 0:
if len(int_tpl[2]) != 0:
raise int_tpl[2][0]
raise GroupError("Error occured during iteration")
- return i-2
+ return i-1
# === Custom extensions =======================================================
@@ -346,7 +351,8 @@ def py_exists(hid_t group_id, char* name, int follow_link=1):
""" (INT group_id, STRING name, BOOL follow_link=True) => BOOL exists
Determine if a named member exists in the given group. If follow_link
- is True (default), symbolic links will be dereferenced.
+ is True (default), symbolic links will be dereferenced. Note this
+ function will not raise GroupError, even if the group ID is bad.
"""
cdef int retval
retval = H5Gget_objinfo(group_id, name, follow_link, NULL)
diff --git a/h5py/tests/__init__.py b/h5py/tests/__init__.py
index e58680e..db747ff 100755
--- a/h5py/tests/__init__.py
+++ b/h5py/tests/__init__.py
@@ -13,9 +13,12 @@
import unittest
import sys
import test_h5a
-import h5py.h5a, h5py.h5f, h5py.h5g, h5py.h5d, h5py.h5s, h5py.h5t, h5py.h5z, h5py.h5p
+import test_h5f
+import test_h5g
-TEST_CASES = (test_h5a.TestH5A,)
+from h5py import h5a, h5f, h5g, h5d, h5s, h5i, h5z, h5p
+
+TEST_CASES = (test_h5a.TestH5A, test_h5f.TestH5F, test_h5g.TestH5G)
def buildsuite(cases):
diff --git a/h5py/tests/data/attributes.hdf5 b/h5py/tests/data/attributes.hdf5
index c431d49..7435e3e 100755
Binary files a/h5py/tests/data/attributes.hdf5 and b/h5py/tests/data/attributes.hdf5 differ
diff --git a/h5py/tests/test_h5f.py b/h5py/tests/test_h5f.py
new file mode 100644
index 0000000..e05c1f5
--- /dev/null
+++ b/h5py/tests/test_h5f.py
@@ -0,0 +1,67 @@
+#+
+#
+# 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 tempfile
+import os
+
+import h5py
+from h5py import h5f, h5i
+from h5py.errors import FileError
+from common import getcopy, deletecopy, errstr
+
+HDFNAME = os.path.join(os.path.dirname(h5py.__file__), 'tests/data/attributes.hdf5')
+
+class TestH5F(unittest.TestCase):
+
+ def test_open_close(self):
+ fid = h5f.open(HDFNAME)
+ self.assertEqual(h5i.get_type(fid), h5i.TYPE_FILE)
+ h5f.close(fid)
+ self.assertEqual(h5i.get_type(fid), h5i.TYPE_BADID)
+
+ self.assertRaises(FileError, h5f.open, 'SOME OTHER NAME')
+ self.assertRaises(FileError, h5f.close, -1)
+
+ def test_create(self):
+ name = tempfile.mktemp('.hdf5')
+ fid = h5f.create(name)
+ self.assertEqual(h5i.get_type(fid), h5i.TYPE_FILE)
+ h5f.close(fid)
+ self.assertRaises(FileError, h5f.create, name, h5f.ACC_EXCL)
+ os.unlink(name)
+
+ def test_flush(self):
+ fid = h5f.open(HDFNAME, h5f.ACC_RDWR)
+ h5f.flush(fid)
+ self.assertRaises(FileError, h5f.flush, -1)
+ h5f.close(fid)
+
+ def test_is_hdf5(self):
+ fd, name = tempfile.mkstemp('.hdf5')
+ os.close(fd)
+ try:
+ self.assert_(not h5f.is_hdf5(name))
+ finally:
+ os.unlink(name)
+
+ self.assert_(h5f.is_hdf5(HDFNAME))
+
+
+
+
+
+
+
+
+
+
diff --git a/h5py/tests/test_h5g.py b/h5py/tests/test_h5g.py
new file mode 100644
index 0000000..89fc142
--- /dev/null
+++ b/h5py/tests/test_h5g.py
@@ -0,0 +1,206 @@
+#+
+#
+# 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 tempfile
+import os
+
+import h5py
+from h5py import h5f, h5g, h5i
+from h5py.errors import GroupError
+
+from common import getcopy, deletecopy
+
+HDFNAME = os.path.join(os.path.dirname(h5py.__file__), 'tests/data/attributes.hdf5')
+OBJECTNAME = 'Group'
+TEST_GROUPS = ['Subgroup1','Subgroup2','Subgroup3']
+NEW_LINK_NAME = 'Link name'
+
+class TestH5G(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 is_grp(self, item):
+ return h5i.get_type(item) == h5i.TYPE_GROUP
+
+ def test_open_close(self):
+ for name in TEST_GROUPS:
+ gid = h5g.open(self.obj, name)
+ self.assert_(self.is_grp(gid))
+ 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)
+
+ def test_create(self):
+ fid, filename = getcopy(HDFNAME)
+ obj = h5g.open(fid, OBJECTNAME)
+
+ 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')
+
+ deletecopy(fid, filename)
+
+ def test_link_unlink_move(self):
+ fid, filename = getcopy(HDFNAME)
+ obj = h5g.open(fid, OBJECTNAME)
+
+ # local link
+ h5g.link(obj, TEST_GROUPS[1], NEW_LINK_NAME, h5g.LINK_HARD)
+ self.assert_( h5g.py_exists(obj, NEW_LINK_NAME) )
+
+ # test local unlink
+ h5g.unlink(obj, NEW_LINK_NAME)
+ self.assert_(not h5g.py_exists(obj, NEW_LINK_NAME))
+
+ # remote link
+ rgid = h5g.open(obj, TEST_GROUPS[0])
+ h5g.link(obj, TEST_GROUPS[0], NEW_LINK_NAME, h5g.LINK_HARD, rgid)
+ self.assert_( h5g.py_exists(rgid, NEW_LINK_NAME) )
+
+ h5g.unlink(rgid, NEW_LINK_NAME)
+ self.assert_( not h5g.py_exists(rgid, NEW_LINK_NAME) )
+ h5g.close(rgid)
+
+ h5g.move(obj, TEST_GROUPS[2], NEW_LINK_NAME)
+ 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')
+
+ h5g.close(obj)
+
+ deletecopy(fid, filename)
+
+ def test_get_num_objs(self):
+
+ self.assertEqual(h5g.get_num_objs(self.obj), 3)
+ self.assertRaises(GroupError, h5g.get_num_objs, -1)
+
+ def test_objname_objtype(self):
+
+ for idx, name in enumerate(TEST_GROUPS):
+ self.assertEqual(h5g.get_objname_by_idx(self.obj, idx), name)
+ self.assertEqual(h5g.get_objtype_by_idx(self.obj, idx), h5g.OBJ_GROUP)
+
+ self.assertRaises(GroupError, h5g.get_objname_by_idx, self.obj, -1)
+ self.assertRaises(GroupError, h5g.get_objtype_by_idx, self.obj, -1)
+
+ def test_get_objinfo(self):
+
+ retval = h5g.get_objinfo(self.obj, '.')
+ retval.fileno
+ retval.objno
+ self.assertEqual(retval.nlink, 1)
+ self.assertEqual(retval.type, h5g.OBJ_GROUP)
+ retval.mtime
+ retval.linklen
+
+ self.assertRaises(GroupError, h5g.get_objinfo, self.obj, 'Something else')
+
+
+ def test_iterate(self):
+
+ def iterate_all(id, name, namelist):
+ namelist.append(name)
+
+ def iterate_two(id, name, namelist):
+ if len(namelist) == 2:
+ raise StopIteration
+ namelist.append(name)
+
+ def iterate_fault(id, name, namelist):
+ if len(namelist) == 2:
+ raise RuntimeError("Intentional fault")
+ namelist.append(name)
+
+ namelist = []
+ n = h5g.iterate(self.obj, '.', iterate_all, namelist)
+ self.assertEqual(namelist, TEST_GROUPS)
+ self.assertEqual(n, len(TEST_GROUPS)-1)
+
+ namelist = []
+ n = h5g.iterate(self.obj, '.', iterate_two, namelist)
+ self.assertEqual(namelist, TEST_GROUPS[0:2])
+ self.assertEqual(n, 1)
+
+ namelist = []
+ self.assertRaises(RuntimeError, h5g.iterate, self.obj, '.', iterate_fault, namelist)
+ self.assertEqual(namelist, TEST_GROUPS[0:2])
+
+ namelist = []
+ n = h5g.iterate(self.obj, '.', iterate_two, namelist, 1)
+ self.assertEqual(namelist, TEST_GROUPS[1:3])
+ self.assertEqual(n, 2)
+
+ def test_py_listnames(self):
+
+ self.assertEqual(h5g.py_listnames(self.obj), TEST_GROUPS)
+ self.assertRaises(GroupError, h5g.py_listnames, -1)
+
+ def test_py_iternames(self):
+
+ iterator = h5g.py_iternames(self.obj)
+ self.assertEqual(list(iterator), TEST_GROUPS)
+ #self.assertRaises(StopIteration, iterator.next()) bug in unittest
+
+ self.assertRaises(GroupError, h5g.py_iternames, -1)
+
+ def test_py_exists(self):
+
+ self.assert_(h5g.py_exists(self.obj, TEST_GROUPS[0]))
+ self.assert_(not h5g.py_exists(self.obj, 'Something else'))
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/meta/gen_attributes.c b/meta/gen_attributes.c
index 204c1ad..b14c71c 100755
--- a/meta/gen_attributes.c
+++ b/meta/gen_attributes.c
@@ -67,6 +67,11 @@ int attributes(char* filename){
if(H5Awrite(aid, H5T_NATIVE_INT, &val4)<0) goto out;
if(H5Aclose(aid)<0) goto out;
+ if(H5Gcreate(gid, "Subgroup1", -1)<0) goto out;
+ if(H5Gcreate(gid, "Subgroup2", -1)<0) goto out;
+ if(H5Gcreate(gid, "Subgroup3", -1)<0) goto out;
+
+
retval = 0; /* got here == success */
out:
--
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