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

UW-504: Allow YAML as supplemental config always #421

Merged
merged 13 commits into from
Feb 29, 2024
6 changes: 4 additions & 2 deletions src/uwtools/config/tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -277,8 +277,10 @@ def _validate_format_supplemental(
if isinstance(supplemental_cfg, Config)
else _ensure_format(desc=pre, config=supplemental_cfg)
)
if sc_fmt != config_fmt:
raise UWError("%s format %s must match input format %s" % (pre, sc_fmt, config_fmt))
if sc_fmt not in (FORMAT.yaml, config_fmt):
raise UWError(
"%s format %s must be input format %s or %s" % (pre, sc_fmt, config_fmt, FORMAT.yaml)
WeirAE marked this conversation as resolved.
Show resolved Hide resolved
)


# Import-time code
Expand Down
8 changes: 4 additions & 4 deletions src/uwtools/tests/config/test_tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -657,22 +657,22 @@ def test__validate_format_output(input_fmt, output_fmt):


def test__validate_format_supplemental_fail_obj():
config_fmt = FORMAT.yaml
config_fmt = FORMAT.ini
sc = NMLConfig(config={"n": {"k": "v"}})
with raises(UWError) as e:
tools._validate_format_supplemental(config_fmt=config_fmt, supplemental_cfg=sc, idx=87)
assert str(e.value) == "Supplemental config #88 format %s must match input format %s" % (
assert str(e.value) == "Supplemental config #88 format %s must be YAML or input format %s" % (
WeirAE marked this conversation as resolved.
Show resolved Hide resolved
FORMAT.nml,
config_fmt,
)


def test__validate_format_supplemental_fail_path():
config_fmt = FORMAT.yaml
config_fmt = FORMAT.ini
sc = Path("/path/to/config.nml")
with raises(UWError) as e:
tools._validate_format_supplemental(config_fmt=config_fmt, supplemental_cfg=sc, idx=87)
assert str(e.value) == "Supplemental config #%s format %s must match input format %s" % (
assert str(e.value) == "Supplemental config #%s format %s must be YAML or input format %s" % (
WeirAE marked this conversation as resolved.
Show resolved Hide resolved
88,
FORMAT.nml,
config_fmt,
Expand Down
Loading