Skip to content

Commit

Permalink
Updated to allow YAML as output always
Browse files Browse the repository at this point in the history
  • Loading branch information
WeirAE committed Feb 23, 2024
1 parent fba233a commit 6c5dc46
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 6 deletions.
4 changes: 2 additions & 2 deletions docs/sections/user_guide/cli/mode_config.rst
Original file line number Diff line number Diff line change
Expand Up @@ -434,7 +434,7 @@ and an additional supplemental YAML file ``values2.yaml`` with the following con
.. note:: In recognition of the different sets of value types representable in each config format, ``uw`` supports two format-combination schemes:

1. **Output matches input:** The format of the output config matches that of the input config.
2. **Input is YAML:** If the input config is YAML, any output format may be requested. In the worst case, values always have a string representation, but note that, for example, the string representation of a YAML sequence (Python ``list``) in an INI output config may not be useful.
2. **Output or input is YAML:** If either config is YAML, any other format may be requested. In the worst case, output values always have a string representation, but note that, for example, the string representation of a YAML sequence (Python ``list``) in an INI output config may not be useful.

In all cases, any supplemental configs must be in the same format as the input config and must have recognized extensions.

Expand All @@ -443,7 +443,7 @@ and an additional supplemental YAML file ``values2.yaml`` with the following con
.. code-block:: text
$ uw config realize --input-file b.nml --output-file a.yaml
Output format yaml must match input format nml unless input is YAML
Output format yaml must match input format nml unless either is YAML
.. code-block:: text
Expand Down
4 changes: 2 additions & 2 deletions src/uwtools/config/tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -251,9 +251,9 @@ def _validate_format_output(input_fmt: str, output_fmt: str) -> None:
:param output_fmt: Output format.
:raises: UWError if output format is incompatible.
"""
if not input_fmt in (FORMAT.yaml, output_fmt):
if FORMAT.yaml not in (input_fmt, output_fmt) and input_fmt != output_fmt:
raise UWError(
"Output format %s must match input format %s unless input is YAML"
"Output format %s must match input format %s unless either is YAML"
% (output_fmt, input_fmt)
)

Expand Down
4 changes: 2 additions & 2 deletions src/uwtools/tests/config/test_tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -645,14 +645,14 @@ def test__realize_config_values_needed_negative_results(caplog, tmp_path):
@pytest.mark.parametrize("output_fmt", FORMAT.extensions())
def test__validate_format_output(input_fmt, output_fmt):
call = lambda: tools._validate_format_output(input_fmt=input_fmt, output_fmt=output_fmt)
if input_fmt in (FORMAT.yaml, output_fmt):
if FORMAT.yaml in (input_fmt, output_fmt) or input_fmt == output_fmt:
call() # no exception raised
else:
with raises(UWError) as e:
call()
assert (
str(e.value) == f"Output format {output_fmt} must match input format {input_fmt}"
" unless input is YAML"
" unless either is YAML"
)


Expand Down

0 comments on commit 6c5dc46

Please sign in to comment.