72 lines
2.2 KiB
Python
72 lines
2.2 KiB
Python
import pytest
|
|
from bec_server.device_server.tests.utils import DMMock
|
|
from ophyd_devices.interfaces.base_classes.psi_device_base import DeviceStoppedError
|
|
|
|
from aare_bec_proto.devices import RobotState, SimAerotechStage, SimGoniometer, SimSampleChanger
|
|
|
|
|
|
@pytest.fixture
|
|
def robot():
|
|
dev = SimSampleChanger(name="robot", mount_time=0.05, device_manager=DMMock())
|
|
dev.on_connected()
|
|
yield dev
|
|
dev.destroy()
|
|
|
|
|
|
@pytest.mark.parametrize("cls", [SimAerotechStage, SimGoniometer])
|
|
def test_stage_reads_all_axes(cls):
|
|
stage = cls(name="stage")
|
|
readings = stage.read()
|
|
for axis in cls.component_names:
|
|
assert f"stage_{axis}" in readings
|
|
stage.destroy()
|
|
|
|
|
|
def test_omega_is_unbounded():
|
|
stage = SimAerotechStage(name="aerotech")
|
|
stage.omega.delay = 0
|
|
stage.omega.move(720).wait(timeout=1)
|
|
assert stage.omega.position == pytest.approx(720, abs=stage.omega.tolerance.get())
|
|
stage.destroy()
|
|
|
|
|
|
def test_robot_mount_and_unmount(robot):
|
|
assert robot.mount_time.get() == 0.05
|
|
robot.mount(puck=2, position=7).wait(timeout=1)
|
|
assert robot.read()["robot_sample_mounted"]["value"] == 1
|
|
assert robot.mounted_puck.get() == 2
|
|
assert robot.mounted_position.get() == 7
|
|
assert robot.state.get() == RobotState.IDLE
|
|
|
|
robot.unmount().wait(timeout=1)
|
|
assert robot.sample_mounted.get() == 0
|
|
assert robot.mounted_puck.get() == 0
|
|
|
|
|
|
def test_robot_is_busy_while_mounting(robot):
|
|
status = robot.mount(puck=1, position=1)
|
|
assert robot.state.get() == RobotState.BUSY
|
|
with pytest.raises(RuntimeError, match="not idle"):
|
|
robot.mount(puck=1, position=2)
|
|
status.wait(timeout=1)
|
|
assert robot.mounted_position.get() == 1
|
|
|
|
|
|
def test_robot_refuses_with_door_open(robot):
|
|
robot.door_closed.put(0)
|
|
with pytest.raises(RuntimeError, match="door"):
|
|
robot.mount(puck=1, position=1)
|
|
assert robot.state.get() == RobotState.ERROR
|
|
robot.reset()
|
|
assert robot.state.get() == RobotState.IDLE
|
|
|
|
|
|
def test_robot_stop_aborts_mount(robot):
|
|
robot.mount_time.put(5)
|
|
status = robot.mount(puck=1, position=1)
|
|
robot.stop()
|
|
with pytest.raises(DeviceStoppedError):
|
|
status.wait(timeout=1)
|
|
assert robot.sample_mounted.get() == 0
|
|
assert robot.state.get() == RobotState.IDLE
|