diff --git a/data/misc/diff_missing_fill.nc b/data/misc/diff_missing_fill.nc new file mode 100644 index 0000000..74e0e48 Binary files /dev/null and b/data/misc/diff_missing_fill.nc differ diff --git a/tests/conftest.py b/tests/conftest.py index 0e91cae..624df0c 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -130,6 +130,12 @@ def sample_cordex_path(data_dir: Path) -> Path: ) +@pytest.fixture +def sample_incoherent_encoding_path(data_dir: Path) -> Path: + """Return path to a incoherent NetCDF file.""" + return data_dir / "misc/diff_missing_fill.nc" + + def pytest_configure(config): """Register custom markers.""" config.addinivalue_line( diff --git a/tests/test_entrypoint.py b/tests/test_entrypoint.py index b1aef6d..7768ac1 100644 --- a/tests/test_entrypoint.py +++ b/tests/test_entrypoint.py @@ -214,6 +214,25 @@ def test_xarray_open_with_freva_engine(self, sample_netcdf_path: Path): assert isinstance(ds, xr.Dataset) ds.close() + @pytest.mark.required_data + def test_decoding(self, sample_incoherent_encoding_path: Path): + with pytest.warns(): + ds = xr.open_dataset(str(sample_incoherent_encoding_path), engine="prism") + assert isinstance(ds, xr.Dataset) + ds.close() + + @pytest.mark.required_data + def test_not_decoding(self, sample_incoherent_encoding_path: Path): + import warnings + + with warnings.catch_warnings(): + warnings.simplefilter("error") + ds = xr.open_dataset( + str(sample_incoherent_encoding_path), engine="prism", decode_cf=False + ) + assert isinstance(ds, xr.Dataset) + ds.close() + class TestCustomRegistry: """Tests for custom backend registration."""