def test_h5py_dataset_typecheck(): ds = datasets['uni2small'] fd, fpath = tempfile.mkstemp('mvpa', 'test') os.close(fd) fd, fpath2 = tempfile.mkstemp('mvpa', 'test') os.close(fd) h5save(fpath2, [[1, 2, 3]]) assert_raises(ValueError, AttrDataset.from_hdf5, fpath2) # this one just catches if there is such a group assert_raises(ValueError, AttrDataset.from_hdf5, fpath2, name='bogus') hdf = h5py.File(fpath, 'w') ds = AttrDataset([1, 2, 3]) obj2hdf(hdf, ds, name='non-bogus') obj2hdf(hdf, [1, 2, 3], name='bogus') hdf.close() assert_raises(ValueError, AttrDataset.from_hdf5, fpath, name='bogus') ds_loaded = AttrDataset.from_hdf5(fpath, name='non-bogus') assert_array_equal(ds, ds_loaded) # just to do smth useful with ds ;) # cleanup and ignore stupidity os.remove(fpath) os.remove(fpath2)
def test_h5py_dataset_typecheck(): ds = datasets["uni2small"] fd, fpath = tempfile.mkstemp("mvpa", "test") os.close(fd) fd, fpath2 = tempfile.mkstemp("mvpa", "test") os.close(fd) h5save(fpath2, [[1, 2, 3]]) assert_raises(ValueError, AttrDataset.from_hdf5, fpath2) # this one just catches if there is such a group assert_raises(ValueError, AttrDataset.from_hdf5, fpath2, name="bogus") hdf = h5py.File(fpath, "w") ds = AttrDataset([1, 2, 3]) obj2hdf(hdf, ds, name="non-bogus") obj2hdf(hdf, [1, 2, 3], name="bogus") hdf.close() assert_raises(ValueError, AttrDataset.from_hdf5, fpath, name="bogus") ds_loaded = AttrDataset.from_hdf5(fpath, name="non-bogus") assert_array_equal(ds, ds_loaded) # just to do smth useful with ds ;) # cleanup and ignore stupidity os.remove(fpath) os.remove(fpath2)