Skip to content

Commit afc5180

Browse files
committed
bald
1 parent 285332a commit afc5180

15 files changed

+221
-0
lines changed

lib/bald/__init__.py

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
import h5py
2+
3+
import bald.validation
4+
5+
6+
@contextlib.contextmanager
7+
def load(afilepath):
8+
if afilepath.endswith('.hdf5'):
9+
loader = h5py.File
10+
else:
11+
raise ValueError('filepath suffix not supported')
12+
try:
13+
f = loader(afilepath, "r")
14+
yield f
15+
finally:
16+
f.close()
17+
return f
18+
19+
def validate(afilepath):
20+
"""
21+
Validate a file with respect ot binarry-array-linked-data.
22+
Returns a :class:`bald.validation.Validation`
23+
"""
24+
25+
with load(afilepath) as f:
26+
27+

lib/bald/__init__.pyc

152 Bytes
Binary file not shown.

lib/bald/__init__.py~

Whitespace-only changes.

lib/bald/tests/__init__.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import contextlib
2+
import os
3+
import tempfile
4+
import unittest
5+
6+
7+
class BaldTestCase(unittest.TestCase):
8+
@contextlib.contextmanager
9+
def temp_filename(self, suffix=''):
10+
temp_file = tempfile.mkstemp(suffix)
11+
os.close(temp_file[0])
12+
filename = temp_file[1]
13+
try:
14+
yield filename
15+
finally:
16+
os.remove(filename)

lib/bald/tests/__init__.pyc

894 Bytes
Binary file not shown.

lib/bald/tests/__init__.py~

Whitespace-only changes.

lib/bald/tests/integration/__init__.py

Whitespace-only changes.
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
import unittest
2+
3+
import h5py
4+
import numpy as np
5+
6+
from bald.tests import BaldTestCase
7+
8+
def _fattrs(f):
9+
f.attrs['bald_._'] = 'http://binary_array_ld.net/experimental'
10+
f.attrs['bald_._type'] = 'bald_._Container'
11+
return f
12+
13+
def _create_parent_child(f, pshape, cshape):
14+
dsetp = f.create_dataset("parent_dataset", pshape, dtype='i')
15+
dsetc = f.create_dataset("child_dataset", cshape, dtype='i')
16+
dsetp.attrs['bald_._type'] = 'bald_._Dataset'
17+
dsetp.attrs['bald_._reference'] = dsetc.ref
18+
dsetc.attrs['bald_._type'] = 'bald_._Dataset'
19+
return f
20+
21+
22+
class TestArrayReference(BaldTestCase):
23+
def test_match_array_reference(self):
24+
with self.temp_filename('.hdf') as tfile:
25+
f = h5py.File(tfile, "w")
26+
f = _fattrs(f)
27+
f = _create_parent_child(f, (11, 17), (11, 17))
28+
f.close()
29+
30+
31+
if __name__ == '__main__':
32+
unittest.main()
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
import unittest
2+
3+
import h5py
4+
import numpy as np
5+
6+
from bald.tests import BaldTestCase
7+
8+
def _fattrs(f):
9+
f.attrs.create('bald_._', 'http://binary_array_ld.net/experimental')
10+
f.attrs.create('bald_._type', 'bald_._Container')
11+
# f.attrs['bald_._'] = 'http://binary_array_ld.net/experimental'
12+
# f.attrs['bald_._type'] = 'bald_._Container'
13+
return f
14+
15+
16+
class TestArrayReference(BaldTestCase):
17+
def test_match_array_reference(self):
18+
with self.temp_filename('.hdf') as tfile:
19+
f = h5py.File(tfile, "w")
20+
f = _fattrs(f)
21+
dsetp = f.create_dataset("mydataset", (11, 17), dtype='i')
22+
dsetc = f.create_dataset("mydataset", (11, 17), dtype='i')
23+
dsetp.create('bald_._reference', dsetc.ref)
24+
f.close()
25+
newf = h5py.File(tfile, "r")
26+
import pdb; pdb.set_trace()
27+
nset = newf.get('mydatasetp')
28+
29+
30+
if __name__ == '__main__':
31+
unittest.main()

lib/bald/tests/test_simple.py

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
import unittest
2+
3+
import h5py
4+
import numpy as np
5+
6+
from bald.tests import BaldTestCase
7+
8+
9+
class ATest(BaldTestCase):
10+
def setUp(self):
11+
self.this = 'this'
12+
13+
def test_this(self):
14+
self.assertTrue(self.this, 'this')
15+
16+
def test_make_file(self):
17+
with self.temp_filename('.hdf') as tfile:
18+
f = h5py.File(tfile, "w")
19+
dset = f.create_dataset("mydataset", (100,), dtype='i')
20+
21+
def test_make_load_file(self):
22+
with self.temp_filename('.hdf') as tfile:
23+
f = h5py.File(tfile, "w")
24+
dset = f.create_dataset("mydataset", (100,), dtype='i')
25+
dset.attrs['bald_._'] = 'http://binary_array_ld.net/alpha'
26+
f.close()
27+
newf = h5py.File(tfile, "r")
28+
nset = newf.get('mydataset')
29+
self.assertEqual(nset.shape, (100,))
30+
self.assertEqual(nset.dtype, 'int32')
31+
self.assertEqual(nset.attrs.get('bald_._'),
32+
'http://binary_array_ld.net/alpha')
33+
34+
35+
if __name__ == '__main__':
36+
unittest.main()

0 commit comments

Comments
 (0)