diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 57117b2..a13d685 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -41,7 +41,3 @@ repos: - pyyaml - tomli always_run: true - - repo: https://github.com/mashi/codecov-validator - rev: 1.0.1 - hooks: - - id: ccv diff --git a/space_packet_parser/xtce/parameter_types.py b/space_packet_parser/xtce/parameter_types.py index e8b71b3..f20ad6b 100644 --- a/space_packet_parser/xtce/parameter_types.py +++ b/space_packet_parser/xtce/parameter_types.py @@ -126,8 +126,7 @@ def get_units(parameter_type_element: ElementTree.Element) -> str | tuple[str, . """ # Assume we are not parsing a Time Parameter Type, which stores units differently - units = parameter_type_element.findall("UnitSet/Unit") - units = [u.text for u in units if u.text] + units = parameter_type_element.xpath('.//*[local-name()="UnitSet"]/*[local-name()="Unit"]/text()') if not units: # Units are optional so return None if they aren't specified @@ -293,7 +292,6 @@ def to_xml(self, *, elmaker: ElementMaker) -> ElementTree.Element: """ param_type_element = getattr(elmaker, self.__class__.__name__)(name=self.name) - if self.unit: if isinstance(self.unit, tuple): unit_elements = [elmaker.Unit(u) for u in self.unit] diff --git a/tests/unit/test_xtce/test_parameter_types.py b/tests/unit/test_xtce/test_parameter_types.py index 2665438..58ead87 100644 --- a/tests/unit/test_xtce/test_parameter_types.py +++ b/tests/unit/test_xtce/test_parameter_types.py @@ -170,6 +170,21 @@ def test_string_parameter_type(elmaker, xtce_parser, xml_string: str, expectatio ), ( f""" + + + km + + + +""", + parameter_types.IntegerParameterType( + name="TEST_INT_Type", + unit="km", + encoding=encodings.IntegerDataEncoding(size_in_bits=16, encoding="unsigned"), + ), + ), + ( + f""" m @@ -843,3 +858,34 @@ def test_absolute_time_parameter_type(elmaker, xtce_parser, xml_string, expectat ElementTree.fromstring(result_string, parser=xtce_parser) ) assert full_circle == expectation + + +def test_parameter_type_to_xml_unit_serialization(elmaker): + """Test serialization of UnitSet in ParameterType.to_xml""" + + encoding = encodings.IntegerDataEncoding(size_in_bits=16, encoding="unsigned") + ns = {"xtce": XTCE_1_2_XMLNS} + + # Single unit + param = parameter_types.IntegerParameterType( + name="TEST_PARAM_Type", + unit="km", + encoding=encoding, + ) + element = param.to_xml(elmaker=elmaker) + + units = element.findall(".//xtce:Unit", namespaces=ns) + assert len(units) == 1 + assert units[0].text == "km" + + # Multiple units + param = parameter_types.IntegerParameterType( + name="TEST_PARAM_Type", + unit=("m", "s"), + encoding=encoding, + ) + element = param.to_xml(elmaker=elmaker) + + units = element.findall(".//xtce:Unit", namespaces=ns) + assert len(units) == 2 + assert [u.text for u in units] == ["m", "s"]