Skip to content

Commit

Permalink
UW-504: Allow YAML as supplemental config always (#421)
Browse files Browse the repository at this point in the history
* Edit to allow supplemental YAML

* Update tools.py

Co-authored-by: Paul Madden <136389411+maddenp-noaa@users.noreply.github.com>

* format run

* Update src/uwtools/config/tools.py

Co-authored-by: Paul Madden <136389411+maddenp-noaa@users.noreply.github.com>

* Update src/uwtools/tests/config/test_tools.py

Co-authored-by: Paul Madden <136389411+maddenp-noaa@users.noreply.github.com>

* Update src/uwtools/tests/config/test_tools.py

Co-authored-by: Paul Madden <136389411+maddenp-noaa@users.noreply.github.com>

---------

Co-authored-by: Paul Madden <136389411+maddenp-noaa@users.noreply.github.com>
  • Loading branch information
WeirAE and maddenp-noaa authored Feb 29, 2024
1 parent c308953 commit 32c327e
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 6 deletions.
6 changes: 4 additions & 2 deletions src/uwtools/config/tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -281,8 +281,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 %s or input format %s" % (pre, sc_fmt, FORMAT.yaml, config_fmt)
)


# 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 @@ -665,22 +665,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" % (
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" % (
88,
FORMAT.nml,
config_fmt,
Expand Down

0 comments on commit 32c327e

Please sign in to comment.