Skip to content

Issues/47 support xtce unitset#258

Open
blakedehaas wants to merge 2 commits into
mainfrom
issues/47-support-xtce-unitset
Open

Issues/47 support xtce unitset#258
blakedehaas wants to merge 2 commits into
mainfrom
issues/47-support-xtce-unitset

Conversation

@blakedehaas
Copy link
Copy Markdown
Collaborator

Summary

Adds support for multiple <xtce:Unit> elements within a <xtce:UnitSet>.

Previously, only a single unit was supported. This change allows compound units to be
parsed and serialized in accordance with the XTCE specification.

Changes

  • Updated ParameterType.get_units to return:
    • str for a single unit
    • tuple[str, ...] for multiple units
  • Updated to_xml to correctly serialize multiple <Unit> elements
  • Updated type hints and docstrings for consistency

Testing

  • Added test cases for multiple <xtce:Unit> support in:
    • IntegerParameterType
    • FloatParameterType
    • BinaryParameterType
  • Verified round-trip XML parsing and serialization
  • All tests pass (448 total), no regressions observed

@blakedehaas blakedehaas self-assigned this May 28, 2026
@blakedehaas blakedehaas requested a review from medley56 as a code owner May 28, 2026 19:09
@codecov
Copy link
Copy Markdown

codecov Bot commented May 28, 2026

Codecov Report

❌ Patch coverage is 80.00000% with 4 lines in your changes missing coverage. Please review.
✅ Project coverage is 94.80%. Comparing base (946497d) to head (e222883).

Files with missing lines Patch % Lines
space_packet_parser/xtce/parameter_types.py 80.00% 4 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #258      +/-   ##
==========================================
- Coverage   94.85%   94.80%   -0.05%     
==========================================
  Files          48       48              
  Lines        3885     3892       +7     
==========================================
+ Hits         3685     3690       +5     
- Misses        200      202       +2     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

1 similar comment
@codecov
Copy link
Copy Markdown

codecov Bot commented May 28, 2026

Codecov Report

❌ Patch coverage is 80.00000% with 4 lines in your changes missing coverage. Please review.
✅ Project coverage is 94.80%. Comparing base (946497d) to head (e222883).

Files with missing lines Patch % Lines
space_packet_parser/xtce/parameter_types.py 80.00% 4 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #258      +/-   ##
==========================================
- Coverage   94.85%   94.80%   -0.05%     
==========================================
  Files          48       48              
  Lines        3885     3892       +7     
==========================================
+ Hits         3685     3690       +5     
- Misses        200      202       +2     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Copy link
Copy Markdown
Member

@medley56 medley56 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice. One test coverage request.

Comment on lines +298 to 303
if isinstance(self.unit, tuple):
unit_elements = [elmaker.Unit(u) for u in self.unit]
param_type_element.append(elmaker.UnitSet(*unit_elements))
else:
param_type_element.append(elmaker.UnitSet(elmaker.Unit(self.unit)))

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add a unit test that covers these lines. This method is used when we serialize XML so it should live along side the other tests for that functionality.

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds support for parsing and serializing multiple <xtce:Unit> elements within a <xtce:UnitSet>, replacing the previous NotImplementedError path. ParameterType.get_units now returns str for a single unit, tuple[str, ...] for compound units, or None. Serialization in both the base ParameterType.to_xml and EnumeratedParameterType.to_xml handles the tuple case.

Changes:

  • get_units returns str | tuple[str, ...] | None instead of raising on multiple units.
  • to_xml (base and enumerated) serializes each element of a tuple as a separate <Unit> child.
  • Updated type hints and docstrings on ParameterType, StringParameterType, BinaryParameterType, BooleanParameterType, and EnumeratedParameterType.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
space_packet_parser/xtce/parameter_types.py Adds tuple-based compound unit support in parsing and serialization; widens unit parameter types and docstrings.
tests/unit/test_xtce/test_parameter_types.py Adds round-trip tests with multiple <xtce:Unit> entries for Integer, Float, and Binary parameter types.

Comment on lines +552 to +571
(
f"""
<xtce:BinaryParameterType xmlns:xtce="{XTCE_1_2_XMLNS}" name="TEST_PARAM_Type">
<xtce:UnitSet>
<xtce:Unit>m</xtce:Unit>
<xtce:Unit>s</xtce:Unit>
</xtce:UnitSet>
<xtce:BinaryDataEncoding>
<xtce:SizeInBits>
<xtce:FixedValue>128</xtce:FixedValue>
</xtce:SizeInBits>
</xtce:BinaryDataEncoding>
</xtce:BinaryParameterType>
""",
parameter_types.BinaryParameterType(
name="TEST_PARAM_Type",
unit=("m", "s"),
encoding=encodings.BinaryDataEncoding(fixed_size_in_bits=128),
),
),
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants