Skip to content

Commit 2d13a05

Browse files
committed
Test for atlas context
1 parent babfea4 commit 2d13a05

File tree

2 files changed

+94
-2
lines changed

2 files changed

+94
-2
lines changed

src/murfey/client/contexts/atlas.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ def post_transfer(
4646
function_name="make_atlas_jpg",
4747
token=self._token,
4848
session_id=environment.murfey_session,
49-
data={"path": str(transferred_atlas_name)},
49+
data={"path": str(transferred_atlas_name).replace("//", "/")},
5050
)
5151
logger.info(
5252
f"Submitted request to create JPG image of atlas {str(transferred_atlas_name)!r}"
@@ -87,7 +87,7 @@ def post_transfer(
8787
dcg_data = {
8888
"experiment_type_id": 44, # Atlas
8989
"tag": str(transferred_file.parent),
90-
"atlas": str(transferred_atlas_name),
90+
"atlas": str(transferred_atlas_name).replace("//", "/"),
9191
"sample": sample,
9292
"atlas_pixel_size": atlas_pixel_size,
9393
}
Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
from unittest.mock import patch
2+
from urllib.parse import urlparse
3+
4+
from murfey.client.contexts.atlas import AtlasContext
5+
from murfey.client.instance_environment import MurfeyInstanceEnvironment
6+
7+
8+
def test_atlas_context_initialisation(tmp_path):
9+
context = AtlasContext("tomo", tmp_path, "token")
10+
assert context.name == "Atlas"
11+
assert context._acquisition_software == "tomo"
12+
assert context._basepath == tmp_path
13+
assert context._token == "token"
14+
15+
16+
@patch("murfey.client.contexts.atlas.capture_post")
17+
def test_atlas_context_mrc(mock_capture_post, tmp_path):
18+
env = MurfeyInstanceEnvironment(
19+
url=urlparse("http://localhost:8000"),
20+
client_id=0,
21+
sources=[tmp_path / "cm12345-6"],
22+
default_destinations={
23+
tmp_path / "cm12345-6": f"{tmp_path}/destination/cm12345-6"
24+
},
25+
instrument_name="",
26+
visit="cm12345-6",
27+
murfey_session=1,
28+
)
29+
context = AtlasContext("tomo", tmp_path, "token")
30+
31+
atlas_mrc = tmp_path / "cm12345-6/Supervisor_atlas/Sample2/Atlas/Atlas_1.mrc"
32+
atlas_mrc.parent.mkdir(parents=True)
33+
atlas_mrc.touch()
34+
35+
context.post_transfer(
36+
atlas_mrc,
37+
environment=env,
38+
)
39+
mock_capture_post.assert_called_once_with(
40+
base_url="http://localhost:8000",
41+
router_name="session_control.spa_router",
42+
function_name="make_atlas_jpg",
43+
token="token",
44+
session_id=1,
45+
data={"path": f"{tmp_path}/destination/{atlas_mrc.relative_to(tmp_path)}"},
46+
)
47+
48+
49+
@patch("murfey.client.contexts.atlas.capture_post")
50+
def test_atlas_context_xml(mock_capture_post, tmp_path):
51+
env = MurfeyInstanceEnvironment(
52+
url=urlparse("http://localhost:8000"),
53+
client_id=0,
54+
sources=[tmp_path / "cm12345-6"],
55+
default_destinations={
56+
tmp_path / "cm12345-6": f"{tmp_path}/destination/cm12345-6"
57+
},
58+
instrument_name="",
59+
visit="cm12345-6",
60+
murfey_session=1,
61+
)
62+
context = AtlasContext("tomo", tmp_path, "token")
63+
64+
atlas_pixel_size = 4.6
65+
atlas_xml = tmp_path / "cm12345-6/Supervisor_atlas/Sample2/Atlas/Atlas_1.xml"
66+
atlas_xml.parent.mkdir(parents=True)
67+
with open(atlas_xml, "w") as new_xml:
68+
new_xml.write(
69+
f"<MicroscopeImage><SpatialScale><pixelSize><x><numericValue>{atlas_pixel_size}"
70+
"</numericValue></x></pixelSize></SpatialScale></MicroscopeImage>"
71+
)
72+
73+
context.post_transfer(
74+
atlas_xml,
75+
environment=env,
76+
)
77+
dcg_data = {
78+
"experiment_type_id": 44, # Atlas
79+
"tag": str(atlas_xml.parent),
80+
"atlas": f"{tmp_path}/destination/{atlas_xml.relative_to(tmp_path).with_suffix('.mrc')}",
81+
"sample": 2,
82+
"atlas_pixel_size": atlas_pixel_size * 7.8,
83+
}
84+
mock_capture_post.assert_called_once_with(
85+
base_url="http://localhost:8000",
86+
router_name="workflow.router",
87+
function_name="register_dc_group",
88+
token="token",
89+
visit_name="cm12345-6",
90+
session_id=1,
91+
data=dcg_data,
92+
)

0 commit comments

Comments
 (0)