Skip to content

Commit

Permalink
flepimop patch unit test for seir::parameters
Browse files Browse the repository at this point in the history
Added a unit test to demonstrate the issue described in
#375 (comment)
with respect to the `seir::parameters` section. Appears to be related to
if the parameters are a list or a dict.
  • Loading branch information
TimothyWillard committed Dec 10, 2024
1 parent b32cad8 commit b21cfcc
Showing 1 changed file with 76 additions and 0 deletions.
76 changes: 76 additions & 0 deletions flepimop/gempyor_pkg/tests/cli/test_flepimop_patch_cli.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
from pathlib import Path
from typing import Any

from click.testing import CliRunner
import pytest
import yaml

from gempyor.cli import patch


@pytest.mark.parametrize(
("data_one", "data_two", "expected_parameters"),
(
(
{
"seir": {
"parameters": {
"beta": {"value": 1.2},
}
}
},
{
"seir": {
"parameters": {
"gamma": {"value": 3.4},
}
}
},
{"gamma": {"value": 3.4}},
),
(
{
"seir": {
"parameters": {
"sigma": {"value": 5.6},
"gamma": {"value": 7.8},
}
}
},
{
"seir": {
"parameters": {
"gamma": {"value": 3.4},
}
}
},
{"gamma": {"value": 3.4}},
),
),
)
def test_patch_seir_parameters_behavior(
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)
config_one = tmp_path / "config_one.yml"
config_one.write_text(yaml.dump(data_one))
config_two = tmp_path / "config_two.yml"
config_two.write_text(yaml.dump(data_two))

# 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

0 comments on commit b21cfcc

Please sign in to comment.