Skip to content

Commit 2ce7816

Browse files
committed
Parametrised test to further improve coverage
1 parent 88c5bde commit 2ce7816

File tree

1 file changed

+36
-6
lines changed

1 file changed

+36
-6
lines changed

tests/workflows/spa/test_atlas_workflow.py

Lines changed: 36 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,29 @@
22
from unittest.mock import MagicMock
33

44
import numpy as np
5+
import pytest
56
from pytest_mock import MockerFixture
7+
from werkzeug.utils import secure_filename
68

79
from murfey.workflows.spa.atlas import atlas_jpg_from_mrc
810

11+
atlas_jpg_from_mrc_test_matrix = (
12+
("Atlas1.mrc",),
13+
("Sample1/Atlas1.mrc",),
14+
)
915

10-
def test_atlas_jpg_from_mrc(mocker: MockerFixture, tmp_path: Path):
16+
17+
@pytest.mark.parametrize("test_params", atlas_jpg_from_mrc_test_matrix)
18+
def test_atlas_jpg_from_mrc(
19+
mocker: MockerFixture, tmp_path: Path, test_params: tuple[str]
20+
):
21+
# Unpack test params
22+
(file_name_stub,) = test_params
23+
24+
# Set up mock session params
1125
visit_name = "test_visit"
1226
instrument_name = "test"
27+
processed_dir_name = "processed"
1328

1429
# Create a 16-bit grayscale image
1530
shape = (64, 64)
@@ -23,17 +38,32 @@ def test_atlas_jpg_from_mrc(mocker: MockerFixture, tmp_path: Path):
2338

2439
# Mock the return result of 'get_machine_config()'
2540
mock_machine_config = MagicMock()
26-
mock_machine_config.processed_directory_name = "processed"
41+
mock_machine_config.processed_directory_name = processed_dir_name
2742
mocker.patch(
2843
"murfey.workflows.spa.atlas.get_machine_config",
2944
return_value={"test": mock_machine_config},
3045
)
3146

3247
# Create a test file
33-
test_dir = tmp_path / instrument_name / "data" / visit_name / "atlas"
34-
test_dir.mkdir(parents=True, exist_ok=True)
35-
test_file = test_dir / "Atlas1.mrc"
48+
test_file = (
49+
tmp_path / instrument_name / "data" / visit_name / "atlas" / file_name_stub
50+
)
51+
test_file.parent.mkdir(parents=True, exist_ok=True)
3652
test_file.touch(exist_ok=True)
3753

38-
# Run the function
54+
# Create the expected destination directory and file
55+
processed_dir = (
56+
tmp_path / instrument_name / "data" / visit_name / processed_dir_name / "atlas"
57+
)
58+
sample_id = "Sample"
59+
for part in file_name_stub.split("/"):
60+
if part.startswith("Sample"):
61+
sample_id = part
62+
break
63+
processed_file_name = processed_dir / secure_filename(
64+
f"{sample_id}_{test_file.stem}_fullres.jpg"
65+
)
66+
67+
# Run the function and check that the expected calls are made
3968
atlas_jpg_from_mrc(instrument_name, visit_name, test_file)
69+
assert processed_file_name.exists()

0 commit comments

Comments
 (0)