Skip to content

Commit 821ac69

Browse files
committed
tests: make topostats tests flexible to key name
We are going to switch from having the `topostats_file_version` as the name for the metadata that `.topostats` files were generated with to using the `topostats_version` as key which will align with the release tag and make it easier for work to be reproducible. This small commit adds the `version_key` variable to the `tests/test_topostats.py::test_load_topostats()` test so that the key against which tests are made will work with old versions and future versions.
1 parent 42d7903 commit 821ac69

File tree

1 file changed

+37
-6
lines changed

1 file changed

+37
-6
lines changed

tests/test_topostats.py

Lines changed: 37 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,24 @@
99
BASE_DIR = Path.cwd()
1010
RESOURCES = BASE_DIR / "tests" / "resources"
1111

12+
# pylint: disable=too-many-positional-arguments
13+
1214

1315
@pytest.mark.parametrize(
14-
("file_name", "topostats_file_version", "image_shape", "pixel_to_nm_scaling", "data_keys", "image_sum"),
16+
(
17+
"file_name",
18+
"version_key",
19+
"version",
20+
"image_shape",
21+
"pixel_to_nm_scaling",
22+
"data_keys",
23+
"image_sum",
24+
),
1525
[
1626
pytest.param(
1727
"sample_0_1.topostats",
18-
0.1,
28+
"topostats_file_version",
29+
"0.1",
1930
(64, 64),
2031
1.97601171875,
2132
{
@@ -28,7 +39,8 @@
2839
),
2940
pytest.param(
3041
"sample_0_2.topostats",
31-
0.2,
42+
"topostats_file_version",
43+
"0.2",
3244
(64, 64),
3345
1.97601171875,
3446
{
@@ -49,11 +61,27 @@
4961
1176.601500471239,
5062
id="version 0.2",
5163
),
64+
pytest.param(
65+
"sample_2_3_2.topostats",
66+
"topostats_version",
67+
"2.3.2",
68+
(64, 64),
69+
1.97601171875,
70+
{
71+
"pixel_to_nm_scaling",
72+
"image",
73+
"topostats_version",
74+
},
75+
112069.51332503435,
76+
id="version 2.3.2",
77+
marks=pytest.mark.xfail(reason="Not yet implemented"),
78+
),
5279
],
5380
)
5481
def test_load_topostats(
5582
file_name: str,
56-
topostats_file_version: float,
83+
version_key: str,
84+
version: str,
5785
image_shape: tuple,
5886
pixel_to_nm_scaling: float,
5987
data_keys: set[str],
@@ -64,11 +92,14 @@ def test_load_topostats(
6492
topostats_data = topostats.load_topostats(file_path)
6593

6694
assert set(topostats_data.keys()) == data_keys # type: ignore
67-
assert topostats_data["topostats_file_version"] == topostats_file_version
95+
if version_key == "topostats_file_version":
96+
assert topostats_data[version_key] == float(version)
97+
else:
98+
assert topostats_data[version_key] == version
6899
assert topostats_data["pixel_to_nm_scaling"] == pixel_to_nm_scaling
69100
assert topostats_data["image"].shape == image_shape
70101
assert topostats_data["image"].sum() == image_sum
71-
if topostats_file_version >= 0.2:
102+
if version >= "0.2":
72103
assert isinstance(topostats_data["img_path"], Path)
73104

74105

0 commit comments

Comments
 (0)