[h5py] 278/455: Update tests; workaround HDF5 bug in H5FD_CORE/H5F_ACC_EXCL

Ghislain Vaillant ghisvail-guest at moszumanska.debian.org
Thu Jul 2 18:19:41 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 3be441ed63b9761ff351d38169381603d00010d5
Author: andrewcollette <andrew.collette at gmail.com>
Date:   Mon Jun 15 23:26:17 2009 +0000

    Update tests; workaround HDF5 bug in H5FD_CORE/H5F_ACC_EXCL
---
 h5py/h5e.pyx                 |  17 +++--
 h5py/highlevel.py            |  11 ++-
 h5py/tests/__init__.py       |   5 ++
 h5py/tests/common.py         |  23 ++++++
 h5py/tests/test_h5a.py       |   3 +-
 h5py/tests/test_h5d.py       |   1 -
 h5py/tests/test_h5f.py       |   7 +-
 h5py/tests/test_h5g.py       |   1 -
 h5py/tests/test_h5i.py       |   1 -
 h5py/tests/test_h5p.py       |   1 -
 h5py/tests/test_h5r.py       |   1 -
 h5py/tests/test_h5s.py       |   1 -
 h5py/tests/test_h5t.py       |   3 +-
 h5py/tests/test_highlevel.py | 171 ++++++++++++++++++++++++++++++++-----------
 h5py/tests/test_utils.py     |   1 -
 15 files changed, 180 insertions(+), 67 deletions(-)

