Skip to content

Commit b9bc8f6

Browse files
committed
Added unit test for the 'atlas_jpg_from_mrc' function
1 parent 93537e0 commit b9bc8f6

File tree

1 file changed

+39
-0
lines changed

1 file changed

+39
-0
lines changed
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
from pathlib import Path
2+
from unittest.mock import MagicMock
3+
4+
import numpy as np
5+
from pytest_mock import MockerFixture
6+
7+
from murfey.workflows.spa.atlas import atlas_jpg_from_mrc
8+
9+
10+
def test_atlas_jpg_from_mrc(mocker: MockerFixture, tmp_path: Path):
11+
visit_name = "test_visit"
12+
instrument_name = "test"
13+
14+
# Create a 16-bit grayscale image
15+
shape = (64, 64)
16+
test_data = np.ones(shape).astype("uint16")
17+
18+
# Mock out the data returned from openning the file
19+
mock_mrcfile = mocker.patch("murfey.workflows.spa.atlas.mrcfile")
20+
mock_mrc = MagicMock()
21+
mock_mrc.data = test_data
22+
mock_mrcfile.open.return_value.__enter__.return_value = mock_mrc
23+
24+
# Mock the return result of 'get_machine_config()'
25+
mock_machine_config = MagicMock()
26+
mock_machine_config.processed_directory_name = "processed"
27+
mocker.patch(
28+
"murfey.workflows.spa.atlas.get_machine_config",
29+
return_value={"test": mock_machine_config},
30+
)
31+
32+
# 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"
36+
test_file.touch(exist_ok=True)
37+
38+
# Run the function
39+
atlas_jpg_from_mrc(instrument_name, visit_name, test_file)

0 commit comments

Comments
 (0)