Skip to content

Commit

Permalink
Test serialization of ParameterWithPath
Browse files Browse the repository at this point in the history
  • Loading branch information
seb5g committed Nov 5, 2024
1 parent d3e374b commit ab673cc
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 8 deletions.
11 changes: 7 additions & 4 deletions src/pymodaq_gui/parameter/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
from pymodaq_utils.utils import find_keys_from_val
from pymodaq_data.serialize.factory import SerializableFactory, SerializableBase
from pymodaq_gui.parameter import ioxml
if TYPE_CHECKING:
from pymodaq_gui.parameter import Parameter

from pymodaq_gui.parameter import Parameter

ser_factory = SerializableFactory()

Expand Down Expand Up @@ -50,6 +50,7 @@ def serialize(param: 'ParameterWithPath') -> bytes:
param_as_xml = ioxml.parameter_to_xml_string(param.parameter)
bytes_string += ser_factory.get_apply_serializer(path)
bytes_string += ser_factory.get_apply_serializer(param_as_xml)
return bytes_string

@classmethod
def deserialize(cls, bytes_str: bytes) -> Tuple[Any, bytes]:
Expand Down Expand Up @@ -135,8 +136,10 @@ def getValues(param:Parameter,) -> OrderedDict:
"""
return param.getValues()

def compareParameters(param1:Parameter,param2:Parameter,opts:list=[])-> bool:
"""Compare the structure and the opts of two parameters with their children, return True if structure and all opts are identical

def compareParameters(param1:Parameter, param2:Parameter, opts: list = [])-> bool:
"""Compare the structure and the opts of two parameters with their children,
return True if structure and all opts are identical
Parameters
----------
param1: Parameter
Expand Down
15 changes: 11 additions & 4 deletions tests/parameter_test/param_utils_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -136,10 +136,6 @@ def test_compareValuesParameter():
putils.compareValuesParameter(param1=P1,param2=P3) == False,
putils.compareValuesParameter(param1=P1,param2=P4) == False]






class TestScroll:
def test_scroll_log(self):
Expand Down Expand Up @@ -214,3 +210,14 @@ def test_set_param_from_param(qtbot):
assert settings_old.child('main_settings', 'axis').value() == 2
assert dict_widget.currentText() == 'DAQ2D'


def test_ParameterWithPath_serialize():

p1_with_path = putils.ParameterWithPath(P1.child('numbers', 'afloat', 'aint'))
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]
assert param_back.path == p1_with_path.path
assert putils.compareParameters(param_back.parameter, p1_with_path.parameter)

0 comments on commit ab673cc

Please sign in to comment.