~ubuntu-branches/ubuntu/precise/h5py/precise

« back to all changes in this revision

Viewing changes to h5py/tests/low/test_h5a.py

  • Committer: Bazaar Package Importer
  • Author(s): Soeren Sonnenburg
  • Date: 2010-03-23 15:38:34 UTC
  • mfrom: (3.1.1 sid)
  • Revision ID: james.westby@ubuntu.com-20100323153834-ysfm9nsr8gdnkid3
Tags: 1.3.0-1
* New upstream version.
  - Remove quilt patches.
  - Bump standards version to 3.8.4 (no changes required).
  - Switch to dpkg-source 3.0 (quilt) format.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#+
 
2
 
3
# This file is part of h5py, a low-level Python interface to the HDF5 library.
 
4
 
5
# Copyright (C) 2008 Andrew Collette
 
6
# http://h5py.alfven.org
 
7
# License: BSD  (See LICENSE.txt for full license)
 
8
 
9
# $Date$
 
10
 
11
#-
 
12
 
 
13
import numpy as np
 
14
from h5py import tests
 
15
 
 
16
from h5py import *
 
17
 
 
18
def isattr(aid):
 
19
    return aid and h5i.get_type(aid) == h5i.ATTR
 
20
 
 
21
class TestCreate(tests.HTest):
 
22
 
 
23
    def setUp(self):
 
24
        self.fid, self.name = tests.gettemp()
 
25
        self.sid = h5s.create_simple((1,))
 
26
 
 
27
    def tearDown(self):
 
28
        import os
 
29
        self.fid.close()
 
30
        os.unlink(self.name)
 
31
 
 
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))
 
36
    
 
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))
 
45
 
 
46
    def test_exc_1(self):
 
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)
 
51
 
 
52
    @tests.require(api=18)
 
53
    def test_exc_2(self):
 
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')
 
57
 
 
58
class TestOpenExists(tests.HTest):
 
59
 
 
60
    def setUp(self):
 
61
        self.fid, self.name = tests.gettemp()
 
62
        tid = h5t.STD_I32LE
 
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)
 
67
 
 
68
    def tearDown(self):
 
69
        self.fid.close()
 
70
        import os
 
71
        os.unlink(self.name)
 
72
 
 
73
    def test_open_1(self):
 
74
        """ (H5A) Open by name """
 
75
        aid = h5a.open(self.fid, 'name')
 
76
        self.assert_(isattr(aid))
 
77
 
 
78
    def test_open_2(self):
 
79
        """ (H5A) Open by index """
 
80
        aid = h5a.open(self.fid, index=0)
 
81
        self.assert_(isattr(aid))
 
82
 
 
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))
 
89
    
 
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)
 
94
 
 
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)
 
101
 
 
102
    def test_exc_1(self):
 
103
        """ (H5A) Open with wrong name causes KeyError """
 
104
        self.assertRaises(KeyError, h5a.open, self.fid, 'missing')
 
105
 
 
106
    #def test_exc_2(self):
 
107
    #    """ (H5A) Open with wrong index causes ValueError """
 
108
    #    self.assertRaises(ValueError, h5a.open, self.fid, index=2)
 
109
 
 
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')
 
114
 
 
115