From fc29a576622ab6e51fc3b9b4e0435751e3e61957 Mon Sep 17 00:00:00 2001 From: Mattia Almansi Date: Mon, 5 Dec 2022 18:44:00 +0100 Subject: [PATCH] check version exist (#8) --- c3s_eqc_data_checker/check.py | 9 +++++++++ tests/test_20_grib.py | 6 ++++++ 2 files changed, 15 insertions(+) diff --git a/c3s_eqc_data_checker/check.py b/c3s_eqc_data_checker/check.py index 6422e92..d27c58e 100644 --- a/c3s_eqc_data_checker/check.py +++ b/c3s_eqc_data_checker/check.py @@ -273,6 +273,15 @@ def check_cf_compliance( silent=True, ) for path in self.paths_iterator: + if version and version not in cfchecker.cfchecks.cfVersions: + versions = sorted( + str(version) for version in cfchecker.cfchecks.cfVersions + ) + errors[ + path + ] = f"{version=!s} is not available.\nAvailable versions: {versions!r}." + continue + if self.files_format == "NETCDF": inst.checker(path) else: diff --git a/tests/test_20_grib.py b/tests/test_20_grib.py index 45b12ed..d1bc6d2 100644 --- a/tests/test_20_grib.py +++ b/tests/test_20_grib.py @@ -67,6 +67,12 @@ def test_cf_compliance(tmp_path: pathlib.Path, grib_path: pathlib.Path) -> None: actual = checker.check_cf_compliance(None) assert set(actual) == {str(tmp_path / "non-compliant.grib")} + actual = checker.check_cf_compliance("10") + print(actual.values) + assert actual[str(tmp_path / "non-compliant.grib")].startswith( + "version=CF-10 is not available." + ) + def test_temporal_resolution(grib_path: pathlib.Path) -> None: checker = Checker(str(grib_path / "GRIB2.tmpl"), files_format="GRIB")