|  | 
| 1 | 1 | """ Test pyfive's abililty to read multidimensional datasets. """ | 
| 2 | 2 | import os | 
| 3 | 3 | 
 | 
|  | 4 | +import h5py | 
| 4 | 5 | import numpy as np | 
|  | 6 | +import pytest | 
| 5 | 7 | from numpy.testing import assert_array_equal | 
| 6 | 8 | 
 | 
| 7 | 9 | import pyfive | 
|  | 
| 10 | 12 | DATASET_CHUNKED_HDF5_FILE = os.path.join(DIRNAME, "data", 'chunked.hdf5') | 
| 11 | 13 | 
 | 
| 12 | 14 | 
 | 
| 13 |  | -def test_chunked_dataset(): | 
|  | 15 | +@pytest.fixture(scope='module') | 
|  | 16 | +def data(): | 
|  | 17 | +    return np.array(list(range(10_000)), dtype=np.int32).reshape((100, 100)) | 
| 14 | 18 | 
 | 
| 15 |  | -    with pyfive.File(DATASET_CHUNKED_HDF5_FILE) as hfile: | 
| 16 | 19 | 
 | 
|  | 20 | +@pytest.fixture(scope='module') | 
|  | 21 | +def name(data): | 
|  | 22 | +    name = os.path.join(os.path.dirname(__file__), 'btreev2.hdf5') | 
|  | 23 | + | 
|  | 24 | +    with h5py.File(name, "w", libver="latest") as f: | 
|  | 25 | +        # type 10 record - chunked without filters | 
|  | 26 | +        f.create_dataset( | 
|  | 27 | +            "btreev2", | 
|  | 28 | +            data=data, | 
|  | 29 | +            chunks=(10, 10), | 
|  | 30 | +            maxshape=(None, None), | 
|  | 31 | +            dtype="int32") | 
|  | 32 | + | 
|  | 33 | +        # type 11 record - chunked with filters | 
|  | 34 | +        f.create_dataset( | 
|  | 35 | +            "btreev2_filters", | 
|  | 36 | +            data=data, | 
|  | 37 | +            chunks=(10, 10), | 
|  | 38 | +            maxshape=(None, None), | 
|  | 39 | +            compression="gzip", | 
|  | 40 | +            compression_opts=1, | 
|  | 41 | +            fletcher32=True, | 
|  | 42 | +            dtype="int32") | 
|  | 43 | + | 
|  | 44 | +    return name | 
|  | 45 | + | 
|  | 46 | + | 
|  | 47 | +def test_chunked_dataset(): | 
|  | 48 | +    with pyfive.File(DATASET_CHUNKED_HDF5_FILE) as hfile: | 
| 17 | 49 |         # check data | 
| 18 | 50 |         dset1 = hfile['dataset1'] | 
| 19 |  | -        assert_array_equal(dset1[:], np.arange(21*16).reshape((21, 16))) | 
|  | 51 | +        assert_array_equal(dset1[:], np.arange(21 * 16).reshape((21, 16))) | 
| 20 | 52 |         assert dset1.chunks == (2, 2) | 
|  | 53 | + | 
|  | 54 | +@pytest.mark.skip(reason="Not implemented yet, see https://github.com/NCAS-CMS/pyfive/issues/137") | 
|  | 55 | +def test_chunked_dataset_btreev2(name, data): | 
|  | 56 | +    with pyfive.File(name) as hfile: | 
|  | 57 | +        dset1 = hfile['btreev2'] | 
|  | 58 | +        assert_array_equal(dset1[...], data) | 
0 commit comments