Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion pyfive/dataobjects.py
Original file line number Diff line number Diff line change
Expand Up @@ -527,7 +527,11 @@ def _get_chunk_params(self):
dims, address = struct.unpack_from(
'<BQ', self.msg_data, property_offset)
data_offset = property_offset + struct.calcsize('<BQ')
assert (version >= 1) and (version <= 3)
supported_version = (version >= 1) and (version <= 3)
if not supported_version:
# Note that implementation of layout class version 4 will need to deal with
# assumption that btree is of type V1 (see chunk_btree = ... in h5d.py).
raise RuntimeError(f'Pyfive cannot yet read HDF5 files with layout class {version}')

fmt = '<' + 'I' * (dims-1)
chunk_shape = struct.unpack_from(fmt, self.msg_data, data_offset)
Expand Down
10 changes: 5 additions & 5 deletions tests/test_chunk_index_options.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ def test_lazy_index():
assert dset1.attrs['attr1'] == 130

# test we have no index yet
assert dset1.id._DatasetID__index_built==False
assert not dset1.id._DatasetID__index_built

# this should force an index build
assert_array_equal(dset1[:], np.arange(21*16).reshape((21, 16)))
Expand All @@ -42,13 +42,13 @@ def simpler_check(x,y):
""" Expect this to be visited and instantiated without an index """
print(x,y.name)
assert y.attrs['attr1'] == 130
assert y.id._DatasetID__index_built==False
assert not y.id._DatasetID__index_built

def simplest_check(x,y):
""" Expect this to be visited and instantiated with an index """
print(x,y.name)
assert y.attrs['attr1'] == 130
assert y.id._DatasetID__index_built==True
assert y.id._DatasetID__index_built


with pyfive.File(DATASET_CHUNKED_HDF5_FILE) as hfile:
Expand All @@ -68,7 +68,7 @@ def test_get_chunk_info_chunked():
open(DATASET_CHUNKED_HDF5_FILE, "rb") as f:

ds = hfile.get_lazy_view('dataset1')
assert ds.id._DatasetID__index_built==False
assert not ds.id._DatasetID__index_built

si = StoreInfo((0,0), 0, 4016, 16)
info = ds.id.get_chunk_info(0)
Expand All @@ -92,7 +92,7 @@ def test_get_chunk_methods_contiguous():
with pyfive.File(NOT_CHUNKED_FILE) as hfile:

ds = hfile.get_lazy_view('q')
assert ds.id._DatasetID__index_built==False
assert not ds.id._DatasetID__index_built

with pytest.raises(TypeError):
ds.id.get_chunk_info(0)
Expand Down
13 changes: 13 additions & 0 deletions tests/test_chunked.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,19 @@ def test_chunked_dataset():
assert dset1.chunks == (2, 2)


def test_recognise_btree(name, data):
"""
At this point we want to raise an error if we find a chunked variable
with a b-tree v2 index, as we don't know how to read it ... yet.
It seems that can only come with layoutclass = 4.
"""
with pytest.raises(RuntimeError):
with pyfive.File(name) as hfile:
dset1 = hfile['btreev2']
print(dset1)



@pytest.mark.skip(reason="Not implemented yet, see https://github.com/NCAS-CMS/pyfive/issues/137")
def test_chunked_dataset_btreev2(name, data):
with pyfive.File(name) as hfile:
Expand Down
47 changes: 39 additions & 8 deletions tests/test_p5ncdump.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
"""Test the p5dump executable via p5ncdump utility."""
import os
import shutil

import pyfive
import pytest
import subprocess
import tempfile

DIRNAME = os.path.dirname(__file__)

def test_which_p5dump():
"""Run the basic which p5dump."""
Expand All @@ -13,16 +14,46 @@ def test_which_p5dump():


def test_p5dump_cmd():
"""Run a basic p5dump with no/yes file arg."""
s1 = os.system("p5dump")
assert s1 != 0
s2 = os.system("p5dump tests/data/groups.hdf5")
assert s2 == 0
"""
Run p5dump on a test HDF5 file safely, capturing output.
This currently works fine with pytest from the command
line but breaks inside visual studio code with a wierd
numpy error. This lengthy version is en route to debugging
"""

p5dump = shutil.which("p5dump")
assert p5dump, "p5dump not found in PATH"
assert os.access(p5dump, os.X_OK), f"{p5dump} is not executable"

dfile = os.path.join(os.path.dirname(__file__), 'data', 'groups.hdf5')
assert os.path.exists(dfile), f"Test file does not exist: {dfile}"

with tempfile.TemporaryDirectory() as tmpdir:

# Copy environment and remove PYTHONPATH to avoid NumPy source tree detection
env = os.environ.copy()
env.pop("PYTHONPATH", None)

result = subprocess.run(
[p5dump, dfile],
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
text=True,
cwd=tmpdir,
env=env
)

print("cmd:", result.args)
print("returncode:", result.returncode)
print("stdout:\n", result.stdout)
print("stderr:\n", result.stderr)

assert result.returncode == 0


def test_hdf5(capsys):
"""Run p5dump on a local HDF5 file."""
hdf5_file = "./tests/data/groups.hdf5"
hdf5_file = DIRNAME+'/data/groups.hdf5'
pyfive.p5ncdump(hdf5_file)

captured = capsys.readouterr()
Expand Down
Loading