Skip to content

Commit

Permalink
Speed up tests (#1000)
Browse files Browse the repository at this point in the history
* Speed up apple2 undulator tests

* Reduce timeout on test
  • Loading branch information
DominicOram authored Feb 3, 2025
1 parent 8061351 commit b628f8c
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 8 deletions.
File renamed without changes.
21 changes: 14 additions & 7 deletions tests/devices/unit_tests/test_apple2_undulator.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import asyncio
from collections import defaultdict
from unittest.mock import ANY
from unittest.mock import ANY, AsyncMock

import bluesky.plan_stubs as bps
import pytest
Expand Down Expand Up @@ -117,12 +117,14 @@ async def test_gap_cal_timout(
assert await mock_id_gap.get_timeout() == pytest.approx(expected_timeout, rel=0.1)


async def test_gap_time_out_error(mock_id_gap: UndulatorGap, RE: RunEngine):
async def test_given_gate_never_closes_then_setting_gaps_times_out(
mock_id_gap: UndulatorGap, RE: RunEngine
):
callback_on_mock_put(
mock_id_gap.user_setpoint,
lambda *_, **__: set_mock_value(mock_id_gap.gate, UndulatorGateStatus.OPEN),
)
set_mock_value(mock_id_gap.velocity, 1000)
mock_id_gap._cal_timeout = AsyncMock(return_value=0.01)
with pytest.raises(asyncio.TimeoutError):
await mock_id_gap.set("2")

Expand Down Expand Up @@ -162,14 +164,17 @@ def capture_emitted(name, doc):
assert docs["event"][i]["data"]["mock_id_gap-user_readback"] == i


async def test_phase_time_out_error(mock_phaseAxes: UndulatorPhaseAxes, RE: RunEngine):
async def test_given_gate_never_closes_then_setting_phases_times_out(
mock_phaseAxes: UndulatorPhaseAxes, RE: RunEngine
):
setValue = Apple2PhasesVal("3", "2", "5", "7")

callback_on_mock_put(
mock_phaseAxes.top_outer.user_setpoint,
lambda *_, **__: set_mock_value(mock_phaseAxes.gate, UndulatorGateStatus.OPEN),
)
set_mock_value(mock_phaseAxes.top_inner.velocity, 1000)
mock_phaseAxes._cal_timeout = AsyncMock(return_value=0.01)

with pytest.raises(asyncio.TimeoutError):
await mock_phaseAxes.set(setValue)

Expand Down Expand Up @@ -285,12 +290,14 @@ def set_complete_move():
}


async def test_jaw_phase_time_out_error(mock_jaw_phase: UndulatorJawPhase):
async def test_given_gate_never_closes_then_setting_jaw_phases_times_out(
mock_jaw_phase: UndulatorJawPhase,
):
callback_on_mock_put(
mock_jaw_phase.jaw_phase.user_setpoint,
lambda *_, **__: set_mock_value(mock_jaw_phase.gate, UndulatorGateStatus.OPEN),
)
set_mock_value(mock_jaw_phase.jaw_phase.velocity, 1000)
mock_jaw_phase._cal_timeout = AsyncMock(return_value=0.01)
with pytest.raises(asyncio.TimeoutError):
await mock_jaw_phase.set(2)

Expand Down
2 changes: 1 addition & 1 deletion tests/devices/unit_tests/test_focusing_mirror.py
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ def plan():
RE(plan())


@patch("dodal.devices.focusing_mirror.DEFAULT_SETTLE_TIME_S", 3)
@patch("dodal.devices.focusing_mirror.DEFAULT_SETTLE_TIME_S", 0.1)
def test_mirror_set_voltage_sets_and_waits_settle_timeout_expires(
RE: RunEngine,
mirror_voltage_with_set_timing_out: SingleMirrorVoltage,
Expand Down

0 comments on commit b628f8c

Please sign in to comment.