Skip to content

Commit

Permalink
Merge pull request #33 from jjhelmus/resizeable
Browse files Browse the repository at this point in the history
TST: unit tests for resizable datasets
  • Loading branch information
jjhelmus authored Sep 29, 2017
2 parents 55d9425 + 03e393f commit b4a928b
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 0 deletions.
22 changes: 22 additions & 0 deletions tests/make_resizable.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#! /usr/bin/env python
""" Create a HDF5 file with data with an resizable datasets. """

import h5py
import numpy as np

f = h5py.File('resizable.hdf5', 'w', libver='earliest')

f.create_dataset(
'dataset1', shape=(4, 6), maxshape=(8, 12), dtype='<f8',
data=np.arange(4 * 6).reshape(4, 6), track_times=False)

# datasets with unlimited dimensions
f.create_dataset(
'dataset2', shape=(10, 5), maxshape=(10, None), dtype='<i4',
data=np.arange(10*5).reshape(10, 5), track_times=False)

f.create_dataset(
'dataset3', shape=(8, 4), maxshape=(None, None), dtype='>i2',
data=np.arange(8*4).reshape(8, 4), track_times=False)

f.close()
Binary file added tests/resizable.hdf5
Binary file not shown.
27 changes: 27 additions & 0 deletions tests/test_resizable.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
""" Test pyfive's abililty to read resizable datasets. """
import os

import numpy as np
from numpy.testing import assert_array_equal

import pyfive

DIRNAME = os.path.dirname(__file__)
DATASET_RESIZABLE_HDF5_FILE = os.path.join(DIRNAME, 'resizable.hdf5')


def test_resizable_dataset():

with pyfive.File(DATASET_RESIZABLE_HDF5_FILE) as hfile:

dset1 = hfile['dataset1']
assert_array_equal(dset1[:], np.arange(4 * 6).reshape((4, 6)))
assert dset1.dtype == '<f8'

dset2 = hfile['dataset2']
assert_array_equal(dset2[:], np.arange(10 * 5).reshape((10, 5)))
assert dset2.dtype == '<i4'

dset3 = hfile['dataset3']
assert_array_equal(dset3[:], np.arange(8 * 4).reshape((8, 4)))
assert dset3.dtype == '>i2'

0 comments on commit b4a928b

Please sign in to comment.