Skip to content

Commit

Permalink
Upgrade TL key collision from warning to error
Browse files Browse the repository at this point in the history
  • Loading branch information
TimothyWillard committed Dec 11, 2024
1 parent d3f89d2 commit b5142d9
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 17 deletions.
4 changes: 3 additions & 1 deletion flepimop/gempyor_pkg/src/gempyor/shared_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
23 changes: 8 additions & 15 deletions flepimop/gempyor_pkg/tests/cli/test_flepimop_patch_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@


@pytest.mark.parametrize(
("data_one", "data_two", "expected_parameters"),
("data_one", "data_two"),
(
(
{
Expand All @@ -26,7 +26,6 @@
}
}
},
{"gamma": {"value": 3.4}},
),
(
{
Expand All @@ -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)
Expand All @@ -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'}."
)
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit b5142d9

Please sign in to comment.