From f3fd0a0ed227f8a354f97b949dc24f2126de182f Mon Sep 17 00:00:00 2001 From: sneakers-the-rat Date: Fri, 17 May 2024 16:51:41 -0700 Subject: [PATCH] coverage tests for hdf5 interface. filter numpy deprecation warnings from nptyping --- pyproject.toml | 4 ++++ tests/test_interface/test_hdf5.py | 27 +++++++++++++++++++++++++++ 2 files changed, 31 insertions(+) diff --git a/pyproject.toml b/pyproject.toml index bfb816f..5979c60 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -67,6 +67,10 @@ addopts = [ testpaths = [ "tests" ] +filterwarnings = [ + # nptyping's alias warnings + 'ignore:.*deprecated alias.*Deprecated NumPy 1\.24.*' +] [tool.ruff] target-version = "py311" diff --git a/tests/test_interface/test_hdf5.py b/tests/test_interface/test_hdf5.py index 3697736..f12bd87 100644 --- a/tests/test_interface/test_hdf5.py +++ b/tests/test_interface/test_hdf5.py @@ -48,6 +48,22 @@ def test_hdf5_check(interface_type): assert not H5Interface.check(interface_type[0]) +def test_hdf5_check_not_exists(): + """We should fail a check for a nonexistent hdf5 file""" + spec = ("./fakefile.h5", "/fake/array") + assert not H5Interface.check(spec) + + +def test_hdf5_check_not_hdf5(tmp_path): + """Files that exist but aren't actually hdf5 files should fail a check""" + afile = tmp_path / "not_an_hdf.h5" + with open(afile, "w") as af: + af.write("hey") + + spec = (afile, "/fake/array") + assert not H5Interface.check(spec) + + def test_hdf5_shape(shape_cases, hdf5_array): _test_hdf5_case(shape_cases, hdf5_array) @@ -66,6 +82,17 @@ def test_hdf5_dataset_not_exists(hdf5_array, model_blank): assert "no array found" in e +def test_assignment(hdf5_array, model_blank): + array = hdf5_array() + + model = model_blank(array=array) + model.array[1, 1] = 5 + assert model.array[1, 1] == 5 + + model.array[1:3, 2:4] = 10 + assert (model.array[1:3, 2:4] == 10).all() + + def test_to_json(hdf5_array, array_model): """ Test serialization of HDF5 arrays to JSON