Skip to content

Commit

Permalink
GH 586 bad stdin_ok prompt (#587)
Browse files Browse the repository at this point in the history
  • Loading branch information
maddenp-noaa authored Aug 22, 2024
1 parent 0ae1b49 commit ba08c9d
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 3 deletions.
4 changes: 3 additions & 1 deletion src/uwtools/api/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,10 +125,12 @@ def realize(
"""
NB: This docstring is dynamically replaced: See realize.__doc__ definition below.
"""
if update_config is None and update_format is not None: # i.e. updates will be read from stdin
update_config = _ensure_data_source(update_config, stdin_ok)
return _realize(
input_config=_ensure_data_source(_str2path(input_config), stdin_ok),
input_format=input_format,
update_config=_ensure_data_source(_str2path(update_config), stdin_ok),
update_config=_str2path(update_config),
update_format=update_format,
output_file=_str2path(output_file),
output_format=output_format,
Expand Down
29 changes: 27 additions & 2 deletions src/uwtools/tests/api/test_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@
from unittest.mock import patch

import yaml
from pytest import mark
from pytest import mark, raises

from uwtools.api import config
from uwtools.config.formats.yaml import YAMLConfig
from uwtools.exceptions import UWConfigError
from uwtools.exceptions import UWConfigError, UWError
from uwtools.utils.file import FORMAT


Expand Down Expand Up @@ -92,6 +92,31 @@ def test_realize_to_dict():
)


def test_realize_update_config_from_stdin():
with raises(UWError) as e:
config.realize(input_config={}, output_file="output.yaml", update_format="yaml")
assert str(e.value) == "Set stdin_ok=True to permit read from stdin"


def test_realize_update_config_none():
input_config = {"n": 88}
output_file = Path("output.yaml")
with patch.object(config, "_realize") as _realize:
config.realize(input_config=input_config, output_file=output_file)
_realize.assert_called_once_with(
input_config=input_config,
input_format=None,
update_config=None,
update_format=None,
output_file=output_file,
output_format=None,
key_path=None,
values_needed=False,
total=False,
dry_run=False,
)


@mark.parametrize("cfg", [{"foo": "bar"}, YAMLConfig(config={})])
def test_validate(cfg):
kwargs: dict = {"schema_file": "schema-file", "config": cfg}
Expand Down

0 comments on commit ba08c9d

Please sign in to comment.