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

Commit

Permalink
Fixed some type errors
Browse files Browse the repository at this point in the history
  • Loading branch information
DominicOram committed Dec 14, 2023
1 parent 734d5f7 commit cbd336c
Show file tree
Hide file tree
Showing 11 changed files with 61 additions and 58 deletions.
2 changes: 1 addition & 1 deletion src/hyperion/snapshot_plan.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import bluesky.plan_stubs as bps
import bluesky.preprocessors as bpp
from bluesky import RunEngine
from bluesky.run_engine import RunEngine

Check warning on line 3 in src/hyperion/snapshot_plan.py

View check run for this annotation

Codecov / codecov/patch

src/hyperion/snapshot_plan.py#L3

Added line #L3 was not covered by tests
from dodal.devices.aperture import Aperture
from dodal.devices.backlight import Backlight
from dodal.devices.oav.oav_detector import OAV
Expand Down
2 changes: 1 addition & 1 deletion tests/system_tests/experiment_plans/test_plan_system.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import bluesky.preprocessors as bpp
import pytest
from bluesky import RunEngine
from bluesky.run_engine import RunEngine
from dodal.beamlines import i03
from dodal.devices.s4_slit_gaps import S4SlitGaps
from dodal.devices.undulator import Undulator
Expand Down
8 changes: 4 additions & 4 deletions tests/unit_tests/device_setup_plans/test_setup_oav.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ def oav() -> OAV:
oav = i03.oav(fake_with_ophyd_sim=True)
oav.parameters = OAVConfigParams(ZOOM_LEVELS_XML, DISPLAY_CONFIGURATION)

oav.proc.port_name.sim_put("proc")
oav.cam.port_name.sim_put("CAM")
oav.proc.port_name.sim_put("proc") # type: ignore
oav.cam.port_name.sim_put("CAM") # type: ignore

oav.zoom_controller.zrst.set("1.0x")
oav.zoom_controller.onst.set("2.0x")
Expand All @@ -51,7 +51,7 @@ def fake_smargon() -> Smargon:
smargon.omega.user_setpoint._use_limits = False

def mock_set(motor, val):
motor.user_readback.sim_put(val)
motor.user_readback.sim_put(val) # type: ignore
return Status(done=True, success=True)

