-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathtest_context.py
More file actions
157 lines (139 loc) · 5.1 KB
/
Copy pathtest_context.py
File metadata and controls
157 lines (139 loc) · 5.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
from unittest.mock import patch
from urllib.parse import urlparse
from murfey.client.context import ensure_dcg_exists
from murfey.client.instance_environment import MurfeyInstanceEnvironment
@patch("murfey.client.context.capture_post")
def test_ensure_dcg_exists_tomo(mock_capture_post, tmp_path):
env = MurfeyInstanceEnvironment(
url=urlparse("http://localhost:8000"),
client_id=0,
sources=[tmp_path / "cm12345-6/metadata_folder"],
default_destinations={
tmp_path
/ "cm12345-6/metadata_folder": f"{tmp_path}/destination/cm12345-6/raw"
},
instrument_name="",
visit="cm12345-6",
murfey_session=1,
)
metadata_source = tmp_path / "cm12345-6/metadata_folder"
metadata_source.mkdir(parents=True)
with open(metadata_source / "Session.dm", "w") as dm_file:
dm_file.write(
"<TomographySession><AtlasId>"
r"X:\cm12345-6\atlas\atlas_metadata\Sample6\Atlas\Atlas.dm"
"</AtlasId></TomographySession>"
)
atlas_xml = tmp_path / "cm12345-6/atlas/atlas_metadata/Sample6/Atlas/Atlas_4.xml"
atlas_xml.parent.mkdir(parents=True)
with open(atlas_xml, "w") as xml_file:
xml_file.write(
"<MicroscopeImage><SpatialScale><pixelSize><x><numericValue>4.7"
"</numericValue></x></pixelSize></SpatialScale></MicroscopeImage>"
)
ensure_dcg_exists(
collection_type="tomo",
metadata_source=metadata_source,
environment=env,
token="token",
)
dcg_data = {
"experiment_type_id": 36,
"tag": f"{tmp_path}/metadata_folder",
"atlas": f"{tmp_path}/destination/{atlas_xml.relative_to(tmp_path).with_suffix('.jpg')}",
"sample": 6,
"atlas_pixel_size": 4.7 * 7.8,
}
mock_capture_post.assert_called_once_with(
base_url="http://localhost:8000",
router_name="workflow.router",
function_name="register_dc_group",
token="token",
visit_name="cm12345-6",
session_id=1,
data=dcg_data,
)
@patch("murfey.client.context.capture_post")
def test_ensure_dcg_exists_spa(mock_capture_post, tmp_path):
env = MurfeyInstanceEnvironment(
url=urlparse("http://localhost:8000"),
client_id=0,
sources=[tmp_path / "cm12345-6/metadata_folder"],
default_destinations={
tmp_path
/ "cm12345-6/metadata_folder": f"{tmp_path}/destination/cm12345-6/raw",
},
instrument_name="",
visit="cm12345-6",
murfey_session=1,
)
metadata_source = tmp_path / "cm12345-6/metadata_folder"
metadata_source.mkdir(parents=True)
with open(metadata_source / "EpuSession.dm", "w") as dm_file:
dm_file.write(
"<EpuSessionXml><Samples><_items><SampleXml><AtlasId z:Id='10'>"
r"X:\cm12345-6\atlas\atlas_metadata\Sample6\Atlas\Atlas.dm"
"</AtlasId></SampleXml><SampleXml></SampleXml></_items></Samples></EpuSessionXml>"
)
# Make data location
(tmp_path / "metadata_folder/Images-Disc1").mkdir(parents=True)
atlas_xml = tmp_path / "cm12345-6/atlas/atlas_metadata/Sample6/Atlas/Atlas_4.xml"
atlas_xml.parent.mkdir(parents=True)
with open(atlas_xml, "w") as xml_file:
xml_file.write(
"<MicroscopeImage><SpatialScale><pixelSize><x><numericValue>4.7"
"</numericValue></x></pixelSize></SpatialScale></MicroscopeImage>"
)
ensure_dcg_exists(
collection_type="spa",
metadata_source=metadata_source / "Images-Disc1",
environment=env,
token="token",
)
dcg_data = {
"experiment_type_id": 37,
"tag": f"{tmp_path}/metadata_folder/Images-Disc1",
"atlas": f"{tmp_path}/destination/{atlas_xml.relative_to(tmp_path).with_suffix('.jpg')}",
"sample": 6,
"atlas_pixel_size": 4.7 * 7.8,
}
mock_capture_post.assert_called_once_with(
base_url="http://localhost:8000",
router_name="workflow.router",
function_name="register_dc_group",
token="token",
visit_name="cm12345-6",
session_id=1,
data=dcg_data,
)
@patch("murfey.client.context.capture_post")
def test_ensure_dcg_exists_spa_missing_xml(mock_capture_post, tmp_path):
env = MurfeyInstanceEnvironment(
url=urlparse("http://localhost:8000"),
client_id=0,
sources=[tmp_path],
default_destinations={tmp_path: str(tmp_path)},
instrument_name="",
visit="cm12345-6",
murfey_session=1,
)
metadata_source = tmp_path / "cm12345-6/metadata_folder"
ensure_dcg_exists(
collection_type="spa",
metadata_source=metadata_source,
environment=env,
token="token",
)
dcg_data = {
"experiment_type_id": 37,
"tag": f"{tmp_path}/metadata_folder",
}
mock_capture_post.assert_called_once_with(
base_url="http://localhost:8000",
router_name="workflow.router",
function_name="register_dc_group",
token="token",
visit_name="cm12345-6",
session_id=1,
data=dcg_data,
)