-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
flepimop patch
unit test for seir::parameters
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
1 parent
b32cad8
commit b21cfcc
Showing
1 changed file
with
76 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |