mirror of
https://github.com/tiqi-group/pydase.git
synced 2025-06-07 05:50:41 +02:00
fixes serializer types and test
pydase dicts can only have stringed keys. This is now reflected in the serializer, as well.
This commit is contained in:
parent
88a630518b
commit
b209ad75bb
@ -164,16 +164,13 @@ class Serializer:
|
|||||||
}
|
}
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def _serialize_dict(
|
def _serialize_dict(obj: dict[str, Any], access_path: str = "") -> SerializedDict:
|
||||||
obj: dict[str | float, Any], access_path: str = ""
|
|
||||||
) -> SerializedDict:
|
|
||||||
readonly = False
|
readonly = False
|
||||||
doc = get_attribute_doc(obj)
|
doc = get_attribute_doc(obj)
|
||||||
value = {}
|
value = {}
|
||||||
for key, val in obj.items():
|
for key, val in obj.items():
|
||||||
processed_key = key if not isinstance(key, str) else f'"{key}"'
|
|
||||||
value[key] = Serializer.serialize_object(
|
value[key] = Serializer.serialize_object(
|
||||||
val, access_path=f"{access_path}[{processed_key}]"
|
val, access_path=f'{access_path}["{key}"]'
|
||||||
)
|
)
|
||||||
return {
|
return {
|
||||||
"full_access_path": access_path,
|
"full_access_path": access_path,
|
||||||
|
@ -400,7 +400,7 @@ def test_dict_serialization() -> None:
|
|||||||
|
|
||||||
test_dict = {
|
test_dict = {
|
||||||
"int_key": 1,
|
"int_key": 1,
|
||||||
1.0: 1.0,
|
"1.0": 1.0,
|
||||||
"bool_key": True,
|
"bool_key": True,
|
||||||
"Quantity_key": 1.0 * u.units.s,
|
"Quantity_key": 1.0 * u.units.s,
|
||||||
"DataService_key": MyClass(),
|
"DataService_key": MyClass(),
|
||||||
@ -442,8 +442,8 @@ def test_dict_serialization() -> None:
|
|||||||
"type": "bool",
|
"type": "bool",
|
||||||
"value": True,
|
"value": True,
|
||||||
},
|
},
|
||||||
1.0: {
|
"1.0": {
|
||||||
"full_access_path": "[1.0]",
|
"full_access_path": '["1.0"]',
|
||||||
"doc": None,
|
"doc": None,
|
||||||
"readonly": False,
|
"readonly": False,
|
||||||
"type": "float",
|
"type": "float",
|
||||||
|
Loading…
x
Reference in New Issue
Block a user