mirror of
https://github.com/tiqi-group/pydase.git
synced 2025-06-07 14:00:40 +02:00
fixes tests
This commit is contained in:
parent
7279fed2aa
commit
e8638f1f3a
@ -196,7 +196,7 @@ class DataService(rpyc.Service, AbstractDataService):
|
|||||||
)
|
)
|
||||||
|
|
||||||
# Traverse the serialized representation and set the attributes of the class
|
# Traverse the serialized representation and set the attributes of the class
|
||||||
serialized_class = self.serialize()
|
serialized_class = self.serialize()["value"]
|
||||||
for path in generate_serialized_data_paths(json_dict):
|
for path in generate_serialized_data_paths(json_dict):
|
||||||
nested_json_dict = get_nested_dict_by_path(json_dict, path)
|
nested_json_dict = get_nested_dict_by_path(json_dict, path)
|
||||||
value = nested_json_dict["value"]
|
value = nested_json_dict["value"]
|
||||||
|
@ -91,7 +91,7 @@ class Service(pydase.DataService):
|
|||||||
self._property_attr = value
|
self._property_attr = value
|
||||||
|
|
||||||
|
|
||||||
CURRENT_STATE = Service().serialize()
|
CURRENT_STATE = Service().serialize()["value"]
|
||||||
|
|
||||||
LOAD_STATE = {
|
LOAD_STATE = {
|
||||||
"list_attr": {
|
"list_attr": {
|
||||||
|
@ -323,7 +323,7 @@ def test_derived_data_service_serialization() -> None:
|
|||||||
|
|
||||||
|
|
||||||
@pytest.fixture
|
@pytest.fixture
|
||||||
def setup_dict():
|
def setup_dict() -> dict[str, Any]:
|
||||||
class MySubclass(pydase.DataService):
|
class MySubclass(pydase.DataService):
|
||||||
attr3 = 1.0
|
attr3 = 1.0
|
||||||
list_attr = [1.0, 1]
|
list_attr = [1.0, 1]
|
||||||
@ -333,30 +333,32 @@ def setup_dict():
|
|||||||
attr2 = MySubclass()
|
attr2 = MySubclass()
|
||||||
attr_list = [0, 1, MySubclass()]
|
attr_list = [0, 1, MySubclass()]
|
||||||
|
|
||||||
return ServiceClass().serialize()
|
return ServiceClass().serialize()["value"]
|
||||||
|
|
||||||
|
|
||||||
def test_update_attribute(setup_dict):
|
def test_update_attribute(setup_dict) -> None:
|
||||||
set_nested_value_by_path(setup_dict, "attr1", 15)
|
set_nested_value_by_path(setup_dict, "attr1", 15)
|
||||||
assert setup_dict["attr1"]["value"] == 15
|
assert setup_dict["attr1"]["value"] == 15
|
||||||
|
|
||||||
|
|
||||||
def test_update_nested_attribute(setup_dict):
|
def test_update_nested_attribute(setup_dict) -> None:
|
||||||
set_nested_value_by_path(setup_dict, "attr2.attr3", 25.0)
|
set_nested_value_by_path(setup_dict, "attr2.attr3", 25.0)
|
||||||
assert setup_dict["attr2"]["value"]["attr3"]["value"] == 25.0
|
assert setup_dict["attr2"]["value"]["attr3"]["value"] == 25.0
|
||||||
|
|
||||||
|
|
||||||
def test_update_list_entry(setup_dict):
|
def test_update_list_entry(setup_dict) -> None:
|
||||||
set_nested_value_by_path(setup_dict, "attr_list[1]", 20)
|
set_nested_value_by_path(setup_dict, "attr_list[1]", 20)
|
||||||
assert setup_dict["attr_list"]["value"][1]["value"] == 20
|
assert setup_dict["attr_list"]["value"][1]["value"] == 20
|
||||||
|
|
||||||
|
|
||||||
def test_update_list_append(setup_dict):
|
def test_update_list_append(setup_dict) -> None:
|
||||||
set_nested_value_by_path(setup_dict, "attr_list[3]", 20)
|
set_nested_value_by_path(setup_dict, "attr_list[3]", 20)
|
||||||
assert setup_dict["attr_list"]["value"][3]["value"] == 20
|
assert setup_dict["attr_list"]["value"][3]["value"] == 20
|
||||||
|
|
||||||
|
|
||||||
def test_update_invalid_list_index(setup_dict, caplog: pytest.LogCaptureFixture):
|
def test_update_invalid_list_index(
|
||||||
|
setup_dict, caplog: pytest.LogCaptureFixture
|
||||||
|
) -> None:
|
||||||
set_nested_value_by_path(setup_dict, "attr_list[10]", 30)
|
set_nested_value_by_path(setup_dict, "attr_list[10]", 30)
|
||||||
assert (
|
assert (
|
||||||
"Error occured trying to change 'attr_list[10]': list index "
|
"Error occured trying to change 'attr_list[10]': list index "
|
||||||
|
Loading…
x
Reference in New Issue
Block a user