| 1 |
import os |
| 2 |
from shutil import copyfile |
| 3 |
|
| 4 |
from hdmf.backends.hdf5.h5tools import HDF5IO |
| 5 |
from tests.unit.helpers.utils import Foo, FooBucket, get_foo_buildmanager |
| 6 |
from hdmf.testing import TestCase |
| 7 |
|
| 8 |
|
| 9 |
class Test1_1_0(TestCase): |
| 10 |
|
| 11 |
def setUp(self): |
| 12 |
# created using manager in test_io_hdf5_h5tools |
| 13 |
self.orig_1_0_5 = 'tests/unit/back_compat_tests/1.0.5.h5' |
| 14 |
self.path_1_0_5 = 'test_1.0.5.h5' |
| 15 |
copyfile(self.orig_1_0_5, self.path_1_0_5) |
| 16 |
|
| 17 |
# note: this may break if the current manager is different from the old manager |
| 18 |
# better to save a spec file |
| 19 |
self.manager = get_foo_buildmanager() |
| 20 |
|
| 21 |
def tearDown(self): |
| 22 |
if os.path.exists(self.path_1_0_5): |
| 23 |
os.remove(self.path_1_0_5) |
| 24 |
|
| 25 |
def test_read_1_0_5(self): |
| 26 |
'''Test whether we can read files made by hdmf version 1.0.5''' |
| 27 |
with HDF5IO(self.path_1_0_5, manager=self.manager, mode='r') as io: |
| 28 |
read_foofile = io.read() |
| 29 |
self.assertTrue(len(read_foofile.buckets) == 1) |
| 30 |
self.assertListEqual(read_foofile.buckets['test_bucket'].foos['foo1'].my_data[:].tolist(), [0, 1, 2, 3, 4]) |
| 31 |
self.assertListEqual(read_foofile.buckets['test_bucket'].foos['foo2'].my_data[:].tolist(), [5, 6, 7, 8, 9]) |
| 32 |
|
| 33 |
def test_append_1_0_5(self): |
| 34 |
'''Test whether we can append to files made by hdmf version 1.0.5''' |
| 35 |
foo = Foo('foo3', [10, 20, 30, 40, 50], "I am foo3", 17, 3.14) |
| 36 |
foobucket = FooBucket('foobucket2', [foo]) |
| 37 |
|
| 38 |
with HDF5IO(self.path_1_0_5, manager=self.manager, mode='a') as io: |
| 39 |
read_foofile = io.read() |
| 40 |
read_foofile.add_bucket(foobucket) |
| 41 |
io.write(read_foofile) |
| 42 |
|
| 43 |
with HDF5IO(self.path_1_0_5, manager=self.manager, mode='r') as io: |
| 44 |
read_foofile = io.read() |
| 45 |
self.assertListEqual(read_foofile.buckets['foobucket2'].foos['foo3'].my_data[:].tolist(), foo.my_data) |