Skip to content

Commit

Permalink
featire: Ensure img_path is of type Path
Browse files Browse the repository at this point in the history
Closes #106

Ensures that if fileversion >= 0.2 is being loaded that the `data["img_path"]` variable is of type `Path`.

Adds to the test suite a 0.2 sample file to check this (and expands on the keys of the dictionary).
  • Loading branch information
ns-rse committed Jan 29, 2025
1 parent 022dcf2 commit 0135ec9
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 3 deletions.
3 changes: 2 additions & 1 deletion AFMReader/topostats.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,8 @@ def load_topostats(file_path: Path | str) -> tuple:
try:
with h5py.File(file_path, "r") as f:
data = unpack_hdf5(open_hdf5_file=f, group_path="/")

if data["topostats_file_version"] >= 0.2:
data["img_path"] = Path(data["img_path"])
file_version = data["topostats_file_version"]
logger.info(f"[{filename}] TopoStats file version : {file_version}")
image = data["image"]
Expand Down
Binary file added tests/resources/sample_0_2.topostats
Binary file not shown.
33 changes: 31 additions & 2 deletions tests/test_topostats.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,36 @@
0.1,
(64, 64),
1.97601171875,
{"topostats_file_version", "image", "pixel_to_nm_scaling"},
{
"pixel_to_nm_scaling",
"image",
"topostats_file_version",
},
112069.51332503435,
id="version",
id="version 0.1",
),
pytest.param(
"sample_0_2.topostats",
0.2,
(64, 64),
1.97601171875,
{
"disordered_traces",
"filename",
"grain_curvature_stats",
"grain_masks",
"height_profiles",
"image",
"image_original",
"img_path",
"nodestats",
"ordered_traces",
"pixel_to_nm_scaling",
"splining",
"topostats_file_version",
},
1176.601500471239,
id="version 0.2",
),
],
)
Expand All @@ -47,3 +74,5 @@ def test_load_topostats(
assert set(result_data.keys()) == data_keys # type: ignore
assert result_data["topostats_file_version"] == topostats_file_version
assert result_image.sum() == image_sum
if topostats_file_version >= 0.2:
assert isinstance(result_data["img_path"], Path)

0 comments on commit 0135ec9

Please sign in to comment.