[h5py] 361/455: Port Group tests
Ghislain Vaillant
ghisvail-guest at moszumanska.debian.org
Thu Jul 2 18:19:51 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 fad2b5f9de67ad77a2aa6125a2c21332a5206019
Author: andrewcollette <andrew.collette at gmail.com>
Date: Mon Jan 11 00:55:28 2010 +0000
Port Group tests
---
h5py/tests/__init__.py | 32 +++++++++++++++--------
h5py/tests/test_group.py | 61 --------------------------------------------
h5py/tests/test_highlevel.py | 35 -------------------------
3 files changed, 22 insertions(+), 106 deletions(-)
diff --git a/h5py/tests/__init__.py b/h5py/tests/__init__.py
index 89d91c4..c646127 100644
--- a/h5py/tests/__init__.py
+++ b/h5py/tests/__init__.py
@@ -92,20 +92,23 @@ class HTest(unittest.TestCase):
import warnings
filters = warnings.filters
warnings.simplefilter("ignore")
+ objcount = h5py.h5f.get_obj_count()
try:
unittest.TestCase.run(self, *args, **kwds)
finally:
warnings.filters = filters
- if 0 and h5py.h5f.get_obj_count() != 0:
- print "WARNING: %d LEFTOVER IDS" % h5py.h5f.get_obj_count()
- ids = h5py.h5f.get_obj_ids()
- for id_ in ids:
- if id_:
- print "Closing %r" % id_
- else:
- print "Skipping %r" % id_
- while id_ and h5py.h5i.get_ref(id_) > 0:
- h5py.h5i.dec_ref(id_)
+ newcount = h5py.h5f.get_obj_count()
+ if newcount != objcount:
+ print "WARNING: LEAKED %d IDs (total %d)" % (newcount-objcount, newcount)
+ if 0:
+ ids = h5py.h5f.get_obj_ids()
+ for id_ in ids:
+ if id_:
+ print "Closing %r" % id_
+ else:
+ print "Skipping %r" % id_
+ while id_ and h5py.h5i.get_ref(id_) > 0:
+ h5py.h5i.dec_ref(id_)
def assertArrayEqual(self, dset, arr, message=None, precision=None):
""" Make sure dset and arr have the same shape, dtype and contents, to
@@ -129,5 +132,14 @@ class HTest(unittest.TestCase):
assert dset.dtype == arr.dtype, "Dtype mismatch (%s vs %s)%s" % (dset.dtype, arr.dtype, message)
assert np.all(np.abs(dset[...] - arr[...]) < precision), "Arrays differ by more than %.3f%s" % (precision, message)
+ def assertIsInstance(self, obj, typ):
+ """ Check if obj is an instance of typ """
+ if not isinstance(obj, typ):
+ raise AssertionError("instance of %s not %s" % (type(obj).__name__, typ.__name__))
+ def assertEqualContents(self, a, b):
+ a = list(a)
+ b = list(b)
+ if not len(a) == len(b) and set(a) == set(b):
+ raise AssertionError("contents don't match: %s vs %s" % (list(a), list(b)))
diff --git a/h5py/tests/test_group.py b/h5py/tests/test_group.py
index 20e6a68..029843d 100644
--- a/h5py/tests/test_group.py
+++ b/h5py/tests/test_group.py
@@ -44,73 +44,12 @@ class TestInit(GroupBase):
self.assertEqual(grp.name, "/NewGroup")
- def test_Group_create_group(self):
-
- grp = self.f.create_group("NewGroup")
- self.assert_("NewGroup" in self.f)
- self.assertRaises(ValueError, self.f.create_group, "NewGroup")
-
def test_Group_create_dataset(self):
ds = self.f.create_dataset("Dataset", shape=(10,10), dtype='<i4')
self.assert_(isinstance(ds, h5py.Dataset))
self.assert_("Dataset" in self.f)
-class TestSpecial(GroupBase):
-
- """ Special methods """
-
- subgroups = ["Name1", " Name 1231987&*@&^*&#W 2 \t\t ",
- "name3", "14", "!"]
-
- def setUp(self):
- GroupBase.setUp(self)
- for name in self.subgroups:
- self.f.create_group(name)
-
- def test_len(self):
- self.assertEqual(len(self.f), len(self.subgroups))
-
- def test_contains(self):
- for name in self.subgroups:
- self.assert_(name in self.f)
- self.assert_("missing" not in self.f)
-
- def test_iter(self):
- self.assert_equal_contents(self.f, self.subgroups)
-
- def test_dictcompat(self):
-
- # Old style -- now deprecated
- with dump_warnings():
- self.assert_equal_contents(self.f.listnames(), self.subgroups)
- self.assert_equal_contents(self.f.listobjects(), [self.f[x] for x in self.subgroups])
- self.assert_equal_contents(self.f.listitems(), [(x, self.f[x]) for x in self.subgroups])
- self.assert_equal_contents(list(self.f.iternames()), self.subgroups)
- self.assert_equal_contents(list(self.f.iterobjects()), [self.f[x] for x in self.subgroups])
-
- # New style
- self.assert_equal_contents(self.f.keys(), self.subgroups)
- self.assert_equal_contents(self.f.values(), [self.f[x] for x in self.subgroups])
- self.assert_equal_contents(self.f.items(), [(x, self.f[x]) for x in self.subgroups])
- self.assert_equal_contents(list(self.f.iteritems()), [(x, self.f[x]) for x in self.subgroups])
-
-
- def test_del(self):
- names = list(self.subgroups)
- for name in self.subgroups:
- names.remove(name)
- del self.f[name]
- self.assert_equal_contents(self.f, names)
-
- def test_str_repr(self):
- g = self.f.create_group("Foobar")
- s = str(g)
- r = repr(g)
- self.assert_(isinstance(s, str),s)
- self.assert_(isinstance(r, str),r)
- self.assert_(r.startswith('<') and r.endswith('>'),r)
-
class TestSetItem(GroupBase):
""" Behavior of Group.__setitem__ """
diff --git a/h5py/tests/test_highlevel.py b/h5py/tests/test_highlevel.py
index 99dceef..e2a61ed 100644
--- a/h5py/tests/test_highlevel.py
+++ b/h5py/tests/test_highlevel.py
@@ -298,46 +298,11 @@ class TestExceptions(TestCasePlus):
self.f.create_group("foobar")
self.assertRaises(ValueError, self.f.create_group, "foobar")
- def test_files(self):
-
- self.f.create_group("foobar")
- self.f.close()
-
- valerrors = {"__getitem__": ("foobar",),
- "create_group": ("foobar",),
- "create_dataset": ("foobar", (), 'i'),}
-
- for meth, args in valerrors.iteritems():
- self.assertRaises(ValueError, getattr(self.f, meth), *args)
-
def test_attributes(self):
g = self.f.create_group("foobar")
self.assertRaises(KeyError, g.attrs.__getitem__, "attr")
- def test_mode(self):
-
- fname = tempfile.mktemp('hdf5')
- try:
- f = File(fname,'w')
- g = f.create_group("foobar")
- g.attrs["attr"] = 42
- f.close()
-
- f = File(fname, 'r')
- g = f["foobar"]
- self.assertRaises(IOError, g.attrs.__setitem__, "attr", 43)
- f.close()
- finally:
- try:
- f.close()
- except Exception:
- pass
- os.unlink(fname)
-
-
-
-
class TestTypes(TestCasePlus):
def setUp(self):
--
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