mirror of
https://github.com/bec-project/bec_widgets.git
synced 2025-07-14 11:41:49 +02:00
fix(widgets/dock): BECDockArea close overwrites the default pyqtgraph Container close + minor improvements
This commit is contained in:
114
tests/unit_tests/test_bec_dock.py
Normal file
114
tests/unit_tests/test_bec_dock.py
Normal file
@ -0,0 +1,114 @@
|
||||
# pylint: disable=missing-function-docstring, missing-module-docstring, unused-import
|
||||
|
||||
import pytest
|
||||
|
||||
from bec_widgets.widgets import BECDock, BECDockArea
|
||||
|
||||
from .client_mocks import mocked_client
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def bec_dock_area(qtbot, mocked_client):
|
||||
widget = BECDockArea(client=mocked_client)
|
||||
qtbot.addWidget(widget)
|
||||
qtbot.waitExposed(widget)
|
||||
yield widget
|
||||
widget.close()
|
||||
|
||||
|
||||
def test_bec_dock_area_init(bec_dock_area):
|
||||
assert bec_dock_area is not None
|
||||
assert bec_dock_area.client is not None
|
||||
assert isinstance(bec_dock_area, BECDockArea)
|
||||
assert bec_dock_area.config.widget_class == "BECDockArea"
|
||||
|
||||
|
||||
def test_bec_dock_area_add_remove_dock(bec_dock_area, qtbot):
|
||||
initial_count = len(bec_dock_area.docks)
|
||||
|
||||
# Adding 3 docks
|
||||
d0 = bec_dock_area.add_dock()
|
||||
d1 = bec_dock_area.add_dock()
|
||||
d2 = bec_dock_area.add_dock()
|
||||
|
||||
# Check if the docks were added
|
||||
assert len(bec_dock_area.docks) == initial_count + 3
|
||||
assert d0.name() in dict(bec_dock_area.docks)
|
||||
assert d1.name() in dict(bec_dock_area.docks)
|
||||
assert d2.name() in dict(bec_dock_area.docks)
|
||||
assert bec_dock_area.docks[d0.name()].config.widget_class == "BECDock"
|
||||
assert bec_dock_area.docks[d1.name()].config.widget_class == "BECDock"
|
||||
assert bec_dock_area.docks[d2.name()].config.widget_class == "BECDock"
|
||||
|
||||
# Check panels API for getting docks to CLI
|
||||
assert bec_dock_area.panels == dict(bec_dock_area.docks)
|
||||
|
||||
# Remove docks
|
||||
d0_name = d0.name()
|
||||
bec_dock_area.remove_dock(d0_name) # TODO fix this, works in jupyter console
|
||||
qtbot.wait(200)
|
||||
d1.remove()
|
||||
qtbot.wait(200)
|
||||
|
||||
assert len(bec_dock_area.docks) == initial_count + 1
|
||||
assert d0.name() not in dict(bec_dock_area.docks)
|
||||
assert d1.name() not in dict(bec_dock_area.docks)
|
||||
assert d2.name() in dict(bec_dock_area.docks)
|
||||
|
||||
|
||||
def test_add_remove_bec_figure_to_dock(bec_dock_area):
|
||||
d0 = bec_dock_area.add_dock()
|
||||
fig = d0.add_widget_bec("BECFigure")
|
||||
plt = fig.plot("samx", "bpm4i")
|
||||
im = fig.image("eiger")
|
||||
mm = fig.motor_map("samx", "samy")
|
||||
|
||||
assert len(bec_dock_area.docks) == 1
|
||||
assert len(d0.widgets) == 1
|
||||
assert len(d0.widget_list) == 1
|
||||
assert len(fig.widgets) == 3
|
||||
|
||||
assert fig.config.widget_class == "BECFigure"
|
||||
assert plt.config.widget_class == "BECWaveform"
|
||||
assert im.config.widget_class == "BECImageShow"
|
||||
assert mm.config.widget_class == "BECMotorMap"
|
||||
|
||||
|
||||
def test_dock_area_errors(bec_dock_area):
|
||||
d0 = bec_dock_area.add_dock(name="dock_0")
|
||||
|
||||
with pytest.raises(ValueError) as excinfo:
|
||||
bec_dock_area.add_dock(name="dock_0")
|
||||
assert "Dock with name dock_0 already exists." in str(excinfo.value)
|
||||
|
||||
|
||||
def test_close_docks(bec_dock_area, qtbot):
|
||||
d0 = bec_dock_area.add_dock(name="dock_0")
|
||||
d1 = bec_dock_area.add_dock(name="dock_1")
|
||||
d2 = bec_dock_area.add_dock(name="dock_2")
|
||||
|
||||
bec_dock_area.clear_all()
|
||||
qtbot.wait(200)
|
||||
assert len(bec_dock_area.docks) == 0
|
||||
|
||||
|
||||
def test_undock_and_dock_docks(bec_dock_area, qtbot):
|
||||
d0 = bec_dock_area.add_dock(name="dock_0")
|
||||
d1 = bec_dock_area.add_dock(name="dock_1")
|
||||
d2 = bec_dock_area.add_dock(name="dock_4")
|
||||
d3 = bec_dock_area.add_dock(name="dock_3")
|
||||
|
||||
d0.detach()
|
||||
bec_dock_area.detach_dock("dock_1")
|
||||
d2.detach()
|
||||
|
||||
assert len(bec_dock_area.docks) == 4
|
||||
assert len(bec_dock_area.tempAreas) == 3
|
||||
|
||||
d0.attach()
|
||||
assert len(bec_dock_area.docks) == 4
|
||||
assert len(bec_dock_area.tempAreas) == 2
|
||||
|
||||
bec_dock_area.attach_all()
|
||||
assert len(bec_dock_area.docks) == 4
|
||||
assert len(bec_dock_area.tempAreas) == 0
|
@ -1,6 +1,4 @@
|
||||
# pylint: disable=missing-function-docstring, missing-module-docstring, unused-import
|
||||
import os
|
||||
from unittest.mock import MagicMock
|
||||
|
||||
import numpy as np
|
||||
import pytest
|
||||
@ -48,12 +46,12 @@ def test_bec_figure_add_remove_plot(bec_figure):
|
||||
|
||||
# Check if the widgets were added
|
||||
assert len(bec_figure._widgets) == initial_count + 3
|
||||
assert "widget_1" in bec_figure._widgets
|
||||
assert "widget_2" in bec_figure._widgets
|
||||
assert "widget_3" in bec_figure._widgets
|
||||
assert bec_figure._widgets["widget_1"].config.widget_class == "BECWaveform"
|
||||
assert bec_figure._widgets["widget_2"].config.widget_class == "BECWaveform"
|
||||
assert bec_figure._widgets["widget_3"].config.widget_class == "BECPlotBase"
|
||||
assert w0.gui_id in bec_figure._widgets
|
||||
assert w1.gui_id in bec_figure._widgets
|
||||
assert w2.gui_id in bec_figure._widgets
|
||||
assert bec_figure._widgets[w0.gui_id].config.widget_class == "BECWaveform"
|
||||
assert bec_figure._widgets[w1.gui_id].config.widget_class == "BECWaveform"
|
||||
assert bec_figure._widgets[w2.gui_id].config.widget_class == "BECPlotBase"
|
||||
|
||||
# Check accessing positions by the grid in figure
|
||||
assert bec_figure[0, 0] == w0
|
||||
@ -61,11 +59,11 @@ def test_bec_figure_add_remove_plot(bec_figure):
|
||||
assert bec_figure[2, 0] == w2
|
||||
|
||||
# Removing 1 widget
|
||||
bec_figure.remove(widget_id="widget_1")
|
||||
bec_figure.remove(widget_id=w0.gui_id)
|
||||
assert len(bec_figure._widgets) == initial_count + 2
|
||||
assert "widget_1" not in bec_figure._widgets
|
||||
assert "widget_3" in bec_figure._widgets
|
||||
assert bec_figure._widgets["widget_2"].config.widget_class == "BECWaveform"
|
||||
assert w0.gui_id not in bec_figure._widgets
|
||||
assert w2.gui_id in bec_figure._widgets
|
||||
assert bec_figure._widgets[w1.gui_id].config.widget_class == "BECWaveform"
|
||||
|
||||
|
||||
def test_add_different_types_of_widgets(bec_figure):
|
||||
@ -121,20 +119,20 @@ def test_remove_plots(bec_figure):
|
||||
|
||||
# remove by coordinates
|
||||
bec_figure[0, 0].remove()
|
||||
assert "widget_1" not in bec_figure._widgets
|
||||
assert w1.gui_id not in bec_figure._widgets
|
||||
|
||||
# remove by widget_id
|
||||
bec_figure.remove(widget_id="widget_2")
|
||||
assert "widget_2" not in bec_figure._widgets
|
||||
bec_figure.remove(widget_id=w2.gui_id)
|
||||
assert w2.gui_id not in bec_figure._widgets
|
||||
|
||||
# remove by widget object
|
||||
w3.remove()
|
||||
assert "widget_3" not in bec_figure._widgets
|
||||
assert w3.gui_id not in bec_figure._widgets
|
||||
|
||||
# check the remaining widget 4
|
||||
assert bec_figure[0, 0] == w4
|
||||
assert bec_figure["widget_4"] == w4
|
||||
assert "widget_4" in bec_figure._widgets
|
||||
assert bec_figure[w4.gui_id] == w4
|
||||
assert w4.gui_id in bec_figure._widgets
|
||||
assert len(bec_figure._widgets) == 1
|
||||
|
||||
|
||||
@ -143,8 +141,8 @@ def test_remove_plots_by_coordinates_ints(bec_figure):
|
||||
w2 = bec_figure.add_plot(row=0, col=1)
|
||||
|
||||
bec_figure.remove(0, 0)
|
||||
assert "widget_1" not in bec_figure._widgets
|
||||
assert "widget_2" in bec_figure._widgets
|
||||
assert w1.gui_id not in bec_figure._widgets
|
||||
assert w2.gui_id in bec_figure._widgets
|
||||
assert bec_figure[0, 0] == w2
|
||||
assert len(bec_figure._widgets) == 1
|
||||
|
||||
@ -154,8 +152,8 @@ def test_remove_plots_by_coordinates_tuple(bec_figure):
|
||||
w2 = bec_figure.add_plot(row=0, col=1)
|
||||
|
||||
bec_figure.remove(coordinates=(0, 0))
|
||||
assert "widget_1" not in bec_figure._widgets
|
||||
assert "widget_2" in bec_figure._widgets
|
||||
assert w1.gui_id not in bec_figure._widgets
|
||||
assert w2.gui_id in bec_figure._widgets
|
||||
assert bec_figure[0, 0] == w2
|
||||
assert len(bec_figure._widgets) == 1
|
||||
|
||||
|
@ -40,7 +40,7 @@ def test_client_generator_with_black_formatting():
|
||||
'''\
|
||||
# This file was automatically generated by generate_cli.py
|
||||
|
||||
from bec_widgets.cli.client_utils import rpc_call, RPCBase, BECFigureClientMixin
|
||||
from bec_widgets.cli.client_utils import rpc_call, RPCBase, BECGuiClientMixin
|
||||
from typing import Literal, Optional, overload
|
||||
|
||||
class MockBECWaveform1D(RPCBase):
|
||||
|
@ -141,7 +141,7 @@ def test_getting_curve(bec_figure):
|
||||
c1_expected_config = CurveConfig(
|
||||
widget_class="BECCurve",
|
||||
gui_id="test_curve",
|
||||
parent_id="widget_1",
|
||||
parent_id=w1.gui_id,
|
||||
label="bpm4i-bpm4i",
|
||||
color="#cc4778",
|
||||
symbol="o",
|
||||
|
Reference in New Issue
Block a user