Skip to content
This repository has been archived by the owner on Sep 2, 2024. It is now read-only.

Commit

Permalink
Simplify xrc tests slightly
Browse files Browse the repository at this point in the history
  • Loading branch information
DominicOram committed Jun 10, 2024
1 parent a66bfb4 commit 2274ac6
Showing 1 changed file with 9 additions and 14 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
from functools import partial
from typing import Any, Dict, Generator
from typing import Dict, Generator
from unittest.mock import ANY, MagicMock, patch

import bluesky.plan_stubs as bps
Expand All @@ -14,6 +13,7 @@

from hyperion.experiment_plans.grid_detect_then_xray_centre_plan import (
GridDetectThenXRayCentreComposite,
OavGridDetectionComposite,
detect_grid_and_do_gridscan,
grid_detect_then_xray_centre,
)
Expand All @@ -22,13 +22,12 @@


def _fake_grid_detection(
devices: Any,
devices: OavGridDetectionComposite,
parameters: OAVParameters,
snapshot_template: str,
snapshot_dir: str,
grid_width_microns: float = 0,
box_size_um: float = 0.0,
smargon=None,
):
oav = i03.oav(fake_with_ophyd_sim=True)
oav.grid_snapshot.box_width.put(635.00986)
Expand All @@ -37,20 +36,20 @@ def _fake_grid_detection(
oav.grid_snapshot.num_boxes_y.put(4)
yield from bps.create(CONST.DESCRIPTORS.OAV_SNAPSHOT_TRIGGERED)
yield from bps.read(oav.grid_snapshot)
yield from bps.read(smargon)
yield from bps.read(devices.smargon)
yield from bps.save()

# second grid detection: x * z, so num_boxes_y refers to smargon z
oav.grid_snapshot.num_boxes_x.put(10)
oav.grid_snapshot.num_boxes_y.put(1)
yield from bps.create(CONST.DESCRIPTORS.OAV_SNAPSHOT_TRIGGERED)
yield from bps.read(oav.grid_snapshot)
yield from bps.read(smargon)
yield from bps.read(devices.smargon)
yield from bps.save()


@pytest.fixture
def grid_detect_devices(aperture_scatterguard, backlight, detector_motion):
def grid_detect_devices(aperture_scatterguard, backlight, detector_motion, smargon):
return GridDetectThenXRayCentreComposite(
aperture_scatterguard=aperture_scatterguard,
attenuator=MagicMock(),
Expand All @@ -61,7 +60,7 @@ def grid_detect_devices(aperture_scatterguard, backlight, detector_motion):
flux=MagicMock(),
oav=MagicMock(),
pin_tip_detection=MagicMock(),
smargon=MagicMock(),
smargon=smargon,
synchrotron=MagicMock(),
s4_slit_gaps=MagicMock(),
undulator=MagicMock(),
Expand Down Expand Up @@ -100,9 +99,7 @@ def test_detect_grid_and_do_gridscan(
test_full_grid_scan_params: GridScanWithEdgeDetect,
test_config_files: Dict,
):
mock_grid_detection_plan.side_effect = partial(
_fake_grid_detection, smargon=smargon
)
mock_grid_detection_plan.side_effect = _fake_grid_detection
grid_detect_devices.oav.parameters = OAVConfigParams(
test_config_files["zoom_params_file"], test_config_files["display_config"]
)
Expand Down Expand Up @@ -159,9 +156,7 @@ def test_when_full_grid_scan_run_then_parameters_sent_to_fgs_as_expected(
):
oav_params = OAVParameters("xrayCentring", test_config_files["oav_config_json"])

mock_grid_detection_plan.side_effect = partial(
_fake_grid_detection, smargon=smargon
)
mock_grid_detection_plan.side_effect = _fake_grid_detection

grid_detect_devices.oav.parameters = OAVConfigParams(
test_config_files["zoom_params_file"], test_config_files["display_config"]
Expand Down

0 comments on commit 2274ac6

Please sign in to comment.