mirror of
https://github.com/bec-project/bec_widgets.git
synced 2025-07-14 11:41:49 +02:00
test(tests/test_bec_connector): test_bec_connector.py added
This commit is contained in:
@ -59,6 +59,7 @@ class BECConnector:
|
|||||||
gui_id(str): GUI ID
|
gui_id(str): GUI ID
|
||||||
"""
|
"""
|
||||||
self.config.gui_id = gui_id
|
self.config.gui_id = gui_id
|
||||||
|
self.gui_id = gui_id
|
||||||
|
|
||||||
def get_obj_by_id(self, obj_id: str):
|
def get_obj_by_id(self, obj_id: str):
|
||||||
if obj_id == self.gui_id:
|
if obj_id == self.gui_id:
|
||||||
|
@ -49,7 +49,17 @@ def get_mocked_device(device_name: str):
|
|||||||
@pytest.fixture(scope="function")
|
@pytest.fixture(scope="function")
|
||||||
def mocked_client():
|
def mocked_client():
|
||||||
# Create a dictionary of mocked devices
|
# Create a dictionary of mocked devices
|
||||||
device_names = ["samx", "gauss_bpm", "gauss_adc1", "gauss_adc2", "gauss_adc3", "bpm4i"]
|
device_names = [
|
||||||
|
"samx",
|
||||||
|
"samy",
|
||||||
|
"gauss_bpm",
|
||||||
|
"gauss_adc1",
|
||||||
|
"gauss_adc2",
|
||||||
|
"gauss_adc3",
|
||||||
|
"bpm4i",
|
||||||
|
"bpm3a",
|
||||||
|
"bpm3i",
|
||||||
|
]
|
||||||
mocked_devices = {name: get_mocked_device(name) for name in device_names}
|
mocked_devices = {name: get_mocked_device(name) for name in device_names}
|
||||||
|
|
||||||
# Create a MagicMock object
|
# Create a MagicMock object
|
||||||
|
55
tests/test_bec_connector.py
Normal file
55
tests/test_bec_connector.py
Normal file
@ -0,0 +1,55 @@
|
|||||||
|
import pytest
|
||||||
|
|
||||||
|
from .client_mocks import mocked_client
|
||||||
|
from bec_widgets.utils import BECConnector, ConnectionConfig
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.fixture
|
||||||
|
def bec_connector(mocked_client):
|
||||||
|
connector = BECConnector(client=mocked_client)
|
||||||
|
return connector
|
||||||
|
|
||||||
|
|
||||||
|
def test_bec_connector_init(bec_connector):
|
||||||
|
assert bec_connector is not None
|
||||||
|
assert bec_connector.client is not None
|
||||||
|
assert isinstance(bec_connector, BECConnector)
|
||||||
|
assert bec_connector.config.widget_class == "BECConnector"
|
||||||
|
|
||||||
|
|
||||||
|
def test_bec_connector_init_with_gui_id(mocked_client):
|
||||||
|
bc = BECConnector(client=mocked_client, gui_id="test_gui_id")
|
||||||
|
assert bc.config.gui_id == "test_gui_id"
|
||||||
|
assert bc.gui_id == "test_gui_id"
|
||||||
|
|
||||||
|
|
||||||
|
def test_bec_connector_set_gui_id(bec_connector):
|
||||||
|
bec_connector.set_gui_id("test_gui_id")
|
||||||
|
assert bec_connector.config.gui_id == "test_gui_id"
|
||||||
|
|
||||||
|
|
||||||
|
def test_bec_connector_change_config(bec_connector):
|
||||||
|
bec_connector.on_config_update({"gui_id": "test_gui_id"})
|
||||||
|
assert bec_connector.config.gui_id == "test_gui_id"
|
||||||
|
|
||||||
|
|
||||||
|
def test_bec_connector_get_obj_by_id(bec_connector):
|
||||||
|
bec_connector.set_gui_id("test_gui_id")
|
||||||
|
assert bec_connector.get_obj_by_id("test_gui_id") == bec_connector
|
||||||
|
assert bec_connector.get_obj_by_id("test_gui_id_2") is None
|
||||||
|
|
||||||
|
|
||||||
|
def test_bec_connector_update_client(bec_connector, mocked_client):
|
||||||
|
client_new = mocked_client
|
||||||
|
bec_connector.update_client(client_new)
|
||||||
|
assert bec_connector.client == client_new
|
||||||
|
assert bec_connector.dev is not None
|
||||||
|
assert bec_connector.scans is not None
|
||||||
|
assert bec_connector.queue is not None
|
||||||
|
assert bec_connector.scan_storage is not None
|
||||||
|
assert bec_connector.dap is not None
|
||||||
|
|
||||||
|
|
||||||
|
def test_bec_connector_get_config(bec_connector):
|
||||||
|
assert bec_connector.get_config(dict_output=False) == bec_connector.config
|
||||||
|
assert bec_connector.get_config() == bec_connector.config.model_dump()
|
Reference in New Issue
Block a user