|
| 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('.jpg')}", |
| 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