Files
wakonig_k c57819f313
CI for xtreme_bec / test (pull_request) Successful in 1m15s
CI for xtreme_bec / test (push) Successful in 1m4s
feat: consolidate devices and improve undulator handling
2026-10-06 13:28:33 +02:00

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)