0
0
mirror of https://github.com/bec-project/bec_widgets.git synced 2025-07-13 19:21:50 +02:00

test(bec_connector): BECConnector requires a QObject

This commit is contained in:
2025-04-09 19:27:22 +02:00
committed by wyzula-jan
parent d1712552ff
commit 23bdd95d8c
2 changed files with 11 additions and 6 deletions

View File

@ -93,7 +93,8 @@ class BECConnector:
object_name = object_name or kwargs.pop("objectName", None)
# Ensure the parent is always the first argument for QObject
parent = kwargs.pop("parent", None)
# This initializes the QObject or any qt related class
# This initializes the QObject or any qt related class BECConnector has to be used from this line down with QObject, otherwise hierarchy logic will not work
# TODO do a proper check if the class is a QObject -> issue #475
super().__init__(parent=parent, **kwargs)
# BEC related connections
self.bec_dispatcher = BECDispatcher(client=client)
@ -187,7 +188,7 @@ class BECConnector:
# Collect used names among siblings
used_names = {sib.objectName() for sib in siblings if sib is not self}
base_name = self.objectName()
base_name = self.object_name
if base_name not in used_names:
# Name is already unique among siblings
return
@ -380,7 +381,7 @@ class BECConnector:
def remove(self):
"""Cleanup the BECConnector"""
# If the widget is attached to a dock, remove it from the dock.
# TODO this should be handled by dock and dock are not by BECConnector
# TODO this should be handled by dock and dock are not by BECConnector -> issue created #473
if self._parent_dock is not None:
self._parent_dock.delete(self.object_name)
# If the widget is from Qt, trigger its close method.

View File

@ -2,6 +2,7 @@
import time
import pytest
from qtpy.QtCore import QObject
from qtpy.QtWidgets import QApplication
from bec_widgets.utils import BECConnector
@ -10,9 +11,12 @@ from bec_widgets.utils.error_popups import SafeSlot as Slot
from .client_mocks import mocked_client
class BECConnectorQObject(BECConnector, QObject): ...
@pytest.fixture
def bec_connector(mocked_client):
connector = BECConnector(client=mocked_client)
connector = BECConnectorQObject(client=mocked_client)
return connector
@ -20,11 +24,11 @@ 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"
assert bec_connector.config.widget_class == "BECConnectorQObject"
def test_bec_connector_init_with_gui_id(mocked_client):
bc = BECConnector(client=mocked_client, gui_id="test_gui_id")
bc = BECConnectorQObject(client=mocked_client, gui_id="test_gui_id")
assert bc.config.gui_id == "test_gui_id"
assert bc.gui_id == "test_gui_id"