mirror of
https://github.com/bec-project/bec_widgets.git
synced 2026-06-05 12:58:40 +02:00
192 lines
5.8 KiB
Python
192 lines
5.8 KiB
Python
from bec_lib import messages
|
|
|
|
from bec_widgets.utils.toolbars.toolbar import ModularToolBar
|
|
from bec_widgets.widgets.services.beamline_states.beamline_state_pill import (
|
|
AddBeamlineStateDialog,
|
|
BeamlineStateManager,
|
|
BeamlineStatePill,
|
|
)
|
|
|
|
from .client_mocks import mocked_client
|
|
|
|
|
|
def test_beamline_state_pill_updates_from_message(qtbot, mocked_client):
|
|
widget = BeamlineStatePill(state_name="shutter_open", title="Shutter", client=mocked_client)
|
|
qtbot.addWidget(widget)
|
|
|
|
widget.update_state(
|
|
{"name": "shutter_open", "status": "valid", "label": "Shutter is open."}, {}
|
|
)
|
|
|
|
assert widget.state_name == "shutter_open"
|
|
assert widget._name_label.text() == "Shutter"
|
|
assert widget._status_label.text() == "VALID"
|
|
assert widget._detail_label.text() == "Shutter is open."
|
|
assert not widget._icon_label.pixmap().isNull()
|
|
assert widget._flash_active
|
|
assert widget.toolTip() == "Shutter is open."
|
|
|
|
|
|
def test_beamline_state_pill_ignores_other_states(qtbot, mocked_client):
|
|
widget = BeamlineStatePill(state_name="shutter_open", client=mocked_client)
|
|
qtbot.addWidget(widget)
|
|
|
|
widget.update_state(
|
|
{"name": "other_state", "status": "invalid", "label": "Should be ignored."}, {}
|
|
)
|
|
|
|
assert widget._status_label.text() == "UNKNOWN"
|
|
assert widget.toolTip() == "No state information available."
|
|
|
|
|
|
def test_beamline_state_manager_adds_and_removes_pills(qtbot, mocked_client):
|
|
widget = BeamlineStateManager(client=mocked_client)
|
|
qtbot.addWidget(widget)
|
|
|
|
widget.update_available_states(
|
|
{
|
|
"states": [
|
|
messages.BeamlineStateConfig(
|
|
name="shutter_open", title="Shutter", state_type="ShutterState", parameters={}
|
|
),
|
|
{
|
|
"name": "limits",
|
|
"title": "Limits",
|
|
"state_type": "DeviceWithinLimitsState",
|
|
"parameters": {},
|
|
},
|
|
]
|
|
},
|
|
{},
|
|
)
|
|
|
|
assert sorted(widget._state_pills) == ["limits", "shutter_open"]
|
|
assert widget._state_pills["shutter_open"]._name_label.text() == "Shutter"
|
|
assert not widget._empty_label.isVisible()
|
|
|
|
widget.update_available_states(
|
|
{
|
|
"states": [
|
|
{
|
|
"name": "limits",
|
|
"title": "Limits",
|
|
"state_type": "DeviceWithinLimitsState",
|
|
"parameters": {},
|
|
}
|
|
]
|
|
},
|
|
{},
|
|
)
|
|
|
|
assert sorted(widget._state_pills) == ["limits"]
|
|
|
|
|
|
def test_beamline_state_manager_filters_states(qtbot, mocked_client):
|
|
widget = BeamlineStateManager(client=mocked_client)
|
|
qtbot.addWidget(widget)
|
|
|
|
widget.update_available_states(
|
|
{
|
|
"states": [
|
|
{
|
|
"name": "shutter_open",
|
|
"title": "Shutter",
|
|
"state_type": "ShutterState",
|
|
"parameters": {"device": "samy"},
|
|
},
|
|
{
|
|
"name": "limits",
|
|
"title": "Limits",
|
|
"state_type": "DeviceWithinLimitsState",
|
|
"parameters": {"device": "samx"},
|
|
},
|
|
]
|
|
},
|
|
{},
|
|
)
|
|
|
|
assert isinstance(widget._toolbar, ModularToolBar)
|
|
|
|
widget._selected_state_names = {"limits"}
|
|
widget._apply_filters()
|
|
|
|
assert not widget._hidden_summary.isHidden()
|
|
assert "1 state is hidden" in widget._hidden_summary.text()
|
|
assert widget._state_pills["limits"].parent() is widget._content
|
|
assert widget._state_pills["shutter_open"].parent() is widget._hidden_content
|
|
|
|
widget._toggle_hidden_states(True)
|
|
|
|
assert not widget._hidden_content.isHidden()
|
|
|
|
|
|
def test_beamline_state_manager_filters_devices(qtbot, mocked_client):
|
|
widget = BeamlineStateManager(client=mocked_client)
|
|
qtbot.addWidget(widget)
|
|
|
|
widget.update_available_states(
|
|
{
|
|
"states": [
|
|
{
|
|
"name": "samx_limits",
|
|
"title": "samx",
|
|
"state_type": "DeviceWithinLimitsState",
|
|
"parameters": {"device": "samx"},
|
|
},
|
|
{
|
|
"name": "samy_limits",
|
|
"title": "samy",
|
|
"state_type": "DeviceWithinLimitsState",
|
|
"parameters": {"device": "samy"},
|
|
},
|
|
]
|
|
},
|
|
{},
|
|
)
|
|
|
|
widget._device_filter_text = "samx"
|
|
widget._apply_filters()
|
|
|
|
assert not widget._hidden_summary.isHidden()
|
|
assert "1 state is hidden" in widget._hidden_summary.text()
|
|
assert widget._available_devices() == ["samx", "samy"]
|
|
|
|
|
|
def test_add_beamline_state_dialog_uses_device_signal_widgets_and_normalizes_name(
|
|
qtbot, mocked_client
|
|
):
|
|
dialog = AddBeamlineStateDialog(client=mocked_client)
|
|
qtbot.addWidget(dialog)
|
|
|
|
dialog._type_combo.setCurrentIndex(1)
|
|
dialog._name.setText("samx-limits")
|
|
dialog._title.setText("samx-limits-15")
|
|
dialog._device.set_device("samx")
|
|
dialog._signal.set_signal("samx")
|
|
dialog._high_limit.setValue(15.0)
|
|
|
|
config = dialog.config()
|
|
|
|
assert config.name == "samx_limits"
|
|
assert config.title == "samx-limits-15"
|
|
assert config.device == "samx"
|
|
assert config.signal == "samx"
|
|
assert config.low_limit == 0.0
|
|
assert config.high_limit == 15.0
|
|
|
|
|
|
def test_add_beamline_state_dialog_generates_name_only_after_valid_device_selection(
|
|
qtbot, mocked_client
|
|
):
|
|
dialog = AddBeamlineStateDialog(client=mocked_client)
|
|
qtbot.addWidget(dialog)
|
|
|
|
dialog._type_combo.setCurrentIndex(1)
|
|
dialog._device.setCurrentText("s")
|
|
|
|
assert dialog._name.text() == ""
|
|
|
|
dialog._device.set_device("samx")
|
|
|
|
assert dialog._name.text() == "samx_limits"
|