58 lines
1.6 KiB
Python
58 lines
1.6 KiB
Python
from unittest.mock import patch
|
|
|
|
import pytest
|
|
from ophyd.sim import make_fake_device
|
|
from ophyd.status import Status
|
|
|
|
from xtreme_bec.devices.cff import Cff
|
|
|
|
|
|
@pytest.fixture
|
|
def cff():
|
|
return make_fake_device(Cff)("X07MA-", name="cff")
|
|
|
|
|
|
def test_set_confirms_energy_without_waiting_for_cff_readback(cff):
|
|
cff.cff.sim_put(1.8)
|
|
|
|
def confirm(value):
|
|
cff_put.assert_called_once_with(2.25, wait=True)
|
|
assert cff.cff.get() == 1.8
|
|
assert value == 1
|
|
status = Status()
|
|
status.set_finished()
|
|
return status
|
|
|
|
with (
|
|
patch.object(cff.cff, "put") as cff_put,
|
|
patch.object(cff.confirm_energy, "set", side_effect=confirm) as confirm_set,
|
|
):
|
|
status = cff.set(2.25)
|
|
|
|
status.wait(timeout=1)
|
|
assert status.success
|
|
confirm_set.assert_called_once_with(1)
|
|
|
|
|
|
def test_failed_cff_write_does_not_confirm_energy(cff):
|
|
with (
|
|
patch.object(cff.cff, "put", side_effect=RuntimeError("CFF write failed")),
|
|
patch.object(cff.confirm_energy, "set") as confirm_set,
|
|
):
|
|
with pytest.raises(RuntimeError, match="CFF write failed"):
|
|
cff.set(2.25)
|
|
|
|
confirm_set.assert_not_called()
|
|
|
|
|
|
def test_set_returns_confirmation_status(cff):
|
|
confirmation = Status()
|
|
with patch.object(cff.confirm_energy, "set", return_value=confirmation):
|
|
status = cff.set(2.25)
|
|
|
|
assert status is confirmation
|
|
assert not status.done
|
|
confirmation.set_exception(RuntimeError("Energy confirmation failed"))
|
|
with pytest.raises(RuntimeError, match="Energy confirmation failed"):
|
|
status.wait(timeout=1)
|