From 7e913dec791242854ab8ce53f0bba20ff7270ce5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Weber?= Date: Sun, 1 Dec 2024 18:54:43 +0100 Subject: [PATCH] implement last version of pymodaq_data serializer on Parameter --- pyproject.toml | 2 +- src/pymodaq_gui/parameter/utils.py | 10 ++++++---- tests/parameter_test/param_utils_test.py | 2 +- 3 files changed, 8 insertions(+), 6 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index 68a5e4ff..bb278ce1 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -46,7 +46,7 @@ dependencies = [ "setuptools>=60", "toml", "pymodaq_utils", - "pymodaq_data>=5.0.3", + "pymodaq_data>=5.0.13", ] [project.scripts] diff --git a/src/pymodaq_gui/parameter/utils.py b/src/pymodaq_gui/parameter/utils.py index d3a45758..0762edcb 100644 --- a/src/pymodaq_gui/parameter/utils.py +++ b/src/pymodaq_gui/parameter/utils.py @@ -1,5 +1,5 @@ from __future__ import annotations -from typing import TYPE_CHECKING, List, Tuple, Any +from typing import TYPE_CHECKING, List, Tuple, Any, Union from dataclasses import Field, fields import numpy as np from collections import OrderedDict @@ -53,7 +53,9 @@ def serialize(param: 'ParameterWithPath') -> bytes: return bytes_string @classmethod - def deserialize(cls, bytes_str: bytes) -> Tuple[Any, bytes]: + def deserialize(cls, + bytes_str: bytes) -> Union[ParameterWithPath, + Tuple[ParameterWithPath, bytes]]: """Convert bytes into a ParameterWithPath object Returns @@ -61,8 +63,8 @@ def deserialize(cls, bytes_str: bytes) -> Tuple[Any, bytes]: ParameterWithPath: the decoded object bytes: the remaining bytes string if any """ - path, remaining_bytes = ser_factory.get_apply_deserializer(bytes_str) - param_as_xml, remaining_bytes = ser_factory.get_apply_deserializer(remaining_bytes) + path, remaining_bytes = ser_factory.get_apply_deserializer(bytes_str, False) + param_as_xml, remaining_bytes = ser_factory.get_apply_deserializer(remaining_bytes, False) param_dict = ioxml.XML_string_to_parameter(param_as_xml) param_obj = Parameter(**param_dict[0]) return ParameterWithPath(param_obj, path), remaining_bytes diff --git a/tests/parameter_test/param_utils_test.py b/tests/parameter_test/param_utils_test.py index 25d208d9..45cfc7f6 100644 --- a/tests/parameter_test/param_utils_test.py +++ b/tests/parameter_test/param_utils_test.py @@ -238,7 +238,7 @@ def test_ParameterWithPath_serialize(): assert isinstance(putils.ser_factory.get_apply_serializer(p1_with_path), bytes) param_back: putils.ParameterWithPath = putils.ser_factory.get_apply_deserializer( - putils.ser_factory.get_apply_serializer(p1_with_path))[0] + putils.ser_factory.get_apply_serializer(p1_with_path)) assert param_back.path == p1_with_path.path assert putils.compareParameters(param_back.parameter, p1_with_path.parameter)