diff --git a/h5py/h5e.pyx b/h5py/h5e.pyx
index bef7a8d..e029bc1 100644
--- a/h5py/h5e.pyx
+++ b/h5py/h5e.pyx
@@ -190,17 +190,22 @@ cdef dict _minor_table = {
     H5E_OVERFLOW:       IOError,    # Address overflowed 
     H5E_FCNTL:          IOError,    # File control (fcntl) failed
 
+    H5E_FILEEXISTS:     IOError,    # File already exists 
+    H5E_FILEOPEN:       IOError,    # File already open 
+    H5E_CANTCREATE:     IOError,    # Unable to create file
+    H5E_CANTOPENFILE:   IOError,    # Unable to open file 
+    H5E_CANTCLOSEFILE:  IOError,    # Unable to close file 
+    H5E_NOTHDF5:        IOError,    # Not an HDF5 file 
+    H5E_BADFILE:        ValueError, # Bad file ID accessed 
+    H5E_TRUNCATED:      IOError,    # File has been truncated
+    H5E_MOUNT:          IOError,    # File mount error 
+
     H5E_NOFILTER:       IOError,    # Requested filter is not available 
     H5E_CALLBACK:       IOError,    # Callback failed 
     H5E_CANAPPLY:       IOError,    # Error from filter 'can apply' callback 
     H5E_SETLOCAL:       IOError,    # Error from filter 'set local' callback 
     H5E_NOENCODER:      IOError,    # Filter present but encoding disabled 
 
-    H5E_FILEEXISTS:     ValueError,  # File already exists 
-    H5E_FILEOPEN:       ValueError,  # File already open 
-    H5E_NOTHDF5:        ValueError,  # Not an HDF5 file 
-    H5E_BADFILE:        ValueError,  # Bad file ID accessed
-
     H5E_BADATOM:        ValueError,  # Unable to find atom information (already closed?) 
     H5E_BADGROUP:       ValueError,  # Unable to find ID group information 
     H5E_BADSELECT:      ValueError,  # Invalid selection (hyperslabs)
@@ -225,6 +230,8 @@ cdef dict _exact_table = {
     (H5E_CACHE, H5E_BADVALUE):      IOError,  # obj create w/o write intent 1.8
     (H5E_RESOURCE, H5E_CANTINIT):   IOError,  # obj create w/o write intent 1.6
     (H5E_INTERNAL, H5E_SYSERRSTR):  IOError,  # e.g. wrong file permissions
+    (H5E_DATATYPE, H5E_CANTINIT):   TypeError,  # No conversion path
+    (H5E_ARGS, H5E_CANTINIT):       TypeError,  # Illegal operation on object
   }
 
 
diff --git a/h5py/highlevel.py b/h5py/highlevel.py
index 4b06568..6cd5866 100644
--- a/h5py/highlevel.py
+++ b/h5py/highlevel.py
@@ -38,6 +38,8 @@ from h5py.h5 import H5Error
 import h5py.selections as sel
 from h5py.selections import CoordsList
 
+import version
+
 import filters
 
 config = h5.get_config()
@@ -624,14 +626,17 @@ class File(Group):
         elif mode == 'r+':
             self.fid = h5f.open(name, h5f.ACC_RDWR, fapl=plist)
         elif mode == 'w-':
+            if driver == 'core' and version.hdf5_version_tuple[0:2] == (1,6):
+                raise NotImplementedError("w- flag does not work on 1.6 for CORE driver")
             self.fid = h5f.create(name, h5f.ACC_EXCL, fapl=plist)
         elif mode == 'w':
             self.fid = h5f.create(name, h5f.ACC_TRUNC, fapl=plist)
         elif mode == 'a' or mode is None:
-            if not os.path.exists(name):
-                self.fid = h5f.create(name, h5f.ACC_EXCL, fapl=plist)
-            else:
+            try:
                 self.fid = h5f.open(name, h5f.ACC_RDWR, fapl=plist)
+            except IOError:
+                self.fid = h5f.create(name, h5f.ACC_EXCL, fapl=plist)
+                
         else:
             raise ValueError("Invalid mode; must be one of r, r+, w, w-, a")
 
diff --git a/h5py/tests/__init__.py b/h5py/tests/__init__.py
index 505e285..e0290bd 100644
--- a/h5py/tests/__init__.py
+++ b/h5py/tests/__init__.py
@@ -12,6 +12,7 @@
 
 import h5py.tests
 import unittest
+import common
 
 mnames = [
 'test_dataset',
@@ -51,5 +52,9 @@ def autotest():
     except:
         sys.exit(2)
 
+def testinfo():
+    print "%d tests disabled" % common.skipped
+
+
 
 
diff --git a/h5py/tests/common.py b/h5py/tests/common.py
index 5b61200..bf178d8 100644
--- a/h5py/tests/common.py
+++ b/h5py/tests/common.py
@@ -51,6 +51,12 @@ class ResourceManager(object):
         for fname in self.fnames:
             if op.exists(fname):
                 os.unlink(fname)
+            try:
+                fname %= 0
+            except TypeError:
+                continue
+            if op.exists(fname):
+                os.unlink(fname)
 
     def get_data_path(self, name):
         """ Return the full path to a data file (given its basename) """
@@ -79,7 +85,9 @@ def api_16(func):
         return func
     return None
 
+skipped = []
 def skip(func):
+    skipped.append(func)
     return None
 
 test_coverage = set()
@@ -162,6 +170,21 @@ class HDF5TestCase(unittest.TestCase):
         self.fid.close()
         os.unlink(self.fname)
 
+class TestCasePlus(unittest.TestCase):
+
+    def assertRaisesMsg(self, msg, exc, clb, *args, **kwds):
+        try:
+            clb(*args, **kwds)
+        except exc:
+            return
+        raise AssertionError("%s not raised: %s" % (exc, msg))
+
+
+
+
+
+
+
 
 
     
diff --git a/h5py/tests/test_h5a.py b/h5py/tests/test_h5a.py
index daf7080..c58357f 100644
--- a/h5py/tests/test_h5a.py
+++ b/h5py/tests/test_h5a.py
@@ -15,7 +15,6 @@ from numpy import array, ndarray, dtype, all, ones
 from common import HDF5TestCase, api_18
 
 from h5py import *
-from h5py.h5 import H5Error
 
 # === attributes.hdf5 description ===
 
@@ -129,7 +128,7 @@ class TestH5A(HDF5TestCase):
         del attr
 
         h5a.delete(obj, ATTRIBUTES_ORDER[0])
-        self.assertRaises(H5Error, h5a.open, obj, ATTRIBUTES_ORDER[0])
+        self.assertRaises(KeyError, h5a.open, obj, ATTRIBUTES_ORDER[0])
 
 
     # === Attribute I/O =======================================================
diff --git a/h5py/tests/test_h5d.py b/h5py/tests/test_h5d.py
index 78d5d44..91f7894 100644
--- a/h5py/tests/test_h5d.py
+++ b/h5py/tests/test_h5d.py
@@ -14,7 +14,6 @@ import numpy
 from common import HDF5TestCase
 
 from h5py import *
-from h5py.h5 import H5Error
 
 HDFNAME = 'smpl_compound_chunked.hdf5'
 DTYPE = numpy.dtype([('a_name','>i4'),
diff --git a/h5py/tests/test_h5f.py b/h5py/tests/test_h5f.py
index 0f58aab..1d34609 100644
--- a/h5py/tests/test_h5f.py
+++ b/h5py/tests/test_h5f.py
@@ -16,7 +16,6 @@ import tempfile
 from common import getfullpath, HDF5TestCase
 
 from h5py import *
-from h5py.h5 import H5Error
 
 HDFNAME = 'attributes.hdf5'
 
@@ -35,7 +34,7 @@ class TestH5F(HDF5TestCase):
         fid.close()
         self.assertEqual(h5i.get_type(fid), h5i.BADID)
 
-        self.assertRaises(H5Error, h5f.open, 'SOME OTHER NAME')
+        self.assertRaises(IOError, h5f.open, 'SOME OTHER NAME')
 
     def test_create(self):
         name = tempfile.mktemp('.hdf5')
@@ -43,7 +42,7 @@ class TestH5F(HDF5TestCase):
         try:
             self.assertEqual(h5i.get_type(fid), h5i.FILE)
             fid.close()
-            self.assertRaises(H5Error, h5f.create, name, h5f.ACC_EXCL)
+            self.assertRaises(IOError, h5f.create, name, h5f.ACC_EXCL)
         finally:
             try:
                 os.unlink(name)
@@ -85,12 +84,10 @@ class TestH5F(HDF5TestCase):
 
     def test_get_obj_count(self):
         self.assert_(h5f.get_obj_count(self.fid, h5f.OBJ_ALL) >= 0)
-        self.assertRaises(H5Error, h5f.get_obj_count, -1, h5f.OBJ_ALL)
     
     def test_get_obj_ids(self):
         idlist = h5f.get_obj_ids(self.fid, h5f.OBJ_ALL)
         self.assert_(isinstance(idlist, list))
-        self.assertRaises(H5Error, h5f.get_obj_ids, -1, h5f.OBJ_ALL)
 
     def test_py(self):
         self.assertEqual(self.fid.name, self.fname)
diff --git a/h5py/tests/test_h5g.py b/h5py/tests/test_h5g.py
index 95858c0..91929d8 100644
--- a/h5py/tests/test_h5g.py
+++ b/h5py/tests/test_h5g.py
@@ -13,7 +13,6 @@
 from common import HDF5TestCase
 
 from h5py import *
-from h5py.h5 import H5Error
 
 HDFNAME = 'attributes.hdf5'
 OBJECTNAME = 'Group'
diff --git a/h5py/tests/test_h5i.py b/h5py/tests/test_h5i.py
index a1cdb27..9cf4d1c 100644
--- a/h5py/tests/test_h5i.py
+++ b/h5py/tests/test_h5i.py
@@ -13,7 +13,6 @@
 from common import HDF5TestCase
 
 from h5py import *
-from h5py.h5 import H5Error
 
 HDFNAME = 'attributes.hdf5'
 OBJECTNAME = 'Group'
diff --git a/h5py/tests/test_h5p.py b/h5py/tests/test_h5p.py
index a06f5df..0676033 100644
--- a/h5py/tests/test_h5p.py
+++ b/h5py/tests/test_h5p.py
@@ -14,7 +14,6 @@ import unittest
 import numpy
 
 from h5py import *
-from h5py.h5 import H5Error
 
 HDFNAME = 'attributes.hdf5'
 
diff --git a/h5py/tests/test_h5r.py b/h5py/tests/test_h5r.py
index 0ec1470..1604162 100644
--- a/h5py/tests/test_h5r.py
+++ b/h5py/tests/test_h5r.py
@@ -16,7 +16,6 @@ import os
 import numpy
 
 from h5py import *
-from h5py.h5 import H5Error
 
 
 class TestH5R(unittest.TestCase):
diff --git a/h5py/tests/test_h5s.py b/h5py/tests/test_h5s.py
index 9c90831..245e29c 100644
--- a/h5py/tests/test_h5s.py
+++ b/h5py/tests/test_h5s.py
@@ -14,7 +14,6 @@ import unittest
 import numpy
 
 from h5py import *
-from h5py.h5 import H5Error
 
 spaces = [(10,10), (1,1), (1,), (), (2**40,),(2**63-1,)]
 max_spaces = [(10,10), (3,4), (h5s.UNLIMITED,), (), (2**41,), (2**63-1,)]
diff --git a/h5py/tests/test_h5t.py b/h5py/tests/test_h5t.py
index c96537c..fb2eb2f 100644
--- a/h5py/tests/test_h5t.py
+++ b/h5py/tests/test_h5t.py
@@ -16,7 +16,6 @@ import os
 from numpy import dtype
 
 from h5py import *
-from h5py.h5 import H5Error
 from common import HDF5TestCase
 
 kind_map = {'i': h5t.TypeIntegerID, 'u': h5t.TypeIntegerID, 'f': h5t.TypeFloatID,
@@ -105,7 +104,7 @@ class TestH5T(HDF5TestCase):
         htype = h5t.STD_I8LE.copy()
         htype.set_sign(h5t.SGN_NONE)
         htype.lock()
-        self.assertRaises(H5Error, htype.set_sign, h5t.SGN_2)
+        self.assertRaises(TypeError, htype.set_sign, h5t.SGN_2)
 
     def test_get_class(self):
 
diff --git a/h5py/tests/test_highlevel.py b/h5py/tests/test_highlevel.py
index 7fe91d3..4be6faa 100644
--- a/h5py/tests/test_highlevel.py
+++ b/h5py/tests/test_highlevel.py
@@ -17,10 +17,12 @@ import shutil
 import os
 import numpy
 
+import os.path as op
+
+import h5py
 from h5py.highlevel import *
 from h5py import *
-from h5py.h5 import H5Error
-from common import getfullpath, HDF5TestCase, api_18, api_16, res
+from common import getfullpath, HDF5TestCase, api_18, api_16, res, TestCasePlus
 import testfiles
 
 class SliceFreezer(object):
@@ -45,7 +47,7 @@ TYPES = TYPES1 + TYPES2
 SHAPES = [(), (1,), (10,5), (1,10), (10,1), (100,1,100), (51,2,1025)]
 
  
-class TestFile(HDF5TestCase):
+class TestFile(TestCasePlus):
 
     def setUp(self):
         self.fname = res.get_data_copy(HDFNAME)
@@ -66,44 +68,97 @@ class TestFile(HDF5TestCase):
             self.assert_(isinstance(f.filename, typ), msg)
             self.assertEqual(f.filename, fname, msg)
             f.close()
-        
-    def test_File_init_r(self):
-        with File(self.fname, 'r') as f:
-            self.assert_(isinstance(f["CompoundChunked"], Dataset))
-            self.assertRaises(H5Error, f.create_group, "FooBar")
-            self.assertEqual(f.mode, 'r')
-            self.assertEqual(f.filename, self.fname)
-
-    def test_File_init_rp(self):
-        with File(self.fname, 'r+') as f:
-            self.assert_(isinstance(f["CompoundChunked"], Dataset))
-            f.create_group("FooBar")
-            self.assert_(isinstance(f["FooBar"], Group))
-            self.assertEqual(f.mode, 'r+')
-            self.assertEqual(f.filename, self.fname)
-
-    def test_File_init_a(self):
-        with File(self.fname, 'a') as f:
-            self.assert_(isinstance(f["CompoundChunked"], Dataset))
-            f.create_group("FooBar")
-            self.assert_(isinstance(f["FooBar"], Group))
-            self.assertEqual(f.mode, 'a')
-            self.assertEqual(f.filename, self.fname)
-
-    def test_File_init_w(self):
-        with File(self.fname, 'w') as f:
-            self.assert_("CompoundChunked" not in f)
-            f.create_group("FooBar")
-            self.assert_(isinstance(f["FooBar"], Group))
-            self.assertEqual(f.mode, 'w')
-            self.assertEqual(f.filename, self.fname)
-
-    def test_File_init_wm(self):
-        self.assertRaises(H5Error, File, self.fname, 'w-')
-        tmpname = tempfile.mktemp('.hdf5')
-        f = File(tmpname,'w-')
+
+    def mode_tester(self, driver, suffix=None, **kwds):
+        """ Test file behavior w.r.t modes for given driver keywords"""
+
+        # create a test file with known contents
+        fname = res.get_name(suffix)
+        if driver == 'family':
+            # Family info is stored in the file, so have to do it this way
+            f = h5py.File(fname, 'w', driver=driver, **kwds)
+        else:
+            f = h5py.File(fname, 'w')
+        f.attrs['foo'] = 42
+        f.close()
+
+        msg = " driver %s kwds %s" % (driver, kwds)
+
+        # catch core driver for r, r+, a
+        if driver == 'core' and h5py.version.hdf5_version_tuple[0:2] == (1,6):
+            self.assertRaises(NotImplementedError, h5py.File, fname, 'r', driver=driver, **kwds)
+            self.assertRaises(NotImplementedError, h5py.File, fname, 'r+', driver=driver, **kwds)
+            self.assertRaises(NotImplementedError, h5py.File, fname, 'a', driver=driver, **kwds)
+
+        else:
+
+            # mode r
+            f = h5py.File(fname, 'r', driver=driver, **kwds)
+            self.assertEqual(f.attrs['foo'], 42, 'mode r'+msg)
+            f.close()
+            self.assertRaisesMsg('mode r'+msg, IOError, h5py.File, res.get_name(), 'r', driver=driver, **kwds)
+
+            # mode r+
+            f = h5py.File(fname, 'r+', driver=driver, **kwds)
+            self.assertEqual(f.attrs['foo'], 42, 'mode r+'+msg)
+            f.attrs['bar'] = 43
+            self.assertEqual(f.attrs['bar'], 43, 'mode r+'+msg)
+            f.close()
+            self.assertRaises(IOError, h5py.File, res.get_name(), 'r', driver=driver, **kwds)
+
+            # mode a
+            f = h5py.File(fname, 'a', driver=driver, **kwds)
+            self.assertEqual(f.attrs['foo'], 42, 'mode a'+msg)
+            f.attrs['baz'] = 44
+            self.assertEqual(f.attrs['baz'], 44, 'mode a'+msg)
+            f.close()
+
+        # mode w
+        f = h5py.File(fname, 'w', driver=driver, **kwds)
+        self.assertEqual(len(f.attrs), 0, 'mode w'+msg)
+        f.attrs['foo'] = 24
+        self.assertEqual(f.attrs['foo'], 24, 'mode w'+msg)
         f.close()
-        os.unlink(tmpname)
+
+        # mode w-
+        if driver == 'core' and h5py.version.hdf5_version_tuple[0:2] == (1,6):
+            self.assertRaises(NotImplementedError, h5py.File, fname, 'w-', driver=driver, **kwds)
+        else:
+            self.assertRaisesMsg('mode w-'+msg, IOError, h5py.File, fname, 'w-', driver=driver, **kwds)
+            newname = res.get_name(suffix)
+            f = h5py.File(newname, 'w-', driver=driver, **kwds)
+            self.assertEqual(len(f.attrs), 0, 'mode w-'+msg)
+            f.attrs['foo'] = 24
+            self.assertEqual(f.attrs['foo'], 24, 'mode w-'+msg)
+            f.close()
+           
+    def test_drivers(self):
+        
+        # Test generic operations
+        for driver in [None, 'sec2', 'stdio', 'core']:
+            self.mode_tester(driver)
+
+        # Test family driver
+        self.mode_tester('family', suffix='_%d.hdf5')
+        self.mode_tester('family', suffix='_%d.hdf5', memb_size=100*(1024.**2))
+
+        # Keyword tests for core driver
+        def leaves_backing(**kwds):     
+            fname = res.get_name()
+            f = h5py.File(fname, 'w', driver='core', **kwds)
+            f.attrs['foo'] = 42
+            f.close()
+            if not op.exists(fname):
+                return False
+            f = h5py.File(fname, 'r')
+            self.assert_('foo' in f.attrs)
+            self.assertEqual(f.attrs['foo'], 42)
+            f.close()
+            return True
+
+        self.assertTrue(leaves_backing())
+        self.assertTrue(leaves_backing(backing_store=True))
+        self.assertFalse(leaves_backing(backing_store=False))
 
     def test_File_close(self):
         f = File(self.fname, 'r')
@@ -169,6 +224,36 @@ class TestFile(HDF5TestCase):
             grp.id._close()
             str(grp.attrs)
 
+    def test_attr_dictcompat(self):
+        # Test dictionary interface
+
+        f = h5py.File(res.get_name(), 'w')
+
+        values = {'a': 42, 'b': "hello", 'c': -32}
+    
+        self.assertRaises(KeyError, f.attrs.__getitem__, 'foo')
+        self.assert_(not 'foo' in f.attrs)
+
+        for key, val in values.iteritems():
+            f.attrs[key] = val
+            self.assert_(key in f.attrs)
+
+        self.assertEqual(len(values), len(f.attrs))
+
+        def assert_cmp_equal(what):
+            c1 = getattr(f.attrs, what)
+            c2 = getattr(values, what)
+            self.assertEqual(set(c1()), set(c2()), what)
+
+        for w in ['keys', 'values', 'items', 'iterkeys', 'itervalues', 'iteritems']:
+            assert_cmp_equal(w)
+
+        self.assertEqual(f.attrs.get('a', 99), 42)
+        self.assertEqual(f.attrs.get('foo', 99), 99)
+    
+        del f.attrs['a']
+        self.assert_(not 'a' in f.attrs)
+
 class TestDataset(HDF5TestCase):
 
     def setUp(self):
@@ -249,7 +334,7 @@ class TestDataset(HDF5TestCase):
                 self.assert_(numpy.all(ds[...] == newarr))
 
             for illegal_shape in illegal_shapes[shape]:
-                self.assertRaises(H5Error, ds.resize, illegal_shape)
+                self.assertRaises(ValueError, ds.resize, illegal_shape)
 
     def test_Dataset_len_iter(self):
         """ Test new and old len(), iteration over rows """
@@ -345,7 +430,7 @@ class TestDataset(HDF5TestCase):
         ref = numpy.ones((10,10), dtype='<i4')
         dsid = self.f.create_dataset('ds', data=ref)
         arr = numpy.ndarray((10,10), dtype='|S6') # incompatible datatype
-        self.assertRaises(H5Error, dsid.id.read, h5s.ALL, h5s.ALL, arr)
+        self.assertRaises(TypeError, dsid.id.read, h5s.ALL, h5s.ALL, arr)
         # or it'll segfault...
 
 class TestExceptions(HDF5TestCase):
@@ -431,7 +516,7 @@ class TestGroup(HDF5TestCase):
 
         grp = self.f.create_group("NewGroup")
         self.assert_("NewGroup" in self.f)
-        self.assertRaises(H5Error, self.f.create_group, "NewGroup")
+        self.assertRaises(ValueError, self.f.create_group, "NewGroup")
 
     def test_Group_create_dataset(self):
 
diff --git a/h5py/tests/test_utils.py b/h5py/tests/test_utils.py
index 0ef759f..1c31508 100644
--- a/h5py/tests/test_utils.py
+++ b/h5py/tests/test_utils.py
@@ -16,7 +16,6 @@ from common import HDF5TestCase, api_18
 
 from h5py import *
 from h5py import utils
-from h5py.h5 import H5Error
 
 class TestUtils(HDF5TestCase):
 

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