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

GH 586 bad stdin_ok prompt #587

Merged
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: 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
Loading