test: remove collection and deprecation warnings from unit tests

This commit is contained in:
wyzula_j authored and Jan Wyzula committed 2026-10-17 18:31:49 +02:00
1 parent 4c4e5febd8
commit 16765e5d68
8 files changed
+34 -11

No files matched your search

+2
View File
@@ -17,6 +17,8 @@ class TestableQTimer(QTimer):
Patch it over ``qtpy.QtCore.QTimer`` before the widgets under test are imported.
"""
__test__ = False # helper class, not a test
_instances: list[tuple[QTimer, str, str]] = []
_current_test_name: str = ""
+1 -1
View File
@@ -256,7 +256,7 @@ class TestBECAtlasHTTPService:
def test_handle_response_login(self, http_service, qtbot):
"""Test that handling a login response correctly decodes the token and starts the auth timer."""
exp = time.time() + 300
token = jwt.encode({"email": "alice@example.org", "exp": exp}, "secret", algorithm="HS256")
token = jwt.encode({"email": "alice@example.org", "exp": exp}, "x" * 32, algorithm="HS256")
payload = ("{" f'"access_token": "{token}"' "}").encode()
reply = _FakeReply(
request_url="http://localhost:8000/user/login", status=200, payload=payload
@@ -13,7 +13,8 @@ from ophyd_devices.interfaces.device_config_templates.ophyd_templates import (
OPHYD_DEVICE_TEMPLATES,
EpicsMotorDeviceConfigTemplate,
)
from ophyd_devices.utils.static_device_test import StaticDeviceTest, TestResult
from ophyd_devices.utils.static_device_test import StaticDeviceTest
from ophyd_devices.utils.static_device_test import TestResult as DeviceTestResult
from qtpy import QtCore, QtGui, QtWidgets
from bec_widgets.tests.client_mocks import mocked_client
@@ -1028,7 +1029,7 @@ class TestOphydValidation:
runnable.tester, "run_with_list_output"
) as mock_run_with_list_output:
mock_run_with_list_output.return_value = [
TestResult(
DeviceTestResult(
name="test_device",
config_is_valid=ConfigStatus.VALID.value,
success=ConnectionStatus.CANNOT_CONNECT.value,
@@ -1445,7 +1446,7 @@ class TestOphydValidation:
name = next(iter(tester.config))
started.append(name)
release.wait(timeout=3)
return [TestResult(name=name, success=False, message="", config_is_valid=True)]
return [DeviceTestResult(name=name, success=False, message="", config_is_valid=True)]
configs = [
{"name": f"dev_{i}", "deviceClass": "ophyd.Signal", "enabled": True} for i in range(6)
+7 -1
View File
@@ -10,6 +10,8 @@ from bec_widgets.utils.error_popups import ErrorPopupUtility, ExampleWidget, Saf
class TestSafePropertyClass(QObject):
__test__ = False # helper class, not a test
def __init__(self, parent=None):
super().__init__(parent)
self._my_value = 10 # internal store
@@ -30,6 +32,7 @@ class TestSafePropertyClass(QObject):
class TestSafeSlotEmitter(QObject):
__test__ = False # helper class, not a test
test_signal = Signal()
@@ -38,6 +41,8 @@ class TestSafeSlotClass(QObject):
Test class to demonstrate the use of SafeSlot decorator.
"""
__test__ = False # helper class, not a test
def __init__(self, parent=None, signal_obj: TestSafeSlotEmitter | None = None):
super().__init__(parent)
assert signal_obj is not None, "Signal object must be provided"
@@ -239,7 +244,8 @@ def test_safe_connect_removes_stale_connection(qtbot):
# disconnects itself. A second disconnect attempt must then fail because
# the connection no longer exists.
emitter.str_signal.emit("after-death")
assert emitter.str_signal.disconnect(wrapper) is False
with pytest.warns(RuntimeWarning, match="Failed to disconnect"):
assert emitter.str_signal.disconnect(wrapper) is False
emitter.deleteLater()
+9 -4
View File
@@ -80,15 +80,20 @@ class GeneratedSignalOnlySchema(BaseModel):
class GeneratedScanArgumentSchema(BaseModel):
device: Device | str = Field(
default="", **ScanArgument(display_name="Device", description="Device source.").model_dump()
default="",
json_schema_extra=ScanArgument(
display_name="Device", description="Device source."
).model_dump(),
)
signal: Signal | str | None = Field(
default=None,
**ScanArgument(display_name="Signal", description="Signal source.").model_dump(),
json_schema_extra=ScanArgument(
display_name="Signal", description="Signal source."
).model_dump(),
)
low_limit: float | None = Field(
default=None,
**ScanArgument(
json_schema_extra=ScanArgument(
display_name="Low limit",
description="Optional lower bound.",
reference_units="device",
@@ -99,7 +104,7 @@ class GeneratedScanArgumentSchema(BaseModel):
)
exposure: float = Field(
default=0.1,
**ScanArgument(
json_schema_extra=ScanArgument(
display_name="Exposure", tooltip="Camera exposure.", units="s", precision=3, gt=0
).model_dump(),
)
+3
View File
@@ -620,6 +620,8 @@ def test_pending_request_queueing_and_start(heatmap_widget):
# Simulate an active worker processing a job so new requests are queued.
heatmap_widget._interpolation_worker = mock.MagicMock()
heatmap_widget._interpolation_worker.is_processing = True
# Wired like _ensure_interpolation_thread does, so the cleanup disconnect finds it.
heatmap_widget.interpolation_requested.connect(heatmap_widget._interpolation_worker.process)
with mock.patch.object(heatmap_widget, "_start_step_scan_interpolation") as start_mock:
heatmap_widget._request_step_scan_interpolation(
@@ -645,6 +647,7 @@ def test_finish_interpolation_thread_cleans_references(heatmap_widget):
thread_mock.isRunning.return_value = True
heatmap_widget._interpolation_worker = worker_mock
heatmap_widget._interpolation_thread = thread_mock
heatmap_widget.interpolation_requested.connect(worker_mock.process)
heatmap_widget._finish_interpolation_thread()
+6 -2
View File
@@ -389,7 +389,9 @@ def test_context_menu_contains_added_actions(
toolbar.show_bundles(["test_bundle"])
# Mock the QMenu.exec_ method to prevent the context menu from being displayed and block CI pipeline
monkeypatch.setattr(QMenu, "exec_", lambda self, pos=None: None)
event = QContextMenuEvent(QContextMenuEvent.Mouse, QPoint(10, 10))
event = QContextMenuEvent(
QContextMenuEvent.Reason.Mouse, QPoint(10, 10), toolbar.mapToGlobal(QPoint(10, 10))
)
toolbar.contextMenuEvent(event)
menus = toolbar.findChildren(QMenu)
@@ -419,7 +421,9 @@ def test_context_menu_toggle_action_visibility(toolbar_fixture, material_icon_ac
# Manually trigger the context menu event
monkeypatch.setattr(QMenu, "exec_", lambda self, pos=None: None)
event = QContextMenuEvent(QContextMenuEvent.Mouse, QPoint(10, 10))
event = QContextMenuEvent(
QContextMenuEvent.Reason.Mouse, QPoint(10, 10), toolbar.mapToGlobal(QPoint(10, 10))
)
toolbar.contextMenuEvent(event)
# Grab the menu that was created
+2
View File
@@ -12,6 +12,8 @@ from bec_widgets.utils.property_editor import PropertyEditor
class TestWidget(QWidget):
"""Test widget with various property types for testing the property editor."""
__test__ = False # helper class, not a test
def __init__(self, parent=None):
super().__init__(parent)
self.setObjectName("TestWidget")