Skip to content

Commit d6b2563

Browse files
committed
Added test for the align-and-merge registration workflow
1 parent 8774ecc commit d6b2563

1 file changed

Lines changed: 108 additions & 0 deletions

File tree

Lines changed: 108 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,108 @@
1+
from pathlib import Path
2+
3+
import pytest
4+
from sqlmodel import Session as SQLModelSession, select
5+
6+
import murfey.util.db as MurfeyDB
7+
from murfey.workflows.clem.register_align_and_merge_results import run
8+
from tests.conftest import ExampleVisit, get_or_create_db_entry
9+
10+
session_id = ExampleVisit.murfey_session_id + 1
11+
visit_name = f"{ExampleVisit.proposal_code}{ExampleVisit.proposal_number}-{ExampleVisit.visit_number}"
12+
processed_dir_name = "processed"
13+
project_name = "Grid_1"
14+
15+
16+
@pytest.mark.parametrize(
17+
"test_params",
18+
[ # Registered data | Incoming data
19+
["_Lng_LVCC", ""],
20+
["_Lng_LVCC", "_Lng_LVCC"],
21+
["", ""],
22+
["", "_Lng_LVCC"],
23+
],
24+
)
25+
def test_run(
26+
test_params: tuple[str, str], murfey_db_session: SQLModelSession, tmp_path: Path
27+
):
28+
# Unpack test params
29+
registered_type, incoming_type = test_params
30+
31+
# Create a session to insert for this test
32+
murfey_session: MurfeyDB.Session = get_or_create_db_entry(
33+
murfey_db_session,
34+
MurfeyDB.Session,
35+
lookup_kwargs={
36+
"id": session_id,
37+
"name": visit_name,
38+
"visit": visit_name,
39+
"instrument_name": ExampleVisit.instrument_name,
40+
},
41+
)
42+
43+
# Create an ImagingSite entry using the existing values
44+
registered_position_name = "Position_1" + registered_type
45+
image_path = (
46+
tmp_path
47+
/ visit_name
48+
/ "processed"
49+
/ project_name
50+
/ "TileScan_1"
51+
/ registered_position_name
52+
/ "*.tiff"
53+
)
54+
registered_series_name = f"{project_name}--TileScan_1--{registered_position_name}"
55+
site_name = registered_series_name.rstrip(registered_type)
56+
get_or_create_db_entry(
57+
murfey_db_session,
58+
MurfeyDB.ImagingSite,
59+
lookup_kwargs={
60+
"id": murfey_session.id,
61+
"site_name": site_name,
62+
"image_path": str(image_path),
63+
},
64+
)
65+
66+
# Create the incoming message
67+
incoming_position_name = "Position_1" + incoming_type
68+
incoming_series_name = f"{project_name}--TileScan_1--{incoming_position_name}"
69+
# The site names should match
70+
assert site_name == incoming_series_name.rstrip(incoming_type)
71+
72+
message = {
73+
"session_id": murfey_session.id,
74+
"result": {
75+
"series_name": incoming_series_name,
76+
"image_stacks": [],
77+
"align_self": None,
78+
"flatten": None,
79+
"align_across": None,
80+
"output_file": tmp_path / "dummy",
81+
"thumbnail": None,
82+
"thumbnail_size": None,
83+
},
84+
}
85+
86+
# Run the function and check that the expected values were created
87+
result = run(message, murfey_db_session)
88+
assert result["success"]
89+
90+
imaging_site = murfey_db_session.exec(
91+
select(MurfeyDB.ImagingSite)
92+
.where(MurfeyDB.ImagingSite.session_id == murfey_session.id)
93+
.where(
94+
MurfeyDB.ImagingSite.site_name == incoming_series_name.rstrip(incoming_type)
95+
)
96+
).one()
97+
98+
# Check that 'composite_created' is updated correctly
99+
if (
100+
# Both data types match
101+
(registered_type and incoming_type)
102+
or (not registered_type and not incoming_type)
103+
# Registered type is raw data, while incoming is denoised
104+
or (not registered_type and incoming_type)
105+
):
106+
assert imaging_site.composite_created
107+
else:
108+
assert not imaging_site.composite_created

0 commit comments

Comments
 (0)