|  | 
| 1 | 1 | import os | 
| 2 | 2 | 
 | 
| 3 | 3 | import numpy as np | 
|  | 4 | +import pytest | 
| 4 | 5 | from numpy.testing import assert_array_equal | 
| 5 | 6 | 
 | 
| 6 | 7 | import pyfive | 
|  | 8 | +import h5py | 
| 7 | 9 | 
 | 
| 8 |  | -DIRNAME = os.path.dirname(__file__) | 
| 9 |  | -DATASET_COMPACT_HDF5_FILE = os.path.join(DIRNAME, 'compact.hdf5') | 
| 10 |  | - | 
| 11 |  | - | 
| 12 |  | -def test_compact_dataset(): | 
| 13 |  | - | 
| 14 |  | -    with pyfive.File(DATASET_COMPACT_HDF5_FILE) as hfile: | 
| 15 |  | -        data = np.array([1, 2, 3, 4], dtype=np.int32) | 
| 16 | 10 | 
 | 
|  | 11 | +def test_compact_dataset_hdf5(name, data): | 
|  | 12 | +    with pyfive.File(name) as hfile: | 
| 17 | 13 |         # check data | 
| 18 | 14 |         dset1 = hfile['compact'] | 
| 19 | 15 |         assert_array_equal(dset1[...], data) | 
|  | 16 | + | 
|  | 17 | + | 
|  | 18 | +@pytest.fixture(scope='module') | 
|  | 19 | +def data(): | 
|  | 20 | +    return np.array([1, 2, 3, 4], dtype=np.int32) | 
|  | 21 | + | 
|  | 22 | + | 
|  | 23 | +@pytest.fixture(scope='module') | 
|  | 24 | +def name(data): | 
|  | 25 | +    name = os.path.join(os.path.dirname(__file__), 'compact.hdf5') | 
|  | 26 | + | 
|  | 27 | +    f = h5py.File(name, 'w', libver='earliest') | 
|  | 28 | +    dtype = h5py.h5t.NATIVE_INT32 | 
|  | 29 | +    space = h5py.h5s.create_simple(data.shape) | 
|  | 30 | +    dcpl = h5py.h5p.create(h5py.h5p.DATASET_CREATE) | 
|  | 31 | +    dcpl.set_layout(h5py.h5d.COMPACT) | 
|  | 32 | +    dset_id = h5py.h5d.create(f.id, b"compact", dtype, space, dcpl=dcpl) | 
|  | 33 | +    dset_id.write(h5py.h5s.ALL, h5py.h5s.ALL, data) | 
|  | 34 | +    f.close() | 
|  | 35 | + | 
|  | 36 | +    return name | 
0 commit comments