0
0
mirror of https://github.com/bec-project/bec_widgets.git synced 2025-07-14 03:31:50 +02:00

test(unit_tests): unit tests adjusted to use a modern plotting framework instead of BECFigure

This commit is contained in:
2025-03-20 21:28:39 +01:00
parent 6ca4aa0f9b
commit 6ade934356
3 changed files with 14 additions and 23 deletions

View File

@ -3,31 +3,22 @@ from unittest import mock
import pytest import pytest
from bec_widgets.cli.client import BECFigure from bec_widgets.cli.client import BECDockArea
from bec_widgets.cli.client_utils import BECGuiClient, _start_plot_process from bec_widgets.cli.client_utils import BECGuiClient, _start_plot_process
from bec_widgets.tests.utils import FakeDevice
@pytest.fixture @pytest.fixture
def cli_figure(): def cli_dock_area():
fig = BECFigure(gui_id="test") dock_area = BECDockArea(gui_id="test")
with mock.patch.object(fig, "_run_rpc") as mock_rpc_call: with mock.patch.object(dock_area, "_run_rpc") as mock_rpc_call:
with mock.patch.object(fig, "_gui_is_alive", return_value=True): with mock.patch.object(dock_area, "_gui_is_alive", return_value=True):
yield fig, mock_rpc_call yield dock_area, mock_rpc_call
def test_rpc_call_plot(cli_figure): def test_rpc_call_new_dock(cli_dock_area):
fig, mock_rpc_call = cli_figure dock_area, mock_rpc_call = cli_dock_area
fig.plot(x_name="samx", y_name="bpm4i") dock_area.new(name="test")
mock_rpc_call.assert_called_with("plot", x_name="samx", y_name="bpm4i") mock_rpc_call.assert_called_with("new", name="test")
def test_rpc_call_accepts_device_as_input(cli_figure):
dev1 = FakeDevice("samx")
dev2 = FakeDevice("bpm4i")
fig, mock_rpc_call = cli_figure
fig.plot(x_name=dev1, y_name=dev2)
mock_rpc_call.assert_called_with("plot", x_name="samx", y_name="bpm4i")
@pytest.mark.parametrize( @pytest.mark.parametrize(
@ -40,13 +31,13 @@ def test_rpc_call_accepts_device_as_input(cli_figure):
) )
def test_client_utils_start_plot_process(config, call_config): def test_client_utils_start_plot_process(config, call_config):
with mock.patch("bec_widgets.cli.client_utils.subprocess.Popen") as mock_popen: with mock.patch("bec_widgets.cli.client_utils.subprocess.Popen") as mock_popen:
_start_plot_process("gui_id", BECFigure, "bec", config) _start_plot_process("gui_id", BECDockArea, "bec", config)
command = [ command = [
"bec-gui-server", "bec-gui-server",
"--id", "--id",
"gui_id", "gui_id",
"--gui_class", "--gui_class",
"BECFigure", "BECDockArea",
"--gui_class_id", "--gui_class_id",
"bec", "bec",
"--hide", "--hide",

View File

@ -7,7 +7,7 @@ from qtpy.QtWidgets import QVBoxLayout, QWidget
from bec_widgets.utils import Colors, ConnectionConfig from bec_widgets.utils import Colors, ConnectionConfig
from bec_widgets.utils.bec_widget import BECWidget from bec_widgets.utils.bec_widget import BECWidget
from bec_widgets.utils.colors import apply_theme from bec_widgets.utils.colors import apply_theme
from bec_widgets.widgets.containers.figure.plots.waveform.waveform_curve import CurveConfig from bec_widgets.widgets.plots_next_gen.waveform.curve import CurveConfig
from tests.unit_tests.client_mocks import mocked_client from tests.unit_tests.client_mocks import mocked_client
from tests.unit_tests.conftest import create_widget from tests.unit_tests.conftest import create_widget

View File

@ -3,5 +3,5 @@ from bec_widgets.cli.rpc.rpc_widget_handler import RPCWidgetHandler
def test_rpc_widget_handler(): def test_rpc_widget_handler():
handler = RPCWidgetHandler() handler = RPCWidgetHandler()
assert "BECFigure" in handler.widget_classes assert "Image" in handler.widget_classes
assert "RingProgressBar" in handler.widget_classes assert "RingProgressBar" in handler.widget_classes