Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Relax jsonschema pin #649

Merged
merged 5 commits into from
Nov 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions recipe/meta.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
"isort =5.13.*",
"jinja2 =3.1.*",
"jq =1.7.*",
"jsonschema =4.23.*",
"jsonschema >=4.18,<4.24",
"lxml =5.3.*",
"make =4.4.*",
"mypy =1.11.*",
Expand All @@ -27,7 +27,7 @@
"f90nml =1.4.*",
"iotaa =0.8.*",
"jinja2 =3.1.*",
"jsonschema =4.23.*",
"jsonschema >=4.18,<4.24",
"lxml =5.3.*",
"python >=3.9,<3.13",
"pyyaml =6.0.*"
Expand Down
2 changes: 1 addition & 1 deletion recipe/meta.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ requirements:
- f90nml 1.4.*
- iotaa 0.8.*
- jinja2 3.1.*
- jsonschema 4.23.*
- jsonschema >=4.18,<4.24
- lxml 5.3.*
- python >=3.9,<3.13
- pyyaml 6.0.*
Expand Down
51 changes: 37 additions & 14 deletions src/uwtools/tests/test_schemas.py
Original file line number Diff line number Diff line change
Expand Up @@ -297,6 +297,29 @@ def ww3_prop():
return partial(schema_validator, "ww3", "properties", "ww3", "properties")


# Helpers


def non_empty_dict(errors: list[str]) -> bool:
for msg in [
"{} does not have enough properties", # jsonschema [4.18.0,4.20.*]
"{} should be non-empty", # jsonschema [4.21.0,?]
]:
if msg in errors:
return True
return False


def non_empty_list(errors: list[str]) -> bool:
for msg in [
"[] is too short", # jsonschema [4.18.0,4.20.*]
"[] should be non-empty", # jsonschema [4.21.0,?]
]:
if msg in errors:
return True
return False
maddenp-noaa marked this conversation as resolved.
Show resolved Hide resolved


# batchargs


Expand Down Expand Up @@ -743,7 +766,7 @@ def test_schema_stage_files():
# A str -> str dict is ok:
assert not errors({"file1": "/path/to/file1", "file2": "/path/to/file2"})
# An empty dict is not allowed:
assert "{} should be non-empty" in errors({})
assert non_empty_dict(errors({}))
# Non-string values are not allowed:
assert "True is not of type 'string'\n" in errors({"file1": True})

Expand Down Expand Up @@ -949,7 +972,7 @@ def test_schema_fv3_model_configure_update_values(fv3_prop):
# Other types are not, e.g.:
assert "None is not of type 'boolean', 'number', 'string'\n" in errors({"null": None})
# At least one entry is required:
assert "{} should be non-empty" in errors({})
assert non_empty_dict(errors({}))


def test_schema_fv3_namelist(fv3_prop):
Expand Down Expand Up @@ -979,9 +1002,9 @@ def test_schema_fv3_namelist_update_values(fv3_prop):
{"nml": {"null": None}}
)
# At least one namelist entry is required:
assert "{} should be non-empty" in errors({})
assert non_empty_dict(errors({}))
# At least one val/var pair is required:
assert "{} should be non-empty" in errors({"nml": {}})
assert non_empty_dict(errors({"nml": {}}))


def test_schema_fv3_rundir(fv3_prop):
Expand Down Expand Up @@ -1052,7 +1075,7 @@ def test_schema_ioda_configuration_file(ioda_prop):
assert not errors(bf)
assert not errors(uv)
# update_values cannot be empty:
assert "should be non-empty" in errors({"update_values": {}})
assert non_empty_dict(errors({"update_values": {}}))


def test_schema_ioda_rundir(ioda_prop):
Expand Down Expand Up @@ -1096,7 +1119,7 @@ def test_schema_jedi_configuration_file(jedi_prop):
assert not errors(bf)
assert not errors(uv)
# update_values cannot be empty:
assert "should be non-empty" in errors({"update_values": {}})
assert non_empty_dict(errors({"update_values": {}}))


def test_schema_jedi_rundir(jedi_prop):
Expand Down Expand Up @@ -1221,7 +1244,7 @@ def test_schema_makedirs():
# Basic correctness:
assert not errors({"makedirs": ["/path/to/dir1", "/path/to/dir2"]})
# An empty array is not allowed:
assert "[] should be non-empty" in errors({"makedirs": []})
assert non_empty_list(errors({"makedirs": []}))
# Non-string values are not allowed:
assert "True is not of type 'string'\n" in errors({"makedirs": [True]})

Expand Down Expand Up @@ -1308,9 +1331,9 @@ def test_schema_mpas_namelist_update_values(mpas_prop):
{"nml": {"null": None}}
)
# At least one namelist entry is required:
assert "{} should be non-empty" in errors({})
assert non_empty_dict(errors({}))
# At least one val/var pair is required:
assert "{} should be non-empty" in errors({"nml": {}})
assert non_empty_dict(errors({"nml": {}}))


def test_schema_mpas_rundir(mpas_prop):
Expand Down Expand Up @@ -1396,9 +1419,9 @@ def test_schema_mpas_init_namelist_update_values(mpas_init_prop):
{"nml": {"null": None}}
)
# At least one namelist entry is required:
assert "{} should be non-empty" in errors({})
assert non_empty_dict(errors({}))
# At least one val/var pair is required:
assert "{} should be non-empty" in errors({"nml": {}})
assert non_empty_dict(errors({"nml": {}}))


def test_schema_mpas_init_rundir(mpas_init_prop):
Expand Down Expand Up @@ -1477,7 +1500,7 @@ def test_schema_mpas_streams_properties_values_array(mpas_streams):
for prop in ["files", "streams", "vars", "var_arrays", "var_structs"]:
assert "is not of type 'array'\n" in errors({k: {**v, prop: None}})
assert "is not of type 'string'\n" in errors({k: {**v, prop: [None]}})
assert "should be non-empty" in errors({k: {**v, prop: []}})
assert non_empty_list(errors({k: {**v, prop: []}}))


def test_schema_mpas_streams_properties_boolean(mpas_streams):
Expand Down Expand Up @@ -1541,9 +1564,9 @@ def test_schema_namelist():
assert errormsg % "None" in errors({"namelist": {"nonetype": None}})
assert errormsg % "{}" in errors({"namelist": {"dict": {}}})
# Needs at least one namelist value:
assert "{} should be non-empty" in errors({})
assert non_empty_dict(errors({}))
# Needs at least one name-value value:
assert "{} should be non-empty" in errors({"namelist": {}})
assert non_empty_dict(errors({"namelist": {}}))
# Namelist level must be a mapping:
assert "[] is not of type 'object'\n" in errors([])
# Name-value level level must be a mapping:
Expand Down
Loading