|
| 1 | +from pathlib import Path |
| 2 | +from unittest.mock import MagicMock |
| 3 | + |
| 4 | +import pytest |
| 5 | + |
| 6 | +from murfey.server.ispyb import TransportManager |
| 7 | +from murfey.workflows.clem.process_raw_lifs import zocalo_cluster_request |
| 8 | + |
| 9 | +# Set up variables |
| 10 | +visit_name = "cm12345-6" |
| 11 | +root_folder = "images" |
| 12 | +session_id = 0 |
| 13 | +instrument_name = "clem" |
| 14 | +feedback_queue = "murfey_feedback" |
| 15 | + |
| 16 | + |
| 17 | +@pytest.fixture |
| 18 | +def raw_dir(tmp_path: Path): |
| 19 | + raw_dir = tmp_path / visit_name / root_folder |
| 20 | + raw_dir.mkdir(parents=True, exist_ok=True) |
| 21 | + return raw_dir |
| 22 | + |
| 23 | + |
| 24 | +@pytest.fixture |
| 25 | +def lif_file(raw_dir: Path): |
| 26 | + file = raw_dir / "test_file.lif" |
| 27 | + if not file.exists(): |
| 28 | + file.touch() |
| 29 | + return file |
| 30 | + |
| 31 | + |
| 32 | +def test_zocalo_cluster_request( |
| 33 | + lif_file: Path, |
| 34 | + raw_dir: Path, |
| 35 | +): |
| 36 | + |
| 37 | + # Create a mock tranpsort object |
| 38 | + mock_transport = MagicMock(spec=TransportManager) |
| 39 | + mock_transport.feedback_queue = feedback_queue |
| 40 | + |
| 41 | + # Run the function with the listed parameters |
| 42 | + zocalo_cluster_request( |
| 43 | + file=lif_file, |
| 44 | + root_folder=root_folder, |
| 45 | + session_id=session_id, |
| 46 | + instrument_name=instrument_name, |
| 47 | + messenger=mock_transport, |
| 48 | + ) |
| 49 | + |
| 50 | + # Construct the recipe that we expect to send |
| 51 | + job_name = "--".join( |
| 52 | + [ |
| 53 | + p.replace(" ", "_") if " " in p else p |
| 54 | + for p in (lif_file.relative_to(raw_dir).parent / lif_file.stem).parts |
| 55 | + ] |
| 56 | + ) |
| 57 | + sent_recipe = { |
| 58 | + "recipes": ["clem-lif-to-stack"], |
| 59 | + "parameters": { |
| 60 | + # Job parameters |
| 61 | + "lif_file": f"{str(lif_file)}", |
| 62 | + "root_folder": root_folder, |
| 63 | + # Other recipe parameters |
| 64 | + "session_dir": f"{str(raw_dir.parent)}", |
| 65 | + "session_id": session_id, |
| 66 | + "job_name": job_name, |
| 67 | + "feedback_queue": feedback_queue, |
| 68 | + }, |
| 69 | + } |
| 70 | + mock_transport.send.assert_called_once_with( |
| 71 | + "processing_recipe", |
| 72 | + sent_recipe, |
| 73 | + new_connection=True, |
| 74 | + ) |
| 75 | + pass |
0 commit comments