Skip to content

Add tests for EnumParityTest#242

Merged
llucax merged 2 commits into
frequenz-floss:v0.x.xfrom
llucax:enum-parity-tests
Jul 7, 2026
Merged

Add tests for EnumParityTest#242
llucax merged 2 commits into
frequenz-floss:v0.x.xfrom
llucax:enum-parity-tests

Conversation

@llucax

@llucax llucax commented Jul 6, 2026

Copy link
Copy Markdown
Contributor

This test utility is part of the public interface, a tool offered to downstream users, so it should be properly tested.

This PR adds tests cover for:

  • Positive: a correct enum passes every inherited check (including no-op deprecated_members/absent_members).
  • Forward-compat: a protobuf value not yet mirrored in Python is tolerated.
  • Failure detection: value mismatch and name mismatch make the relevant checks raise AssertionError.
  • absent_members: passes when a member is removed from Python but kept in protobuf; fails when a "removed" member is still present.
  • deprecated_members: warns on access yet satisfies parity; and is caught when a listed member isn't actually deprecated.
  • silence_deprecations: a fully-deprecated enum with @deprecated converters (mirrors the real EvChargerType/BatteryType) round-trips cleanly.
  • from_proto unknown: rejects a converter returning a non-int.
  • Context managers _maybe_ignore_deprecation / _maybe_silence_converter_deprecation: suppress warnings only when configured.
  • pytest_generate_tests: parametrizes pb_name/member correctly and ignores unrelated fixtures.
  • test_proto_enum_matches_enum_value(): detects value mismatches (this is currently not properly checked by EnumParityTest`).

It also fixes EnumParityTest so protobuf values whose Python member name exists with a different number fail parity checks instead of being treated as unmirrored protobuf values.

llucax added 2 commits July 6, 2026 17:20
This test utility is part of the public interface, a tool offered to
downstream users, so it should be properly tested.

Added tests cover:
- Positive: a correct enum passes every inherited check (including no-op
  `deprecated_members`/`absent_members`).
- Forward-compat: a protobuf value not yet mirrored in Python is
  tolerated.
- Failure detection: value mismatch and name mismatch make the relevant
  checks raise `AssertionError`.
- `absent_members`: passes when a member is removed from Python but
  kept in protobuf; fails when a "removed" member is still present.
- `deprecated_members`: warns on access yet satisfies parity; and is
  caught when a listed member isn't actually deprecated.
- `silence_deprecations`: a fully-deprecated enum with `@deprecated`
  converters (mirrors the real `EvChargerType`/`BatteryType`)
  round-trips cleanly.
- `from_proto` unknown: rejects a converter returning a non-`int`.
- Context managers `_maybe_ignore_deprecation` /
  `_maybe_silence_converter_deprecation`: suppress warnings only when
  configured.
- `pytest_generate_tests`: parametrizes `pb_name`/`member` correctly and
  ignores unrelated fixtures.
- `test_proto_enum_matches_enum_value(): detects value mismatches
  (this is currently not properly checked by `EnumParityTest`).

Signed-off-by: Leandro Lucarella <luca-frequenz@llucax.com>
Fixed `EnumParityTest` so protobuf values whose Python member name
exists with a different number fail parity checks instead of being
treated as unmirrored protobuf values.

Signed-off-by: Leandro Lucarella <luca-frequenz@llucax.com>
@llucax llucax requested a review from a team as a code owner July 6, 2026 15:20
@llucax llucax requested review from florian-wagner-frequenz and removed request for a team July 6, 2026 15:20
@github-actions github-actions Bot added part:docs Affects the documentation part:tests Affects the unit, integration and performance (benchmarks) tests labels Jul 6, 2026
@llucax llucax self-assigned this Jul 6, 2026
@llucax llucax requested a review from Marenz July 6, 2026 15:25
@llucax llucax added this to the v0.4.1 milestone Jul 6, 2026
@llucax llucax enabled auto-merge July 6, 2026 15:27
@llucax llucax added this pull request to the merge queue Jul 7, 2026
Merged via the queue into frequenz-floss:v0.x.x with commit 23effab Jul 7, 2026
9 checks passed
@llucax llucax deleted the enum-parity-tests branch July 7, 2026 12:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

part:docs Affects the documentation part:tests Affects the unit, integration and performance (benchmarks) tests

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants