From ed80c92b1fd691e81e48c5d070e26940af9be744 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mose=20M=C3=BCller?= Date: Tue, 30 Apr 2024 15:22:44 +0200 Subject: [PATCH] adds dict test for pydase.Client The pop --- tests/client/test_client.py | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/tests/client/test_client.py b/tests/client/test_client.py index f30a6a5..afd34ae 100644 --- a/tests/client/test_client.py +++ b/tests/client/test_client.py @@ -12,6 +12,8 @@ def pydase_client() -> Generator[pydase.Client, None, Any]: class SubService(pydase.DataService): name = "SubService" + subservice_instance = SubService() + class MyService(pydase.DataService): def __init__(self) -> None: super().__init__() @@ -19,6 +21,10 @@ def pydase_client() -> Generator[pydase.Client, None, Any]: self._my_property = 12.1 self.sub_service = SubService() self.list_attr = [1, 2] + self.dict_attr = { + "foo": subservice_instance, + "dotted.key": subservice_instance, + } @property def my_property(self) -> float: @@ -104,6 +110,18 @@ def test_list(pydase_client: pydase.Client) -> None: assert pydase_client.proxy.list_attr == [] +def test_dict(pydase_client: pydase.Client) -> None: + pydase_client.proxy.dict_attr["foo"].name = "foo" + assert pydase_client.proxy.dict_attr["foo"].name == "foo" + assert pydase_client.proxy.dict_attr["dotted.key"].name == "foo" + + # pop will not return anything as the server object was deleted + assert pydase_client.proxy.dict_attr.pop("dotted.key") is None + + # pop will remove the dictionary entry on the server + assert list(pydase_client.proxy.dict_attr.keys()) == ["foo"] + + def test_tab_completion(pydase_client: pydase.Client) -> None: # Tab completion gets its suggestions from the __dir__ class method assert all(