[h5py] 362/455: Add test_group.py
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 522a6a800f4c9f99c3b822c67cdd3c7648d197f1
Author: andrewcollette <andrew.collette at gmail.com>
Date: Mon Jan 11 00:55:55 2010 +0000
Add test_group.py
---
h5py/tests/high/test_group.py | 120 ++++++++++++++++++++++++++++++++++++++++++
1 file changed, 120 insertions(+)
diff --git a/h5py/tests/high/test_group.py b/h5py/tests/high/test_group.py
new file mode 100644
index 0000000..904df01
--- /dev/null
+++ b/h5py/tests/high/test_group.py
@@ -0,0 +1,120 @@
+
+from tempfile import mktemp
+from h5py import tests
+import h5py
+
+class GroupBase(tests.HTest):
+
+ def setUp(self):
+ import tempfile
+ self.name = tempfile.mktemp()
+ self.f = h5py.File(self.name, 'w')
+
+ def tearDown(self):
+ import os
+ self.f.close()
+ os.unlink(self.name)
+
+class TestCreate(GroupBase):
+
+ def test_create(self):
+ """ (Group) Create group """
+ self.f.create_group('new')
+ self.assert_('new' in self.f)
+ g = self.f['new']
+ self.assertIsInstance(g, h5py.Group)
+ self.assertEqual(g.name, '/new')
+
+ def test_conflict(self):
+ """ (Group) Create with existing name raises ValueError """
+ self.f.create_group('new')
+ self.assertRaises(ValueError, self.f.create_group, 'new')
+
+ def test_require(self):
+ """ (Group) Create with require_group() """
+ g = self.f.require_group('new')
+ self.assertIsInstance(g, h5py.Group)
+ self.assert_('new' in self.f)
+ g2 = self.f.require_group('new')
+ self.assertEqual(g, g2)
+
+ def test_require_exc(self):
+ """ (Group) require_group() raises TypeError with incompatible object """
+ ds = self.f.create_dataset('new', (1,), 'f')
+ self.assertRaises(TypeError, self.f.require_group, 'new')
+
+ def test_del(self):
+ """ (Group) del """
+ self.f.create_group('new')
+ self.assert_('new' in self.f)
+ del self.f['new']
+ self.assert_('new' not in self.f)
+
+ @tests.fixme
+ def test_del_exc(self):
+ """ (Group) del raises KeyError for missing item """
+ self.assertRaises(KeyError, self.f.__delitem__, 'new')
+
+ def test_repr(self):
+ """ (Group) repr() """
+ g = self.f.create_group('new')
+ repr(g)
+ g.id._close()
+ repr(g)
+
+ def test_bool(self):
+ """ (Group) nonzero() """
+ g = self.f.create_group('new')
+ self.assert_(g)
+ g.id._close()
+ self.assert_(not g)
+
+class TestDict2(GroupBase):
+
+ def setUp(self):
+ GroupBase.setUp(self)
+ self.groups = ('a','b','c','d')
+ for x in self.groups:
+ self.f.create_group(x)
+
+ def test_len(self):
+ """ (Group) len() """
+ self.assertEqual(len(self.f), len(self.groups))
+ self.f.create_group('e')
+ self.assertEqual(len(self.f), len(self.groups)+1)
+
+ def test_contains(self):
+ """ (Group) __contains__ for absolute and relative paths"""
+ self.assert_(not 'new' in self.f)
+ g = self.f.create_group('new')
+ self.assert_('new' in self.f)
+ self.f.create_group('new/subgroup')
+ self.assert_('subgroup' in g)
+ self.assert_('/new/subgroup' in g)
+
+ def test_iter(self):
+ """ (Group) Iteration yields member names"""
+ self.assertEqualContents(self.groups, self.f)
+
+ def test_old(self):
+ """ (Group) Deprecated dict interface """
+ self.assertEqualContents(self.f.listnames(), self.groups)
+ self.assertEqualContents(self.f.listobjects(), [self.f[x] for x in self.groups])
+ self.assertEqualContents(self.f.listitems(), [(x, self.f[x]) for x in self.groups])
+ self.assertEqualContents(list(self.f.iternames()), self.groups)
+ self.assertEqualContents(list(self.f.iterobjects()), [self.f[x] for x in self.groups])
+
+ def test_new(self):
+ """ (Group) New dict interface """
+ self.assertIsInstance(self.f.keys(), list)
+ self.assertEqualContents(self.f.keys(), self.groups)
+
+ self.assertIsInstance(self.f.values(), list)
+ self.assertEqualContents(self.f.values(), [self.f[x] for x in self.groups])
+
+ self.assertEqualContents(self.f.iteritems(), [(x,self.f[x]) for x in self.groups])
+ self.assertEqualContents(self.f.iterkeys(), self.f)
+ self.assertEqualContents(self.f.itervalues(), [self.f[x] for x in self.groups])
+
+
+
--
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