Skip to content

Commit

Permalink
add h5netcdf for complex model tests, raise on invalid engine
Browse files Browse the repository at this point in the history
  • Loading branch information
slevang committed Oct 7, 2024
1 parent 17a5efc commit d96807e
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 5 deletions.
2 changes: 1 addition & 1 deletion tests/models/cross/test_hilbert_cpcca.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ def test_singular_values(use_pca):


# Currently, netCDF4 does not support complex numbers, so skip this test
@pytest.mark.parametrize("engine", ["zarr"])
@pytest.mark.parametrize("engine", ["h5netcdf", "zarr"])
@pytest.mark.parametrize("alpha", [0.0, 0.5, 1.0])
def test_save_load_with_data(tmp_path, engine, alpha):
"""Test save/load methods in CPCCA class, ensuring that we can
Expand Down
2 changes: 1 addition & 1 deletion tests/models/single/test_pop.py
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ def test_inverse_transform(mock_data_array):
assert set(X_rec.dims) == set(mock_data_array.dims)


@pytest.mark.parametrize("engine", ["zarr"])
@pytest.mark.parametrize("engine", ["h5netcdf", "zarr"])
def test_save_load(mock_data_array, tmp_path, engine):
"""Test save/load methods in POP class, ensuring that we can
roundtrip the model and get the same results when transforming
Expand Down
8 changes: 5 additions & 3 deletions tests/utilities.py
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,9 @@ def skip_if_missing_engine(engine: str):
"""
Skip save/load tests if missing the i/o backend.
"""
# xarray uses engine="netcdf4" but the package itself is called "netCDF4".
mapping = {"netcdf4": "netCDF4"}
module = mapping.get(engine, engine)
# xarray uses engine="netcdf4" but the package itself is "netCDF4".
mapping = {"h5netcdf": "h5netcdf", "netcdf4": "netCDF4", "zarr": "zarr"}
module = mapping.get(engine)
if module is None:
raise ValueError(f"Unrecognized engine: {engine}")
pytest.importorskip(module)

0 comments on commit d96807e

Please sign in to comment.