From b5142d9ebac74109696cc42462f2488350c05e72 Mon Sep 17 00:00:00 2001 From: Timothy Willard <9395586+TimothyWillard@users.noreply.github.com> Date: Wed, 11 Dec 2024 11:45:20 -0500 Subject: [PATCH] Upgrade TL key collision from warning to error --- .../gempyor_pkg/src/gempyor/shared_cli.py | 4 +++- .../tests/cli/test_flepimop_patch_cli.py | 23 +++++++------------ .../shared_cli/test_parse_config_files.py | 2 +- 3 files changed, 12 insertions(+), 17 deletions(-) diff --git a/flepimop/gempyor_pkg/src/gempyor/shared_cli.py b/flepimop/gempyor_pkg/src/gempyor/shared_cli.py index 4c446d643..f98449e61 100644 --- a/flepimop/gempyor_pkg/src/gempyor/shared_cli.py +++ b/flepimop/gempyor_pkg/src/gempyor/shared_cli.py @@ -242,7 +242,9 @@ def _parse_option(param: click.Parameter, value: Any) -> Any: tmp = confuse.Configuration("tmp") tmp.set_file(config_file) if intersect := set(tmp.keys()) & set(cfg_data.keys()): - warnings.warn(f"Configuration files contain overlapping keys: {intersect}.") + raise ValueError( + f"Configuration files contain overlapping keys: {intersect}." + ) for k in tmp.keys(): cfg_data[k] = tmp[k].get() cfg.set(cfg_data) diff --git a/flepimop/gempyor_pkg/tests/cli/test_flepimop_patch_cli.py b/flepimop/gempyor_pkg/tests/cli/test_flepimop_patch_cli.py index 72d0134b9..053aed7f0 100644 --- a/flepimop/gempyor_pkg/tests/cli/test_flepimop_patch_cli.py +++ b/flepimop/gempyor_pkg/tests/cli/test_flepimop_patch_cli.py @@ -9,7 +9,7 @@ @pytest.mark.parametrize( - ("data_one", "data_two", "expected_parameters"), + ("data_one", "data_two"), ( ( { @@ -26,7 +26,6 @@ } } }, - {"gamma": {"value": 3.4}}, ), ( { @@ -44,16 +43,14 @@ } } }, - {"gamma": {"value": 3.4}}, ), ), ) -def test_patch_seir_parameters_behavior( +def test_overlapping_sections_value_error( tmp_path: Path, monkeypatch: pytest.MonkeyPatch, data_one: dict[str, Any], data_two: dict[str, Any], - expected_parameters: dict[str, Any], ) -> None: # Setup the test monkeypatch.chdir(tmp_path) @@ -64,13 +61,9 @@ def test_patch_seir_parameters_behavior( # Invoke the command runner = CliRunner() - with pytest.warns( - UserWarning, match="^Configuration files contain overlapping keys: {'seir'}.$" - ): - result = runner.invoke(patch, [config_one.name, config_two.name]) - assert result.exit_code == 0 - - # Check the output - patched_config = yaml.safe_load(result.output) - assert "seir" in patched_config - assert patched_config["seir"]["parameters"] == expected_parameters + result = runner.invoke(patch, [config_one.name, config_two.name]) + assert result.exit_code == 1 + assert isinstance(result.exception, ValueError) + assert ( + str(result.exception) == "Configuration files contain overlapping keys: {'seir'}." + ) diff --git a/flepimop/gempyor_pkg/tests/shared_cli/test_parse_config_files.py b/flepimop/gempyor_pkg/tests/shared_cli/test_parse_config_files.py index a64fc38f6..a2aa55c47 100644 --- a/flepimop/gempyor_pkg/tests/shared_cli/test_parse_config_files.py +++ b/flepimop/gempyor_pkg/tests/shared_cli/test_parse_config_files.py @@ -158,7 +158,7 @@ def test_multifile_config_collision( tmpconfigfile1 = config_file(tmp_path, testdict1, "config1.yaml") tmpconfigfile2 = config_file(tmp_path, testdict2, "config2.yaml") mockconfig = mock_empty_config() - with pytest.warns(UserWarning, match=r"foo"): + with pytest.raises(ValueError, match=r"foo"): parse_config_files(mockconfig, config_files=[tmpconfigfile1, tmpconfigfile2]) for k, v in (testdict1 | testdict2).items(): assert mockconfig[k].get(v) == v