mirror of
https://github.com/bec-project/bec_widgets.git
synced 2025-07-13 19:21:50 +02:00
test: unit tests moved to separate folder; scope of autouse bec_dispatcher fixture reduced only for unit tests; ci adjusted
This commit is contained in:
@ -88,6 +88,7 @@ tests:
|
||||
- apt-get install -y libgl1-mesa-glx libegl1-mesa x11-utils libxkbcommon-x11-0 libdbus-1-3
|
||||
- pip install -e ./bec/bec_lib[dev]
|
||||
- pip install -e .[dev]
|
||||
- cd ./test/unit_tests/
|
||||
- coverage run --source=./bec_widgets -m pytest -v --junitxml=report.xml --random-order --full-trace ./tests
|
||||
- coverage report
|
||||
- coverage xml
|
||||
@ -151,8 +152,7 @@ end-2-end-conda:
|
||||
- cd ../
|
||||
- pip install -e .[dev]
|
||||
- cd ./tests/end-2-end
|
||||
- redis-server --daemonize yes
|
||||
- pytest --start-servers
|
||||
- pytest --start-servers --flush-redis --random-order
|
||||
|
||||
artifacts:
|
||||
when: on_failure
|
||||
|
@ -82,8 +82,9 @@ class BECDispatcher:
|
||||
return
|
||||
|
||||
self._slots = collections.defaultdict(set)
|
||||
self.client = client
|
||||
|
||||
if client is None:
|
||||
if self.client is None:
|
||||
self.client = BECClient(connector_cls=QtRedisConnector, forced=True)
|
||||
else:
|
||||
if self.client.started:
|
||||
|
@ -1,36 +0,0 @@
|
||||
import threading
|
||||
|
||||
import pytest
|
||||
from bec_lib.bec_service import BECService
|
||||
|
||||
from bec_widgets.utils import bec_dispatcher as bec_dispatcher_module
|
||||
|
||||
|
||||
@pytest.fixture()
|
||||
def threads_check():
|
||||
current_threads = set(
|
||||
th
|
||||
for th in threading.enumerate()
|
||||
if "loguru" not in th.name and th is not threading.main_thread()
|
||||
)
|
||||
yield
|
||||
threads_after = set(
|
||||
th
|
||||
for th in threading.enumerate()
|
||||
if "loguru" not in th.name and th is not threading.main_thread()
|
||||
)
|
||||
additional_threads = threads_after - current_threads
|
||||
assert (
|
||||
len(additional_threads) == 0
|
||||
), f"Test creates {len(additional_threads)} threads that are not cleaned: {additional_threads}"
|
||||
|
||||
|
||||
@pytest.fixture(autouse=True)
|
||||
def bec_dispatcher(threads_check):
|
||||
bec_dispatcher = bec_dispatcher_module.BECDispatcher()
|
||||
yield bec_dispatcher
|
||||
bec_dispatcher.disconnect_all()
|
||||
# clean BEC client
|
||||
bec_dispatcher.client.shutdown()
|
||||
# reinitialize singleton for next test
|
||||
bec_dispatcher_module.BECDispatcher.reset_singleton()
|
@ -7,14 +7,17 @@ from bec_widgets.widgets.plots.waveform import Signal, SignalData
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def rpc_server(qtbot, bec_client_lib):
|
||||
def rpc_server(qtbot, bec_client_lib, threads_check):
|
||||
dispatcher = BECDispatcher(client=bec_client_lib) # Has to init singleton with fixture client
|
||||
server = BECWidgetsCLIServer(gui_id="id_test")
|
||||
qtbot.addWidget(server.fig)
|
||||
qtbot.waitExposed(server.fig)
|
||||
qtbot.wait(1000) # 1s long to wait until gui is ready
|
||||
yield server
|
||||
dispatcher.disconnect_all()
|
||||
server.client.shutdown()
|
||||
server.shutdown()
|
||||
dispatcher.reset_singleton()
|
||||
|
||||
|
||||
def test_rpc_waveform1d_custom_curve(rpc_server, qtbot):
|
||||
@ -31,7 +34,7 @@ def test_rpc_waveform1d_custom_curve(rpc_server, qtbot):
|
||||
assert len(fig_server.widgets["widget_1"].curves) == 1
|
||||
|
||||
|
||||
def test_rpc_plotting_shortcuts(rpc_server, qtbot):
|
||||
def test_rpc_plotting_shortcuts_operation(rpc_server, qtbot):
|
||||
fig = BECFigure(rpc_server.gui_id)
|
||||
fig_server = rpc_server.fig
|
||||
|
||||
@ -48,13 +51,12 @@ def test_rpc_plotting_shortcuts(rpc_server, qtbot):
|
||||
assert motor_map.__class__.__name__ == "BECMotorMap"
|
||||
assert motor_map.__class__ == BECMotorMap
|
||||
|
||||
# # check if the correct devices are set
|
||||
# plt_curve_config = plt.curves[0].get_config()
|
||||
# assert plt_curve_config["signals"] == {
|
||||
# "source": "scan_segment",
|
||||
# "x": {"name": "samx", "entry": "samx", "unit": None, "modifier": None, "limits": None},
|
||||
# "y": {"name": "bpm4i", "entry": "bpm4i", "unit": None, "modifier": None, "limits": None},
|
||||
# "z": None,
|
||||
# }
|
||||
#
|
||||
# im_config = im.get_config()
|
||||
# check if the correct devices are set
|
||||
assert plt.config_dict["curves"]["bpm4i-bpm4i"]["signals"] == {
|
||||
"source": "scan_segment",
|
||||
"x": {"name": "samx", "entry": "samx", "unit": None, "modifier": None, "limits": None},
|
||||
"y": {"name": "bpm4i", "entry": "bpm4i", "unit": None, "modifier": None, "limits": None},
|
||||
"z": None,
|
||||
}
|
||||
|
||||
assert im.config_dict["images"]["eiger"]["monitor"] == "eiger"
|
||||
|
14
tests/unit_tests/conftest.py
Normal file
14
tests/unit_tests/conftest.py
Normal file
@ -0,0 +1,14 @@
|
||||
import pytest
|
||||
|
||||
from bec_widgets.utils import bec_dispatcher as bec_dispatcher_module
|
||||
|
||||
|
||||
@pytest.fixture(autouse=True)
|
||||
def bec_dispatcher(threads_check):
|
||||
bec_dispatcher = bec_dispatcher_module.BECDispatcher()
|
||||
yield bec_dispatcher
|
||||
bec_dispatcher.disconnect_all()
|
||||
# clean BEC client
|
||||
bec_dispatcher.client.shutdown()
|
||||
# reinitialize singleton for next test
|
||||
bec_dispatcher_module.BECDispatcher.reset_singleton()
|
0
tests/unit_tests/test_msgs/__init__.py
Normal file
0
tests/unit_tests/test_msgs/__init__.py
Normal file
@ -1,6 +1,4 @@
|
||||
# pylint: disable = no-name-in-module,missing-class-docstring, missing-module-docstring
|
||||
import os
|
||||
import pickle
|
||||
from unittest.mock import MagicMock
|
||||
|
||||
import pytest
|
||||
@ -9,7 +7,7 @@ from qtpy.QtWidgets import QLineEdit
|
||||
from bec_widgets.utils.widget_io import WidgetIO
|
||||
from bec_widgets.widgets import ScanControl
|
||||
|
||||
from .test_msgs.available_scans_message import available_scans_message
|
||||
from tests.unit_tests.test_msgs.available_scans_message import available_scans_message
|
||||
|
||||
|
||||
class FakePositioner:
|
Reference in New Issue
Block a user