From fa7e5c47f0296941877da2d2fa239fe46db6c0b2 Mon Sep 17 00:00:00 2001 From: Paul Madden Date: Wed, 7 Feb 2024 17:22:57 +0000 Subject: [PATCH] Extra schema test --- src/uwtools/drivers/driver.py | 4 ++- src/uwtools/drivers/forecast.py | 2 +- src/uwtools/resources/FV3Forecast.jsonschema | 3 +-- src/uwtools/tests/drivers/test_forecast.py | 27 ++++++++++++++++++++ 4 files changed, 32 insertions(+), 4 deletions(-) diff --git a/src/uwtools/drivers/driver.py b/src/uwtools/drivers/driver.py index 25822811a..a68c85b8e 100644 --- a/src/uwtools/drivers/driver.py +++ b/src/uwtools/drivers/driver.py @@ -86,7 +86,9 @@ def run_cmd(self) -> str: """ components = [ self._platform_config["mpicmd"], # MPI run program - *[str(x) for x in self._config["runtime_info"].get("mpi_args", [])], # MPI arguments + *[ + str(x) for x in self._config.get("runtime_info", {}).get("mpi_args", []) + ], # MPI arguments self._config["executable"], # NWP tool executable name ] return " ".join(filter(None, components)) diff --git a/src/uwtools/drivers/forecast.py b/src/uwtools/drivers/forecast.py index 27d9625b0..23d7e4382 100644 --- a/src/uwtools/drivers/forecast.py +++ b/src/uwtools/drivers/forecast.py @@ -238,7 +238,7 @@ def _mpi_env_variables(self, delimiter: str = " ") -> str: """ envvars = { "KMP_AFFINITY": "scatter", - "OMP_NUM_THREADS": self._config["runtime_info"].get("threads", 1), + "OMP_NUM_THREADS": self._config.get("runtime_info", {}).get("threads", 1), "OMP_STACKSIZE": "512m", "MPI_TYPE_DEPTH": 20, "ESMF_RUNTIME_COMPLIANCECHECK": "OFF:depth=4", diff --git a/src/uwtools/resources/FV3Forecast.jsonschema b/src/uwtools/resources/FV3Forecast.jsonschema index 861f99ea8..768b90117 100644 --- a/src/uwtools/resources/FV3Forecast.jsonschema +++ b/src/uwtools/resources/FV3Forecast.jsonschema @@ -220,8 +220,7 @@ "domain", "executable", "length", - "run_dir", - "runtime_info" + "run_dir" ], "type": "object" }, diff --git a/src/uwtools/tests/drivers/test_forecast.py b/src/uwtools/tests/drivers/test_forecast.py index b85e3b4d4..41241f2d4 100644 --- a/src/uwtools/tests/drivers/test_forecast.py +++ b/src/uwtools/tests/drivers/test_forecast.py @@ -447,6 +447,33 @@ def test_FV3Forecast_schema_filesToStage(): assert "True is not of type 'string'" in errors({"file1": True}) +def test_FV3Forecast_schema_forecast(): + d = {"domain": "regional", "executable": "fv3", "length": 3, "run_dir": "/tmp"} + errors = validator("FV3Forecast.jsonschema", "properties", "forecast") + # Basic correctness: + assert not errors(d) + # Some top-level keys are required: + assert "'domain' is a required property" in errors(with_del(d, "domain")) + assert "'executable' is a required property" in errors(with_del(d, "executable")) + assert "'length' is a required property" in errors(with_del(d, "length")) + assert "'run_dir' is a required property" in errors(with_del(d, "run_dir")) + # Some top-level keys are optional: + assert not errors( + { + **d, + "diag_table": "/path", + "field_table": {"base_file": "/path"}, + "files_to_copy": {"fn": "/path"}, + "files_to_link": {"fn": "/path"}, + "model_configure": {"base_file": "/path"}, + "namelist": {"base_file": "/path"}, + "runtime_info": {}, + } + ) + # Additional top-level keys are not allowed: + assert "Additional properties are not allowed" in errors({**d, "foo": "bar"}) + + def test_FV3Forecast_schema_forecast_diag_table(fcstprop): errors = fcstprop("diag_table") # String value is ok: