Skip to content

Commit ff5c639

Browse files
committed
move to bald__latest
1 parent 515ebd6 commit ff5c639

File tree

4 files changed

+66
-29
lines changed

4 files changed

+66
-29
lines changed

lib/bald/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ def validate_hdf5(afilepath):
135135
sattrs = dict(fhandle.attrs).copy()
136136
sattrs.update(dataset.attrs)
137137
dset = Subject(sattrs)
138-
dset_val = bv.DatasetValidation(name, dataset, fhandle=fhandle,
138+
dset_val = bv.ArrayValidation(name, dataset, fhandle=fhandle,
139139
subject=dset)
140140
sval.stored_exceptions += dset_val.exceptions()
141141

lib/bald/tests/integration/test_netcdf.py

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,21 @@
88
from bald.tests import BaldTestCase
99

1010
def _fattrs(f):
11-
f.bald__ = 'http://binary-array-ld.net/experimental/'
11+
f.bald__ = 'http://binary-array-ld.net/latest/'
1212
f.rdf__ = 'http://www.w3.org/1999/02/22-rdf-syntax-ns#'
1313
f.rdf__type = 'bald__Container'
1414
return f
1515

16+
# def _create_parent_child(f, pshape, cshape):
17+
# dsetp = f.create_dataset("parent_dataset", pshape, dtype='i')
18+
# dsetc = f.create_dataset("child_dataset", cshape, dtype='i')
19+
# dsetp.attrs['rdf__type'] = 'bald__Dataset'
20+
# dsetp.attrs['bald__references'] = dsetc.ref
21+
# dsetc.attrs['rdf__type'] = 'bald__Dataset'
22+
# dsetc.attrs['rdf__type'] = 'bald__Reference'
23+
# dsetc.attrs['bald__dataset'] = dsetc.ref
24+
# return f
25+
1626

1727
class Test(BaldTestCase):
1828

@@ -35,6 +45,26 @@ def test_invalid_uri(self):
3545
validation = bald.validate_netcdf(tfile)
3646
self.assertFalse(validation.is_valid())
3747

48+
# class TestArrayReference(BaldTestCase):
49+
# def test_match(self):
50+
# with self.temp_filename('.nc') as tfile:
51+
# f = netCDF4.Dataset(tfile, "w", format="NETCDF4")
52+
# f = _fattrs(f)
53+
# f = _create_parent_child(f, (11, 17), (11, 17))
54+
# f.close()
55+
# validation = bald.validate_netcdf(tfile)
56+
# self.assertTrue(validation.is_valid())
57+
58+
# def test_mismatch_zeroth(self):
59+
# with self.temp_filename('.nc') as tfile:
60+
# f = netCDF4.Dataset(tfile, "w", format="NETCDF4")
61+
# f = _fattrs(f)
62+
# f = _create_parent_child(f, (11, 17), (11, 13))
63+
# f.close()
64+
# validation = bald.validate_netcdf(tfile)
65+
# self.assertFalse(validation.is_valid())
66+
67+
3868

3969
if __name__ == '__main__':
4070
unittest.main()

lib/bald/tests/integration/test_validation.py

Lines changed: 22 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -7,19 +7,19 @@
77
from bald.tests import BaldTestCase
88

99
def _fattrs(f):
10-
f.attrs['bald__'] = 'http://binary-array-ld.net/experimental/'
10+
f.attrs['bald__'] = 'http://binary-array-ld.net/latest/'
1111
f.attrs['rdf__'] = 'http://www.w3.org/1999/02/22-rdf-syntax-ns#'
1212
f.attrs['rdf__type'] = 'bald__Container'
1313
return f
1414

1515
def _create_parent_child(f, pshape, cshape):
1616
dsetp = f.create_dataset("parent_dataset", pshape, dtype='i')
1717
dsetc = f.create_dataset("child_dataset", cshape, dtype='i')
18-
dsetp.attrs['rdf__type'] = 'bald__Dataset'
18+
dsetp.attrs['rdf__type'] = 'bald__Array'
1919
dsetp.attrs['bald__references'] = dsetc.ref
20-
dsetc.attrs['rdf__type'] = 'bald__Dataset'
20+
dsetc.attrs['rdf__type'] = 'bald__Array'
2121
dsetc.attrs['rdf__type'] = 'bald__Reference'
22-
dsetc.attrs['bald__dataset'] = dsetc.ref
22+
dsetc.attrs['bald__array'] = dsetc.ref
2323
return f
2424

2525

@@ -31,7 +31,8 @@ def test_valid_uri(self):
3131
f = _fattrs(f)
3232
f = _create_parent_child(f, (11, 17), (11, 17))
3333
f.close()
34-
self.assertTrue(bald.validate_hdf5(tfile).is_valid())
34+
validation = bald.validate_hdf5(tfile)
35+
self.assertTrue(validation.is_valid())
3536

3637
def test_invalid_uri(self):
3738
with self.temp_filename('.hdf') as tfile:
@@ -40,7 +41,8 @@ def test_invalid_uri(self):
4041
f = _create_parent_child(f, (11, 17), (11, 17))
4142
f.attrs['bald__turtle'] = 'bald__walnut'
4243
f.close()
43-
self.assertFalse(bald.validate_hdf5(tfile).is_valid())
44+
validation = bald.validate_hdf5(tfile)
45+
self.assertFalse(validation.is_valid())
4446

4547
class TestArrayReference(BaldTestCase):
4648
def test_match(self):
@@ -49,23 +51,26 @@ def test_match(self):
4951
f = _fattrs(f)
5052
f = _create_parent_child(f, (11, 17), (11, 17))
5153
f.close()
52-
self.assertTrue(bald.validate_hdf5(tfile).is_valid())
54+
validation = bald.validate_hdf5(tfile)
55+
self.assertTrue(validation.is_valid())
5356

5457
def test_mismatch_zeroth(self):
5558
with self.temp_filename('.hdf') as tfile:
5659
f = h5py.File(tfile, "w")
5760
f = _fattrs(f)
5861
f = _create_parent_child(f, (11, 17), (11, 13))
5962
f.close()
60-
self.assertFalse(bald.validate_hdf5(tfile).is_valid())
63+
validation = bald.validate_hdf5(tfile)
64+
self.assertFalse(validation.is_valid())
6165

6266
def test_mismatch_oneth(self):
6367
with self.temp_filename('.hdf') as tfile:
6468
f = h5py.File(tfile, "w")
6569
f = _fattrs(f)
6670
f = _create_parent_child(f, (11, 17), (13, 17))
6771
f.close()
68-
self.assertFalse(bald.validate_hdf5(tfile).is_valid())
72+
validation = bald.validate_hdf5(tfile)
73+
self.assertFalse(validation.is_valid())
6974

7075
def test_match_plead_dim(self):
7176
with self.temp_filename('.hdf') as tfile:
@@ -74,7 +79,8 @@ def test_match_plead_dim(self):
7479
# parent has leading dimension wrt child
7580
f = _create_parent_child(f, (4, 13, 17), (13, 17))
7681
f.close()
77-
self.assertTrue(bald.validate_hdf5(tfile).is_valid())
82+
validation = bald.validate_hdf5(tfile)
83+
self.assertTrue(validation.is_valid())
7884

7985
def test_match_clead_dim(self):
8086
with self.temp_filename('.hdf') as tfile:
@@ -83,7 +89,8 @@ def test_match_clead_dim(self):
8389
# child has leading dimension wrt parent
8490
f = _create_parent_child(f, (13, 17), (7, 13, 17))
8591
f.close()
86-
self.assertTrue(bald.validate_hdf5(tfile).is_valid())
92+
validation = bald.validate_hdf5(tfile)
93+
self.assertTrue(validation.is_valid())
8794

8895
def test_mismatch_pdisjc_lead_dim(self):
8996
with self.temp_filename('.hdf') as tfile:
@@ -93,7 +100,8 @@ def test_mismatch_pdisjc_lead_dim(self):
93100
f = _create_parent_child(f, (4, 13, 17), (7, 13, 17))
94101

95102
f.close()
96-
self.assertFalse(bald.validate_hdf5(tfile).is_valid())
103+
validation = bald.validate_hdf5(tfile)
104+
self.assertFalse(validation.is_valid())
97105

98106
def test_mismatch_pdisjc_trail_dim(self):
99107
with self.temp_filename('.hdf') as tfile:
@@ -102,8 +110,8 @@ def test_mismatch_pdisjc_trail_dim(self):
102110
# child and parent have disjoint trailing dimensions
103111
f = _create_parent_child(f, (13, 17, 2), (13, 17, 9))
104112
f.close()
105-
self.assertFalse(bald.validate_hdf5(tfile).is_valid())
106-
113+
validation = bald.validate_hdf5(tfile)
114+
self.assertFalse(validation.is_valid())
107115

108116

109117
# def test_match_(self):

lib/bald/validation.py

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,6 @@ def exceptions(self):
5959

6060

6161
class SubjectValidation(Validation):
62-
6362
def __init__(self, subject, fhandle, httpcache=None):
6463
self.subject = subject
6564
self.fhandle = fhandle
@@ -145,39 +144,39 @@ def __init__(self, **kwargs):
145144
super(ContainerValidation, self).__init__(**kwargs)
146145

147146

148-
class DatasetValidation(SubjectValidation):
147+
class ArrayValidation(SubjectValidation):
149148

150-
def __init__(self, name, dataset, **kwargs):
151-
self.dataset = dataset
149+
def __init__(self, name, array, **kwargs):
150+
self.array = array
152151
self.name = name
153-
super(DatasetValidation, self).__init__(**kwargs)
152+
super(ArrayValidation, self).__init__(**kwargs)
154153

155154
def _extra_exceptions(self, exceptions):
156155
exceptions = self.check_array_references(exceptions)
157156
return exceptions
158157

159158
def check_array_references(self, exceptions):
160-
def _check_ref(pdataset, parray, cdataset, carray):
159+
def _check_ref(parraysubj, parray, carraysubj, carray):
161160
if not valid_array_reference(parray, carray):
162161
msg = ('{} declares a child of {} but the arrays'
163162
'do not conform to the bald array reference'
164163
'rules')
165-
msg = msg.format(pdataset, cdataset)
164+
msg = msg.format(parraysubj, carraysubj)
166165
exceptions.append(ValueError(msg))
167166
return exceptions
168167

169-
# if this Dataset has a bald__references
168+
# if this Array has a bald__references
170169
# not implemented yet: and it's a singleton
171170
if self.subject.attrs.get('bald__references', ''):
172-
# then it must have a bald_dataset
171+
# then it must have a bald_array
173172
ref_dset = self.fhandle[self.subject.attrs.get('bald__references')]
174-
if not ref_dset.attrs.get('bald__dataset', ''):
173+
if not ref_dset.attrs.get('bald__array', ''):
175174
exceptions.append(ValueError('A bald__Reference must link to '
176-
'one and only one bald__Dataset'))
175+
'one and only one bald__Array'))
177176
else:
178177
# and we impose bald broadcasting rules on it
179-
child_dset = self.fhandle[ref_dset.attrs.get('bald__dataset')]
180-
parray = np.zeros(self.dataset.shape)
178+
child_dset = self.fhandle[ref_dset.attrs.get('bald__array')]
179+
parray = np.zeros(self.array.shape)
181180
carray = np.zeros(child_dset.shape)
182181

183182
exceptions = _check_ref('p', parray, 'c', carray)

0 commit comments

Comments
 (0)