mirror of
https://github.com/tiqi-group/pydase.git
synced 2025-04-20 00:10:03 +02:00
updates serializer tests
This commit is contained in:
parent
24a01c0982
commit
99c7ad0ec8
@ -1,4 +1,5 @@
|
|||||||
import asyncio
|
import asyncio
|
||||||
|
import enum
|
||||||
from enum import Enum
|
from enum import Enum
|
||||||
from typing import Any
|
from typing import Any
|
||||||
|
|
||||||
@ -18,6 +19,11 @@ from pydase.utils.serializer import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
class MyEnum(enum.Enum):
|
||||||
|
RUNNING = "running"
|
||||||
|
FINISHED = "finished"
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.parametrize(
|
@pytest.mark.parametrize(
|
||||||
"test_input, expected",
|
"test_input, expected",
|
||||||
[
|
[
|
||||||
@ -396,33 +402,55 @@ def setup_dict() -> dict[str, Any]:
|
|||||||
class ServiceClass(pydase.DataService):
|
class ServiceClass(pydase.DataService):
|
||||||
attr1 = 1.0
|
attr1 = 1.0
|
||||||
attr2 = MySubclass()
|
attr2 = MySubclass()
|
||||||
|
enum_attr = MyEnum.RUNNING
|
||||||
attr_list = [0, 1, MySubclass()]
|
attr_list = [0, 1, MySubclass()]
|
||||||
|
|
||||||
return ServiceClass().serialize()["value"]
|
return ServiceClass().serialize()["value"]
|
||||||
|
|
||||||
|
|
||||||
def test_update_attribute(setup_dict) -> None:
|
def test_update_attribute(setup_dict: dict[str, Any]) -> 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) -> None:
|
def test_update_nested_attribute(setup_dict: dict[str, Any]) -> 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) -> None:
|
def test_update_float_attribute_to_enum(setup_dict: dict[str, Any]) -> None:
|
||||||
|
set_nested_value_by_path(setup_dict, "attr2.attr3", MyEnum.RUNNING)
|
||||||
|
assert setup_dict["attr2"]["value"]["attr3"] == {
|
||||||
|
"doc": None,
|
||||||
|
"enum": {"FINISHED": "finished", "RUNNING": "running"},
|
||||||
|
"readonly": False,
|
||||||
|
"type": "Enum",
|
||||||
|
"value": "RUNNING",
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
def test_update_enum_attribute_to_float(setup_dict: dict[str, Any]) -> None:
|
||||||
|
set_nested_value_by_path(setup_dict, "enum_attr", 1.01)
|
||||||
|
assert setup_dict["enum_attr"] == {
|
||||||
|
"doc": None,
|
||||||
|
"readonly": False,
|
||||||
|
"type": "float",
|
||||||
|
"value": 1.01,
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
def test_update_list_entry(setup_dict: dict[str, Any]) -> 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) -> None:
|
def test_update_list_append(setup_dict: dict[str, Any]) -> 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(
|
def test_update_invalid_list_index(
|
||||||
setup_dict, caplog: pytest.LogCaptureFixture
|
setup_dict: dict[str, Any], caplog: pytest.LogCaptureFixture
|
||||||
) -> None:
|
) -> 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 (
|
||||||
|
Loading…
x
Reference in New Issue
Block a user