Skip to content

Commit 3ca97cd

Browse files
committed
Added test module for the 'register_atlas' FIB workflow
1 parent e284292 commit 3ca97cd

1 file changed

Lines changed: 83 additions & 0 deletions

File tree

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
from pathlib import Path
2+
3+
import pytest
4+
from pytest_mock import MockerFixture
5+
from sqlmodel import Session, select
6+
7+
import murfey.util.db as MurfeyDB
8+
from murfey.workflows.fib.register_atlas import FIBAtlasMetadata, run
9+
10+
session_id = 10
11+
visit_name = "cm12345-6"
12+
instrument_name = "test_instrument"
13+
14+
15+
@pytest.fixture
16+
def visit_dir(tmp_path: Path):
17+
visit_dir = tmp_path / "data/2020" / visit_name
18+
visit_dir.mkdir(parents=True, exist_ok=True)
19+
return visit_dir
20+
21+
22+
def test_parse_metadata():
23+
pass
24+
25+
26+
def test_register_fib_imaging_site():
27+
pass
28+
29+
30+
def test_run_with_db(
31+
mocker: MockerFixture,
32+
visit_dir: Path,
33+
murfey_db_session: Session,
34+
):
35+
test_file = (
36+
visit_dir / "maps/LayersData/Layer/Electron Snapshot/Electron Snapshot.tiff"
37+
)
38+
39+
# Add a test visit to the database
40+
if not (
41+
session_entry := murfey_db_session.exec(
42+
select(MurfeyDB.Session).where(MurfeyDB.Session.id == session_id)
43+
).one_or_none()
44+
):
45+
session_entry = MurfeyDB.Session(id=session_id)
46+
session_entry.name = visit_name
47+
session_entry.visit = visit_name
48+
session_entry.instrument_name = instrument_name
49+
50+
murfey_db_session.add(session_entry)
51+
murfey_db_session.commit()
52+
53+
# Mock the metadata returned from the image file
54+
mock_metadata = FIBAtlasMetadata(
55+
visit_name=visit_name,
56+
file=test_file,
57+
voltage=2000,
58+
shift_x=0,
59+
shift_y=0,
60+
len_x=0.003072,
61+
len_y=0.002048,
62+
pos_x=0.003,
63+
pos_y=0.0003,
64+
pos_z=0.01,
65+
rotation=-1.309,
66+
tilt_alpha=0.8,
67+
tilt_beta=0,
68+
pixels_x=3072,
69+
pixels_y=2048,
70+
pixel_size_x=1e-6,
71+
pixel_size_y=1e-6,
72+
)
73+
mocker.patch(
74+
"murfey.workflows.fib.register_atlas._parse_metadata",
75+
return_value=mock_metadata,
76+
)
77+
78+
# Run the function and check that it's run through to completion
79+
assert run(
80+
session_id=session_id,
81+
file=test_file,
82+
murfey_db=murfey_db_session,
83+
)

0 commit comments

Comments
 (0)