fix(entry_validator): name validate_signal parameters device and signal

This commit is contained in:
wyzula_j authored and Jan Wyzula committed 2026-11-17 18:41:56 +01:00
1 parent 4288bc661b
commit 08ab59440d
2 files changed
+43 -17

No files matched your search

+19 -17
View File
@@ -2,45 +2,47 @@ class EntryValidator:
def __init__(self, devices):
self.devices = devices
def validate_signal(self, name: str, entry: str = None) -> str:
def validate_signal(self, device: str, signal: str | None = None) -> str:
"""
Validate a signal entry for a given device. If the entry is not provided, the first signal entry will be used from the device hints.
Validate a signal for a given device. If the signal is not provided, the first signal will be used from the device hints.
Args:
name(str): Device name
entry(str): Signal entry
device(str): Device name
signal(str): Signal name
Returns:
str: Signal entry
str: Signal name
"""
if name not in self.devices:
raise ValueError(f"Device '{name}' not found in current BEC session")
if device not in self.devices:
raise ValueError(f"Device '{device}' not found in current BEC session")
device = self.devices[name]
device_obj = self.devices[device]
# Build list of available signal entries from device._info['signals']
signals_dict = getattr(device, "_info", {}).get("signals", {})
signals_dict = getattr(device_obj, "_info", {}).get("signals", {})
available_entries = [
sig.get("obj_name") for sig in signals_dict.values() if sig.get("obj_name")
]
# If no signals are found, means device is a signal, use the device name as the entry
if not available_entries:
available_entries = [name]
available_entries = [device]
# edge case for if name is passed instead of full_name, should not happen
if entry in signals_dict:
entry = signals_dict[entry].get("obj_name", entry)
if signal in signals_dict:
signal = signals_dict[signal].get("obj_name", signal)
if entry is None or entry == "":
entry = next(iter(device._hints), name) if hasattr(device, "_hints") else name
if entry not in available_entries:
if signal is None or signal == "":
signal = (
next(iter(device_obj._hints), device) if hasattr(device_obj, "_hints") else device
)
if signal not in available_entries:
raise ValueError(
f"Entry '{entry}' not found in device '{name}' signals. "
f"Entry '{signal}' not found in device '{device}' signals. "
f"Available signals: '{available_entries}'"
)
return entry
return signal
def validate_monitor(self, monitor: str) -> str:
"""
+24
View File
@@ -477,6 +477,30 @@ def test_export_data_history_curve(curve_tree_fixture, scan_history_factory):
assert exported["label"] == "bpm4i-bpm4i-scan-2"
def test_export_data_validates_a_typed_signal(curve_tree_fixture):
"""
A signal typed into the row that the device does not have is reported as such.
"""
curve_tree, _ = curve_tree_fixture
device_row = curve_tree.add_new_curve(device="bpm4i", signal="bpm4i")
device_row.entry_edit.setEditText("not_a_signal")
with pytest.raises(ValueError, match="'not_a_signal' not found in device 'bpm4i'"):
device_row.export_data()
def test_entry_validator_takes_device_and_signal_keywords(curve_tree_fixture):
"""
The validator names its parameters like its callers do: device and signal.
"""
curve_tree, _ = curve_tree_fixture
validator = curve_tree.add_new_curve(device="bpm4i", signal="bpm4i").entry_validator
assert validator.validate_signal(device="bpm4i", signal="bpm4i") == "bpm4i"
assert validator.validate_signal(device="bpm4i") == "bpm4i"
assert validator.validate_signal("bpm4i", "bpm4i") == "bpm4i"
##################################################
# Staging of edits (issue #1314)
##################################################