def test_create(): with tmpfile('.hdf5') as fn: ds = datashape.dshape('{x: int32, y: {z: 3 * int32}}') f = create(h5py.File, dshape='{x: int32, y: {z: 3 * int32}}', path=fn) assert isinstance(f, h5py.File) assert f.filename == fn assert discover(f) == ds
def test_resource(): with tmpfile('.hdf5') as fn: os.remove(fn) ds = datashape.dshape('{x: int32, y: 3 * int32}') r = resource(fn, dshape=ds) assert isinstance(r, h5py.File) assert discover(r) == ds
def test_resource_with_datapath(): with tmpfile('.hdf5') as fn: ds = datashape.dshape('3 * 4 * int32') r = resource(fn + '::/data', dshape=ds) assert isinstance(r, h5py.Dataset) assert discover(r) == ds assert r.file.filename == fn assert r.file['/data'] == r
def test_resource(): with tmpfile('.hdf5') as fn: ds = datashape.dshape('{x: int32, y: 3 * int32}') r = resource(fn, dshape=ds) assert isinstance(r, h5py.File) assert discover(r) == ds r2 = resource(fn + '::/x') assert isinstance(r2, h5py.Dataset)
def test_discover_on_data_with_object_in_record_name(): data = np.array([(u'a', 1), (u'b', 2)], dtype=[('lrg_object', unicode_dtype), ('an_int', 'int64')]) with tmpfile('.hdf5') as fn: f = h5py.File(fn) try: f.create_dataset('/data', data=data) except: raise else: assert (discover(f['data']) == datashape.dshape('2 * {lrg_object: string, an_int: int64}')) finally: f.close()
def test_discover(): with file(x) as (fn, f, dset): assert str(discover(dset)) == str(discover(x)) assert str(discover(f)) == str(discover({'data': x}))