3
# This file is part of h5py, a low-level Python interface to the HDF5 library.
5
# Copyright (C) 2008 Andrew Collette
6
# http://h5py.alfven.org
7
# License: BSD (See LICENSE.txt for full license)
14
from h5py import tests
19
return aid and h5i.get_type(aid) == h5i.ATTR
21
class TestCreate(tests.HTest):
24
self.fid, self.name = tests.gettemp()
25
self.sid = h5s.create_simple((1,))
32
def test_create_1(self):
33
""" (H5A) Create attribute from type and space """
34
aid = h5a.create(self.fid, 'name', h5t.STD_I32LE, self.sid)
35
self.assert_(isattr(aid))
37
@tests.require(api=18)
38
def test_create_2(self):
39
""" (H5A) Create attribute on group member w/custom LAPL """
40
gid = h5g.create(self.fid, 'subgroup')
41
lapl = h5p.create(h5p.LINK_ACCESS)
42
aid = h5a.create(self.fid, 'name', h5t.STD_I32LE, self.sid,
43
obj_name='subgroup', lapl=lapl)
44
self.assert_(isattr(aid))
47
""" (H5A) Existing name causes ValueError """
48
h5a.create(self.fid, 'name', h5t.STD_I32LE, self.sid)
49
self.assertRaises(ValueError, h5a.create, self.fid, 'name',
50
h5t.STD_I32LE, self.sid)
52
@tests.require(api=18)
54
""" (H5A) Wrong obj_name causes KeyError """
55
self.assertRaises(KeyError, h5a.create, self.fid, 'name',
56
h5t.STD_I32LE, self.sid, obj_name='missing')
58
class TestOpenExists(tests.HTest):
61
self.fid, self.name = tests.gettemp()
63
sid = h5s.create_simple((1,))
64
h5a.create(self.fid, 'name', tid, sid)
65
gid = h5g.create(self.fid, 'subgroup')
66
h5a.create(gid, 'othername', tid, sid)
73
def test_open_1(self):
74
""" (H5A) Open by name """
75
aid = h5a.open(self.fid, 'name')
76
self.assert_(isattr(aid))
78
def test_open_2(self):
79
""" (H5A) Open by index """
80
aid = h5a.open(self.fid, index=0)
81
self.assert_(isattr(aid))
83
@tests.require(api=18)
84
def test_open_3(self):
85
""" (H5A) Open from group member w/custom LAPL """
86
lapl = h5p.create(h5p.LINK_ACCESS)
87
aid = h5a.open(self.fid, 'othername', obj_name='subgroup', lapl=lapl)
88
self.assert_(isattr(aid))
90
def test_exists_1(self):
91
""" (H5A) Check exists by name """
92
self.assert_(h5a.exists(self.fid, 'name') is True)
93
self.assert_(h5a.exists(self.fid, 'missing') is False)
95
@tests.require(api=18)
96
def test_exists_2(self):
97
""" (H5A) Check exists on group member with custom LAPL """
98
lapl = h5p.create(h5p.LINK_ACCESS)
99
self.assert_(h5a.exists(self.fid, 'othername', obj_name='subgroup', lapl=lapl) is True)
100
self.assert_(h5a.exists(self.fid, 'missing', obj_name='subgroup', lapl=lapl) is False)
102
def test_exc_1(self):
103
""" (H5A) Open with wrong name causes KeyError """
104
self.assertRaises(KeyError, h5a.open, self.fid, 'missing')
106
#def test_exc_2(self):
107
# """ (H5A) Open with wrong index causes ValueError """
108
# self.assertRaises(ValueError, h5a.open, self.fid, index=2)
110
@tests.require(api=18)
111
def test_exc_3(self):
112
""" (H5A) Open with wrong subgroup causes KeyError """
113
self.assertRaises(KeyError, h5a.open, self.fid, 'othername', obj_name='missing')