mirror of
https://github.com/tiqi-group/pydase.git
synced 2026-02-13 13:58:41 +01:00
adds enum name to serialized object representation
This commit is contained in:
@@ -103,6 +103,7 @@ class Serializer:
|
|||||||
value = obj.name
|
value = obj.name
|
||||||
readonly = False
|
readonly = False
|
||||||
doc = obj.__doc__
|
doc = obj.__doc__
|
||||||
|
class_name = type(obj).__name__
|
||||||
if sys.version_info < (3, 11) and doc == "An enumeration.":
|
if sys.version_info < (3, 11) and doc == "An enumeration.":
|
||||||
doc = None
|
doc = None
|
||||||
if isinstance(obj, pydase.components.coloured_enum.ColouredEnum):
|
if isinstance(obj, pydase.components.coloured_enum.ColouredEnum):
|
||||||
@@ -111,6 +112,7 @@ class Serializer:
|
|||||||
obj_type = "Enum"
|
obj_type = "Enum"
|
||||||
|
|
||||||
return {
|
return {
|
||||||
|
"name": class_name,
|
||||||
"type": obj_type,
|
"type": obj_type,
|
||||||
"value": value,
|
"value": value,
|
||||||
"readonly": readonly,
|
"readonly": readonly,
|
||||||
|
|||||||
@@ -83,6 +83,7 @@ def test_enum_serialize() -> None:
|
|||||||
assert dump(EnumAttribute())["value"] == {
|
assert dump(EnumAttribute())["value"] == {
|
||||||
"some_enum": {
|
"some_enum": {
|
||||||
"type": "Enum",
|
"type": "Enum",
|
||||||
|
"name": "EnumClass",
|
||||||
"value": "FOO",
|
"value": "FOO",
|
||||||
"enum": {"FOO": "foo", "BAR": "bar"},
|
"enum": {"FOO": "foo", "BAR": "bar"},
|
||||||
"readonly": False,
|
"readonly": False,
|
||||||
@@ -92,6 +93,7 @@ def test_enum_serialize() -> None:
|
|||||||
assert dump(EnumPropertyWithoutSetter())["value"] == {
|
assert dump(EnumPropertyWithoutSetter())["value"] == {
|
||||||
"some_enum": {
|
"some_enum": {
|
||||||
"type": "Enum",
|
"type": "Enum",
|
||||||
|
"name": "EnumClass",
|
||||||
"value": "FOO",
|
"value": "FOO",
|
||||||
"enum": {"FOO": "foo", "BAR": "bar"},
|
"enum": {"FOO": "foo", "BAR": "bar"},
|
||||||
"readonly": True,
|
"readonly": True,
|
||||||
@@ -101,6 +103,7 @@ def test_enum_serialize() -> None:
|
|||||||
assert dump(EnumPropertyWithSetter())["value"] == {
|
assert dump(EnumPropertyWithSetter())["value"] == {
|
||||||
"some_enum": {
|
"some_enum": {
|
||||||
"type": "Enum",
|
"type": "Enum",
|
||||||
|
"name": "EnumClass",
|
||||||
"value": "FOO",
|
"value": "FOO",
|
||||||
"enum": {"FOO": "foo", "BAR": "bar"},
|
"enum": {"FOO": "foo", "BAR": "bar"},
|
||||||
"readonly": False,
|
"readonly": False,
|
||||||
@@ -123,6 +126,7 @@ def test_ColouredEnum_serialize() -> None:
|
|||||||
|
|
||||||
assert dump(Status.FAILED) == {
|
assert dump(Status.FAILED) == {
|
||||||
"type": "ColouredEnum",
|
"type": "ColouredEnum",
|
||||||
|
"name": "Status",
|
||||||
"value": "FAILED",
|
"value": "FAILED",
|
||||||
"enum": {
|
"enum": {
|
||||||
"CANCELLED": "SlateGray",
|
"CANCELLED": "SlateGray",
|
||||||
@@ -427,6 +431,7 @@ def test_update_nested_attribute(setup_dict: dict[str, Any]) -> None:
|
|||||||
def test_update_float_attribute_to_enum(setup_dict: dict[str, Any]) -> 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)
|
set_nested_value_by_path(setup_dict, "attr2.attr3", MyEnum.RUNNING)
|
||||||
assert setup_dict["attr2"]["value"]["attr3"] == {
|
assert setup_dict["attr2"]["value"]["attr3"] == {
|
||||||
|
"name": "MyEnum",
|
||||||
"doc": "MyEnum description",
|
"doc": "MyEnum description",
|
||||||
"enum": {"FINISHED": "finished", "RUNNING": "running"},
|
"enum": {"FINISHED": "finished", "RUNNING": "running"},
|
||||||
"readonly": False,
|
"readonly": False,
|
||||||
@@ -476,6 +481,7 @@ def test_update_list_append(setup_dict: dict[str, SerializedObject]) -> None:
|
|||||||
set_nested_value_by_path(setup_dict, "attr_list[3]", MyEnum.RUNNING)
|
set_nested_value_by_path(setup_dict, "attr_list[3]", MyEnum.RUNNING)
|
||||||
assert setup_dict["attr_list"]["value"][3] == {
|
assert setup_dict["attr_list"]["value"][3] == {
|
||||||
"doc": "MyEnum description",
|
"doc": "MyEnum description",
|
||||||
|
"name": "MyEnum",
|
||||||
"enum": {"FINISHED": "finished", "RUNNING": "running"},
|
"enum": {"FINISHED": "finished", "RUNNING": "running"},
|
||||||
"readonly": False,
|
"readonly": False,
|
||||||
"type": "Enum",
|
"type": "Enum",
|
||||||
|
|||||||
Reference in New Issue
Block a user