def patch_motor(motor):
Expand Down Expand Up @@ -115,7 +115,7 @@ def test_values_for_move_so_that_beam_is_at_pixel(
oav.parameters.beam_centre_i = beam_centre[0]
oav.parameters.beam_centre_j = beam_centre[1]

smargon.omega.user_readback.sim_put(angle)
smargon.omega.user_readback.sim_put(angle) # type: ignore

RE = RunEngine(call_returns_result=True)
pos = RE(
Expand Down
26 changes: 15 additions & 11 deletions tests/unit_tests/device_setup_plans/test_topup_plan.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import pytest
from bluesky.run_engine import RunEngine
from dodal.beamlines import i03
from dodal.devices.synchrotron import SynchrotronMode
from dodal.devices.synchrotron import Synchrotron, SynchrotronMode

from hyperion.device_setup_plans.check_topup import (
check_topup_and_wait_if_necessary,
Expand All @@ -13,16 +13,18 @@


@pytest.fixture
def synchrotron():
def synchrotron() -> Synchrotron:
return i03.synchrotron(fake_with_ophyd_sim=True)


@patch("hyperion.device_setup_plans.check_topup.wait_for_topup_complete")
@patch("hyperion.device_setup_plans.check_topup.bps.sleep")
def test_when_topup_before_end_of_collection_wait(fake_sleep, fake_wait, synchrotron):
synchrotron.machine_status.synchrotron_mode.sim_put(SynchrotronMode.USER.value)
synchrotron.top_up.start_countdown.sim_put(20.0)
synchrotron.top_up.end_countdown.sim_put(60.0)
def test_when_topup_before_end_of_collection_wait(
fake_sleep, fake_wait, synchrotron: Synchrotron
):
synchrotron.machine_status.synchrotron_mode.sim_put(SynchrotronMode.USER.value) # type: ignore
synchrotron.top_up.start_countdown.sim_put(20.0) # type: ignore
synchrotron.top_up.end_countdown.sim_put(60.0) # type: ignore

RE = RunEngine()
RE(
Expand Down Expand Up @@ -58,8 +60,8 @@ def fake_generator(value):

@patch("hyperion.device_setup_plans.check_topup.bps.sleep")
@patch("hyperion.device_setup_plans.check_topup.bps.null")
def test_no_waiting_if_decay_mode(fake_null, fake_sleep, synchrotron):
synchrotron.top_up.start_countdown.sim_put(-1)
def test_no_waiting_if_decay_mode(fake_null, fake_sleep, synchrotron: Synchrotron):
synchrotron.top_up.start_countdown.sim_put(-1) # type: ignore

RE = RunEngine()
RE(
Expand All @@ -74,9 +76,11 @@ def test_no_waiting_if_decay_mode(fake_null, fake_sleep, synchrotron):


@patch("hyperion.device_setup_plans.check_topup.bps.null")
def test_no_waiting_when_mode_does_not_allow_gating(fake_null, synchrotron):
synchrotron.top_up.start_countdown.sim_put(1.0)
synchrotron.machine_status.synchrotron_mode.sim_put(SynchrotronMode.SHUTDOWN.value)
def test_no_waiting_when_mode_does_not_allow_gating(
fake_null, synchrotron: Synchrotron
):
synchrotron.top_up.start_countdown.sim_put(1.0) # type: ignore
synchrotron.machine_status.synchrotron_mode.sim_put(SynchrotronMode.SHUTDOWN.value) # type: ignore

RE = RunEngine()
RE(
Expand Down
1 change: 0 additions & 1 deletion tests/unit_tests/device_setup_plans/test_utils.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
from unittest.mock import MagicMock

import pytest
from bluesky import RunEngine
from bluesky import plan_stubs as bps
from bluesky.run_engine import RunEngine
from dodal.beamlines import i03
Expand Down
6 changes: 3 additions & 3 deletions tests/unit_tests/device_setup_plans/test_xbpm_feedback.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ def fake_devices():
attenuator: Attenuator = make_fake_device(Attenuator)(name="atten")

def fake_attenuator_set(val):
attenuator.actual_transmission.sim_put(val)
attenuator.actual_transmission.sim_put(val) # type: ignore
return Status(done=True, success=True)

attenuator.set = MagicMock(side_effect=fake_attenuator_set)
Expand All @@ -43,7 +43,7 @@ def my_collection_plan():
assert xbpm_feedback.pause_feedback.get() == xbpm_feedback.PAUSE
yield from bps.null()

xbpm_feedback.pos_stable.sim_put(1)
xbpm_feedback.pos_stable.sim_put(1) # type: ignore

RE = RunEngine()
RE(my_collection_plan())
Expand Down Expand Up @@ -85,7 +85,7 @@ def test_given_xpbm_checks_pass_and_plan_fails_when_plan_run_with_decorator_then
xbpm_feedback: XBPMFeedback = fake_devices[0]
attenuator: Attenuator = fake_devices[1]

xbpm_feedback.pos_stable.sim_put(1)
xbpm_feedback.pos_stable.sim_put(1) # type: ignore

class MyException(Exception):
pass
Expand Down
8 changes: 4 additions & 4 deletions tests/unit_tests/experiment_plans/test_grid_detection_plan.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@ def fake_devices(smargon: Smargon, backlight: Backlight, test_config_files):
oav.mxsc.top.set([0,0,0,0,0,0,0,0,5,5,4,4,3,3,2,2,3,3,4,4]) # noqa: E231
# fmt: on

oav.mxsc.pin_tip.tip_x.sim_put(8)
oav.mxsc.pin_tip.tip_y.sim_put(5)
oav.mxsc.pin_tip.tip_x.sim_put(8) # type: ignore
oav.mxsc.pin_tip.tip_y.sim_put(5) # type: ignore

oav.parameters = OAVConfigParams(
test_config_files["zoom_params_file"], test_config_files["display_config"]
Expand Down Expand Up @@ -109,8 +109,8 @@ def test_grid_detection_plan_gives_warningerror_if_tip_not_found(
composite, _ = fake_devices
oav: OAV = composite.oav

oav.mxsc.pin_tip.tip_x.sim_put(-1)
oav.mxsc.pin_tip.tip_y.sim_put(-1)
oav.mxsc.pin_tip.tip_x.sim_put(-1) # type: ignore
oav.mxsc.pin_tip.tip_y.sim_put(-1) # type: ignore
oav.mxsc.pin_tip.validity_timeout.put(0.01)
params = OAVParameters("loopCentring", test_config_files["oav_config_json"])

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ def test_total_counts_calc_new_transmission_raises_warning_on_high_transmission(
composite: OptimizeAttenuationComposite = fake_create_devices()
composite.sample_shutter.set = MagicMock(return_value=get_good_status())
composite.xspress3mini.do_arm.set = MagicMock(return_value=get_good_status())
composite.xspress3mini.dt_corrected_latest_mca.sim_put([1, 1, 1, 1, 1, 1])
composite.xspress3mini.dt_corrected_latest_mca.sim_put([1, 1, 1, 1, 1, 1]) # type: ignore
RE(
total_counts_optimisation(
composite,
Expand Down Expand Up @@ -125,8 +125,8 @@ def test_deadtime_optimisation_calculates_deadtime_correctly(
):
composite: OptimizeAttenuationComposite = fake_create_devices()

composite.xspress3mini.channel_1.total_time.sim_put(100)
composite.xspress3mini.channel_1.reset_ticks.sim_put(101)
composite.xspress3mini.channel_1.total_time.sim_put(100) # type: ignore
composite.xspress3mini.channel_1.reset_ticks.sim_put(101) # type: ignore
is_deadtime_optimised.return_value = True

with patch(
Expand Down Expand Up @@ -207,14 +207,14 @@ def test_total_count_exception_raised_after_max_cycles_reached(RE: RunEngine):
composite.sample_shutter.set = MagicMock(return_value=get_good_status())
optimise_attenuation_plan.is_counts_within_target = MagicMock(return_value=False)
composite.xspress3mini.arm = MagicMock(return_value=get_good_status())
composite.xspress3mini.dt_corrected_latest_mca.sim_put([1, 1, 1, 1, 1, 1])
composite.xspress3mini.dt_corrected_latest_mca.sim_put([1, 1, 1, 1, 1, 1]) # type: ignore
with pytest.raises(AttenuationOptimisationFailedException):
RE(total_counts_optimisation(composite, 1, 0, 10, 0, 5, 2, 1, 0, 0))


def test_arm_devices_runs_correct_functions(RE: RunEngine):
composite: OptimizeAttenuationComposite = fake_create_devices()
composite.xspress3mini.detector_state.sim_put("Acquire")
composite.xspress3mini.detector_state.sim_put("Acquire") # type: ignore
composite.xspress3mini.arm = MagicMock(return_value=get_good_status())
RE(arm_devices(composite.xspress3mini))
composite.xspress3mini.arm.assert_called_once()
Expand Down Expand Up @@ -248,7 +248,7 @@ def test_total_count_calc_new_transmission_raises_error_on_low_ransmission(
RE: RunEngine,
):
composite: OptimizeAttenuationComposite = fake_create_devices()
composite.xspress3mini.dt_corrected_latest_mca.sim_put([1, 1, 1, 1, 1, 1])
composite.xspress3mini.dt_corrected_latest_mca.sim_put([1, 1, 1, 1, 1, 1]) # type: ignore
composite.sample_shutter.set = MagicMock(return_value=get_good_status())
composite.xspress3mini.do_arm.set = MagicMock(return_value=get_good_status())
with pytest.raises(AttenuationOptimisationFailedException):
Expand Down Expand Up @@ -276,7 +276,7 @@ def test_total_counts_gets_within_target(mock_arm_devices, RE: RunEngine):
def update_data(_):
nonlocal iteration
iteration += 1
composite.xspress3mini.dt_corrected_latest_mca.sim_put(
composite.xspress3mini.dt_corrected_latest_mca.sim_put( # type: ignore
([50, 50, 50, 50, 50]) * iteration
)
return get_good_status()
Expand Down
46 changes: 23 additions & 23 deletions tests/unit_tests/experiment_plans/test_pin_tip_centring.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@ def get_fake_pin_values_generator(x, y):
def test_given_the_pin_tip_is_already_in_view_when_get_tip_into_view_then_tip_returned_and_smargon_not_moved(
smargon: Smargon, oav: OAV, RE: RunEngine
):
smargon.x.user_readback.sim_put(0)
oav.mxsc.pin_tip.tip_x.sim_put(100)
oav.mxsc.pin_tip.tip_y.sim_put(200)
smargon.x.user_readback.sim_put(0) # type: ignore
oav.mxsc.pin_tip.tip_x.sim_put(100) # type: ignore
oav.mxsc.pin_tip.tip_y.sim_put(200) # type: ignore

oav.mxsc.pin_tip.trigger = MagicMock(side_effect=oav.mxsc.pin_tip.trigger)

Expand All @@ -44,14 +44,14 @@ def test_given_no_tip_found_but_will_be_found_when_get_tip_into_view_then_smargo
RE: RunEngine,
):
oav.mxsc.pin_tip.settle_time_s.put(0.01)
smargon.x.user_setpoint.sim_set_limits([-2, 2])
smargon.x.user_setpoint.sim_set_limits([-2, 2]) # type: ignore
oav.mxsc.pin_tip.triggered_tip.put(oav.mxsc.pin_tip.INVALID_POSITION)
oav.mxsc.pin_tip.validity_timeout.put(0.015)
smargon.x.user_readback.sim_put(0)
smargon.x.user_readback.sim_put(0) # type: ignore

def set_pin_tip_when_x_moved(*args, **kwargs):
oav.mxsc.pin_tip.tip_x.sim_put(100)
oav.mxsc.pin_tip.tip_y.sim_put(200)
oav.mxsc.pin_tip.tip_x.sim_put(100) # type: ignore
oav.mxsc.pin_tip.tip_y.sim_put(200) # type: ignore

smargon.x.subscribe(set_pin_tip_when_x_moved, run=False)

Expand All @@ -65,16 +65,16 @@ def test_given_tip_at_zero_but_will_be_found_when_get_tip_into_view_then_smargon
smargon: Smargon, oav: OAV, RE: RunEngine
):
oav.mxsc.pin_tip.settle_time_s.put(0.01)
smargon.x.user_setpoint.sim_set_limits([-2, 2])
oav.mxsc.pin_tip.tip_x.sim_put(0)
oav.mxsc.pin_tip.tip_y.sim_put(100)
smargon.x.user_setpoint.sim_set_limits([-2, 2]) # type: ignore
oav.mxsc.pin_tip.tip_x.sim_put(0) # type: ignore
oav.mxsc.pin_tip.tip_y.sim_put(100) # type: ignore
oav.mxsc.pin_tip.validity_timeout.put(0.15)

smargon.x.user_readback.sim_put(0)
smargon.x.user_readback.sim_put(0) # type: ignore

def set_pin_tip_when_x_moved(*args, **kwargs):
oav.mxsc.pin_tip.tip_y.sim_put(200)
oav.mxsc.pin_tip.tip_x.sim_put(100)
oav.mxsc.pin_tip.tip_y.sim_put(200) # type: ignore
oav.mxsc.pin_tip.tip_x.sim_put(100) # type: ignore

smargon.x.subscribe(set_pin_tip_when_x_moved, run=False)

Expand All @@ -93,9 +93,9 @@ def test_pin_tip_starting_near_negative_edge_doesnt_exceed_limit(
get_fake_pin_values_generator(0, 100),
]

smargon.x.user_setpoint.sim_set_limits([-2, 2])
smargon.x.user_setpoint.sim_put(-1.8)
smargon.x.user_readback.sim_put(-1.8)
smargon.x.user_setpoint.sim_set_limits([-2, 2]) # type: ignore
smargon.x.user_setpoint.sim_put(-1.8) # type: ignore
smargon.x.user_readback.sim_put(-1.8) # type: ignore

with pytest.raises(WarningException):
RE(move_pin_into_view(oav, smargon, max_steps=1))
Expand All @@ -114,9 +114,9 @@ def test_pin_tip_starting_near_positive_edge_doesnt_exceed_limit(
get_fake_pin_values_generator(-1, -1),
get_fake_pin_values_generator(-1, -1),
]
smargon.x.user_setpoint.sim_set_limits([-2, 2])
smargon.x.user_setpoint.sim_put(1.8)
smargon.x.user_readback.sim_put(1.8)
smargon.x.user_setpoint.sim_set_limits([-2, 2]) # type: ignore
smargon.x.user_setpoint.sim_put(1.8) # type: ignore
smargon.x.user_readback.sim_put(1.8) # type: ignore

with pytest.raises(WarningException):
RE(move_pin_into_view(oav, smargon, max_steps=1))
Expand All @@ -127,11 +127,11 @@ def test_pin_tip_starting_near_positive_edge_doesnt_exceed_limit(
def test_given_no_tip_found_ever_when_get_tip_into_view_then_smargon_moved_positive_and_exception_thrown(
smargon: Smargon, oav: OAV, RE: RunEngine
):
smargon.x.user_setpoint.sim_set_limits([-2, 2])
smargon.x.user_setpoint.sim_set_limits([-2, 2]) # type: ignore
oav.mxsc.pin_tip.triggered_tip.put(oav.mxsc.pin_tip.INVALID_POSITION)
oav.mxsc.pin_tip.validity_timeout.put(0.01)

smargon.x.user_readback.sim_put(0)
smargon.x.user_readback.sim_put(0) # type: ignore

with pytest.raises(WarningException):
RE(move_pin_into_view(oav, smargon))
Expand All @@ -142,7 +142,7 @@ def test_given_no_tip_found_ever_when_get_tip_into_view_then_smargon_moved_posit
def test_given_moving_out_of_range_when_move_with_warn_called_then_warning_exception(
RE: RunEngine, smargon: Smargon
):
smargon.x.high_limit_travel.sim_put(10)
smargon.x.high_limit_travel.sim_put(10) # type: ignore

with pytest.raises(WarningException):
RE(move_smargon_warn_on_out_of_range(smargon, (100, 0, 0)))
Expand Down Expand Up @@ -183,7 +183,7 @@ def test_when_pin_tip_centre_plan_called_then_expected_plans_called(
test_config_files,
RE,
):
smargon.omega.user_readback.sim_put(0)
smargon.omega.user_readback.sim_put(0) # type: ignore
mock_oav = MagicMock(spec=OAV)
mock_oav.parameters = OAVConfigParams(
test_config_files["zoom_params_file"], test_config_files["display_config"]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -507,7 +507,7 @@ def test_acceleration_offset_calculated_correctly(
undulator: Undulator,
flux: Flux,
):
smargon.omega.acceleration.sim_put(0.2)
smargon.omega.acceleration.sim_put(0.2) # type: ignore
setup_and_run_rotation_plan_for_tests(
RE,
test_rotation_params,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ def test_nexus_handler_gets_documents_in_mock_plan(
)
def test_nexus_handler_only_writes_once(
ispyb,
nexus_writer,
nexus_writer: MagicMock,
RE: RunEngine,
params: RotationInternalParameters,
test_start_doc,
Expand Down Expand Up @@ -197,7 +197,7 @@ def test_nexus_handler_triggers_write_file_when_told(
)
def test_zocalo_start_and_end_triggered_once(
ispyb,
zocalo,
zocalo: MagicMock,
RE: RunEngine,
params: RotationInternalParameters,
):
Expand Down

0 comments on commit cbd336c

Please sign in to comment.