From 54e1924de724b40ed0c32825d7f4787e52f3f00a Mon Sep 17 00:00:00 2001 From: Paul Madden Date: Wed, 21 Aug 2024 21:18:53 +0000 Subject: [PATCH 1/4] Test fails --- src/uwtools/tests/api/test_config.py | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/uwtools/tests/api/test_config.py b/src/uwtools/tests/api/test_config.py index 8d1cdbd42..9bdd5bc0b 100644 --- a/src/uwtools/tests/api/test_config.py +++ b/src/uwtools/tests/api/test_config.py @@ -73,6 +73,13 @@ def test_realize(): ) +def test_realize_no_update_config(): + kwargs: dict = {"input_config": {"n": 88}, "output_file": "output.yaml"} + with patch.object(config, "_realize") as _realize: + config.realize(**kwargs) + _realize.assert_called_once_with(**kwargs) + + def test_realize_to_dict(): kwargs: dict = { "input_config": "path1", From 5736c597685252adf4581da2c47a4ed479d93796 Mon Sep 17 00:00:00 2001 From: Paul Madden Date: Wed, 21 Aug 2024 22:12:23 +0000 Subject: [PATCH 2/4] WIP --- src/uwtools/api/config.py | 2 ++ src/uwtools/tests/api/test_config.py | 18 +++++++++++++++--- 2 files changed, 17 insertions(+), 3 deletions(-) diff --git a/src/uwtools/api/config.py b/src/uwtools/api/config.py index b247fd1e0..40c1f4957 100644 --- a/src/uwtools/api/config.py +++ b/src/uwtools/api/config.py @@ -125,6 +125,8 @@ def realize( """ NB: This docstring is dynamically replaced: See realize.__doc__ definition below. """ + if update_config is None and update_format is None: + update_config = {} return _realize( input_config=_ensure_data_source(_str2path(input_config), stdin_ok), input_format=input_format, diff --git a/src/uwtools/tests/api/test_config.py b/src/uwtools/tests/api/test_config.py index 9bdd5bc0b..96e1c3585 100644 --- a/src/uwtools/tests/api/test_config.py +++ b/src/uwtools/tests/api/test_config.py @@ -74,10 +74,22 @@ def test_realize(): def test_realize_no_update_config(): - kwargs: dict = {"input_config": {"n": 88}, "output_file": "output.yaml"} + input_config = {"n": 88} + output_file = Path("output.yaml") with patch.object(config, "_realize") as _realize: - config.realize(**kwargs) - _realize.assert_called_once_with(**kwargs) + config.realize(input_config=input_config, output_file=output_file) + _realize.assert_called_once_with( + input_config=input_config, + input_format=None, + update_config={}, + update_format=None, + output_file=output_file, + output_format=None, + key_path=None, + values_needed=False, + total=False, + dry_run=False, + ) def test_realize_to_dict(): From 8e5f0a497cee325fb57b627229a07ea948e82e9b Mon Sep 17 00:00:00 2001 From: Paul Madden Date: Wed, 21 Aug 2024 23:20:59 +0000 Subject: [PATCH 3/4] WIP --- src/uwtools/api/config.py | 8 +++-- src/uwtools/tests/api/test_config.py | 48 ++++++++++++++++------------ 2 files changed, 32 insertions(+), 24 deletions(-) diff --git a/src/uwtools/api/config.py b/src/uwtools/api/config.py index 40c1f4957..25986fae2 100644 --- a/src/uwtools/api/config.py +++ b/src/uwtools/api/config.py @@ -125,12 +125,14 @@ def realize( """ NB: This docstring is dynamically replaced: See realize.__doc__ definition below. """ - if update_config is None and update_format is None: - update_config = {} + update_config = _str2path(update_config) + assert not isinstance(update_config, str) + 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=update_config, update_format=update_format, output_file=_str2path(output_file), output_format=output_format, diff --git a/src/uwtools/tests/api/test_config.py b/src/uwtools/tests/api/test_config.py index 96e1c3585..803f35747 100644 --- a/src/uwtools/tests/api/test_config.py +++ b/src/uwtools/tests/api/test_config.py @@ -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 @@ -73,25 +73,6 @@ def test_realize(): ) -def test_realize_no_update_config(): - 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={}, - update_format=None, - output_file=output_file, - output_format=None, - key_path=None, - values_needed=False, - total=False, - dry_run=False, - ) - - def test_realize_to_dict(): kwargs: dict = { "input_config": "path1", @@ -111,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} From 2f45d63ff37f5a2347aaf358b1dae415ad93ca62 Mon Sep 17 00:00:00 2001 From: Paul Madden Date: Wed, 21 Aug 2024 23:25:29 +0000 Subject: [PATCH 4/4] WIP --- src/uwtools/api/config.py | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/uwtools/api/config.py b/src/uwtools/api/config.py index 25986fae2..ec05a0fa5 100644 --- a/src/uwtools/api/config.py +++ b/src/uwtools/api/config.py @@ -125,14 +125,12 @@ def realize( """ NB: This docstring is dynamically replaced: See realize.__doc__ definition below. """ - update_config = _str2path(update_config) - assert not isinstance(update_config, str) 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=update_config, + update_config=_str2path(update_config), update_format=update_format, output_file=_str2path(output_file), output_format=output_format,