mirror of
https://github.com/bec-project/bec_widgets.git
synced 2025-07-14 03:31:50 +02:00
fix: monitor_config_validator.py changed to check .describe() instead of signals
This commit is contained in:
@ -22,6 +22,7 @@ class FakeDevice:
|
||||
self.name = name
|
||||
self.enabled = enabled
|
||||
self.signals = {self.name: {"value": 1.0}}
|
||||
self.description = {self.name: {"source": self.name}}
|
||||
|
||||
def __contains__(self, item):
|
||||
return item == self.name
|
||||
@ -38,6 +39,14 @@ class FakeDevice:
|
||||
"""
|
||||
self.signals[self.name]["value"] = fake_value
|
||||
|
||||
def describe(self) -> dict:
|
||||
"""
|
||||
Get the description of the device
|
||||
Returns:
|
||||
dict: Description of the device
|
||||
"""
|
||||
return self.description
|
||||
|
||||
|
||||
def get_mocked_device(device_name: str):
|
||||
"""
|
||||
@ -54,11 +63,6 @@ def mocked_client():
|
||||
device_names = ["samx", "gauss_bpm", "gauss_adc1", "gauss_adc2", "gauss_adc3", "bpm4i"]
|
||||
mocked_devices = {name: get_mocked_device(name) for name in device_names}
|
||||
|
||||
# Adding a device with empty signals for validation tests
|
||||
no_signal_device = FakeDevice(name="no_signal_device")
|
||||
del no_signal_device.signals # Simulate a device with no signals
|
||||
mocked_devices["no_signal_device"] = no_signal_device
|
||||
|
||||
# Create a MagicMock object
|
||||
client = MagicMock()
|
||||
|
||||
|
@ -34,16 +34,6 @@ def test_signal_validation_name_not_in_bec(setup_devices):
|
||||
assert 'Device "non_existent_device" not found in current BEC session' in str(excinfo.value)
|
||||
|
||||
|
||||
def test_signal_validation_device_has_no_signals(setup_devices):
|
||||
with pytest.raises(ValidationError) as excinfo:
|
||||
Signal(name="no_signal_device")
|
||||
|
||||
errors = excinfo.value.errors()
|
||||
assert len(errors) == 1
|
||||
assert errors[0]["type"] == "no_device_signals"
|
||||
assert 'Device "no_signal_device" does not have "signals" defined' in errors[0]["msg"]
|
||||
|
||||
|
||||
def test_signal_validation_entry_not_in_device(setup_devices):
|
||||
with pytest.raises(ValidationError) as excinfo:
|
||||
Signal(name="samx", entry="non_existent_entry")
|
||||
@ -103,3 +93,17 @@ def test_plot_config_history_source_type(setup_devices):
|
||||
assert len(plot_config.sources) == 1
|
||||
assert plot_config.sources[0].type == "history"
|
||||
assert plot_config.sources[0].scanID == "valid_scan_id"
|
||||
|
||||
|
||||
def test_plot_config_redis_source_type(setup_devices):
|
||||
history_source = {
|
||||
"type": "redis",
|
||||
"endpoint": "valid_endpoint",
|
||||
"update": "append",
|
||||
"signals": {"x": [{"name": "samx"}], "y": [{"name": "samx"}]},
|
||||
}
|
||||
|
||||
plot_config = PlotConfig(sources=[history_source])
|
||||
|
||||
assert len(plot_config.sources) == 1
|
||||
assert plot_config.sources[0].type == "redis"
|
||||
|
Reference in New Issue
Block a user