From 5c6ba65469863ea1e6fc5abdc742650e20eba9b9 Mon Sep 17 00:00:00 2001 From: wyzula-jan Date: Wed, 5 Jun 2024 23:22:05 +0200 Subject: [PATCH] fix(test/e2e): dockarea and dock e2e tests changed to check asserts against config_dict --- bec_widgets/cli/client.py | 17 ++++++---- bec_widgets/widgets/dock/dock_area.py | 28 ++++++++++------- tests/end-2-end/test_bec_dock_rpc_e2e.py | 40 +++++++++++++----------- 3 files changed, 49 insertions(+), 36 deletions(-) diff --git a/bec_widgets/cli/client.py b/bec_widgets/cli/client.py index 63b7f686..92a95795 100644 --- a/bec_widgets/cli/client.py +++ b/bec_widgets/cli/client.py @@ -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 diff --git a/bec_widgets/widgets/dock/dock_area.py b/bec_widgets/widgets/dock/dock_area.py index 60eaea3b..4900e42a 100644 --- a/bec_widgets/widgets/dock/dock_area.py +++ b/bec_widgets/widgets/dock/dock_area.py @@ -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): diff --git a/tests/end-2-end/test_bec_dock_rpc_e2e.py b/tests/end-2-end/test_bec_dock_rpc_e2e.py index 43c2a19e..6324bbce 100644 --- a/tests/end-2-end/test_bec_dock_rpc_e2e.py +++ b/tests/end-2-end/test_bec_dock_rpc_e2e.py @@ -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):