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

fix(test/e2e): dockarea and dock e2e tests changed to check asserts against config_dict

This commit is contained in:
2024-06-05 23:22:05 +02:00
parent cd9fc46ff8
commit 5c6ba65469
3 changed files with 49 additions and 36 deletions

View File

@ -1,9 +1,8 @@
# This file was automatically generated by generate_cli.py
from bec_widgets.cli.client_utils import rpc_call, RPCBase, BECGuiClientMixin
from typing import Literal, Optional, overload
from bec_widgets.cli.client_utils import BECGuiClientMixin, RPCBase, rpc_call
class BECPlotBase(RPCBase):
@property
@ -1588,10 +1587,6 @@ class BECDockArea(RPCBase, BECGuiClientMixin):
extra(str): Extra docks that are in the dockarea but that are not mentioned in state will be added to the bottom of the dockarea, unless otherwise specified by the extra argument.
"""
@rpc_call
def get_docks_repr(self):
"""Return dict, list and text representation of docks"""
@rpc_call
def add_dock(
self,
@ -1655,6 +1650,16 @@ class BECDockArea(RPCBase, BECGuiClientMixin):
Get all registered RPC objects.
"""
@property
@rpc_call
def temp_areas(self) -> "list":
"""
Get the temporary areas in the dock area.
Returns:
list: The temporary areas in the dock area.
"""
class SpiralProgressBar(RPCBase):
@rpc_call

View File

@ -1,6 +1,5 @@
from __future__ import annotations
import collections
from typing import Literal, Optional
from weakref import WeakValueDictionary
@ -34,6 +33,7 @@ class BECDockArea(BECConnector, DockArea):
"detach_dock",
"attach_all",
"get_all_rpc",
"temp_areas",
]
def __init__(
@ -69,19 +69,24 @@ class BECDockArea(BECConnector, DockArea):
"""
return dict(self.docks)
def get_docks_repr(self) -> dict:
docks_repr = {
"docks": collections.defaultdict(dict),
"tempAreas": list(map(str, self.tempAreas)),
}
for dock_name, dock in self.panels.items():
docks_repr["docks"][dock_name]["widgets"] = list(map(str, dock.widgets))
return docks_repr
@panels.setter
def panels(self, value: dict):
self.docks = WeakValueDictionary(value)
@property
def temp_areas(self) -> list:
"""
Get the temporary areas in the dock area.
Returns:
list: The temporary areas in the dock area.
"""
return list(map(str, self.tempAreas))
@temp_areas.setter
def temp_areas(self, value: list):
self.tempAreas = list(map(str, value))
def restore_state(
self, state: dict = None, missing: Literal["ignore", "error"] = "ignore", extra="bottom"
):
@ -116,6 +121,7 @@ class BECDockArea(BECConnector, DockArea):
name(str): The name of the dock to remove.
"""
dock = self.docks.pop(name, None)
self.config.docks.pop(name, None)
if dock:
dock.close()
if len(self.docks) <= 1:
@ -199,7 +205,7 @@ class BECDockArea(BECConnector, DockArea):
BECDock: The undocked dock.
"""
dock = self.docks[dock_name]
self.floatDock(dock)
dock.detach()
return dock
def attach_all(self):

View File

@ -23,17 +23,18 @@ def test_rpc_add_dock_with_figure_e2e(bec_client_lib, rpc_server_dock):
d1 = dock.add_dock("dock_1")
d2 = dock.add_dock("dock_2")
assert len(dock.get_docks_repr()["docks"]) == 3
dock_config = dock.config_dict
assert len(dock_config["docks"]) == 3
# Add 3 figures with some widgets
fig0 = d0.add_widget("BECFigure")
fig1 = d1.add_widget("BECFigure")
fig2 = d2.add_widget("BECFigure")
docks = dock.get_docks_repr()["docks"]
assert len(docks) == 3
assert len(docks["dock_0"]["widgets"]) == 1
assert len(docks["dock_1"]["widgets"]) == 1
assert len(docks["dock_2"]["widgets"]) == 1
dock_config = dock.config_dict
assert len(dock_config["docks"]) == 3
assert len(dock_config["docks"]["dock_0"]["widgets"]) == 1
assert len(dock_config["docks"]["dock_1"]["widgets"]) == 1
assert len(dock_config["docks"]["dock_2"]["widgets"]) == 1
assert fig1.__class__.__name__ == "BECFigure"
assert fig1.__class__ == BECFigure
@ -123,30 +124,31 @@ def test_dock_manipulations_e2e(rpc_server_dock):
d0 = dock.add_dock("dock_0")
d1 = dock.add_dock("dock_1")
d2 = dock.add_dock("dock_2")
assert len(dock.get_docks_repr()["docks"]) == 3
dock_config = dock.config_dict
assert len(dock_config["docks"]) == 3
d0.detach()
dock.detach_dock("dock_2")
docks_repr = dock.get_docks_repr()
assert len(docks_repr["docks"]) == 3
assert len(docks_repr["tempAreas"]) == 2
dock_config = dock.config_dict
assert len(dock_config["docks"]) == 3
assert len(dock.temp_areas) == 2
d0.attach()
docks_repr = dock.get_docks_repr()
assert len(docks_repr["docks"]) == 3
assert len(docks_repr["tempAreas"]) == 1
dock_config = dock.config_dict
assert len(dock_config["docks"]) == 3
assert len(dock.temp_areas) == 1
d2.remove()
docks_repr = dock.get_docks_repr()
assert len(docks_repr["docks"]) == 2
dock_config = dock.config_dict
assert len(dock_config["docks"]) == 2
assert ["dock_0", "dock_1"] == list(docks_repr["docks"])
assert ["dock_0", "dock_1"] == list(dock_config["docks"])
dock.clear_all()
docks_repr = dock.get_docks_repr()
assert len(docks_repr["docks"]) == 0
assert len(docks_repr["tempAreas"]) == 0
dock_config = dock.config_dict
assert len(dock_config["docks"]) == 0
assert len(dock.temp_areas) == 0
def test_spiral_bar(rpc_server_dock):