Skip to content

Add focused pytest coverage for display and LVGL metadata validation#144

Closed
Copilot wants to merge 2 commits into
lvgl-endianfrom
copilot/lvgl-endian
Closed

Add focused pytest coverage for display and LVGL metadata validation#144
Copilot wants to merge 2 commits into
lvgl-endianfrom
copilot/lvgl-endian

Conversation

Copy link
Copy Markdown

Copilot AI commented May 27, 2026

This adds targeted pytest coverage for the display metadata / LVGL metadata-validation refactor on lvgl-endian. The new tests lock in the ID-resolution guard behavior in display and the byte-order validation/fallback contract in lvgl.final_validation().

  • Display metadata guard coverage

    • Add assertions for metadata access before ID resolution completes.
    • Cover both get_display_metadata() and get_all_display_metadata() using real ID objects with unresolved id=None.
  • Duplicate registration coverage

    • Add a focused test proving add_metadata() rejects duplicate registration of the same ID object.
  • LVGL byte-order validation coverage

    • Add/retain coverage for a single LVGL instance configured with multiple displays that advertise conflicting byte_order metadata.
    • Verify LVGL rejects mixed display byte orders with a clear validation failure.
  • LVGL default fallback coverage

    • Add/retain coverage for the no-override path where LVGL config omits byte_order and display metadata does not supply one.
    • Verify final validation defaults LVGL to big_endian.
  • Test fixtures kept narrow

    • Use minimal resolved-ID config structures for LVGL validation tests rather than broader integration setup.
    • Keep coverage concentrated in existing component test modules under tests/component_tests/display/ and tests/component_tests/lvgl/.

Example of the guarded metadata contract covered by these tests:

display_id = ID(None)
add_metadata(display_id, 320, 240)

with pytest.raises(AssertionError, match="resolved"):
    get_display_metadata("display_1")
Original prompt

Add focused pytest coverage on branch lvgl-endian in repository clydebarrow/esphome to address remaining test gaps in the display metadata / LVGL metadata-validation refactor.

Context:

  • The branch head includes commit 3edb476c2d6f3501ec34047b7c4aeae24f9de004 ([lvgl][mipi_spi][mipi_rgb][mipi_dsi] Metadata validation).
  • esphome/components/display/__init__.py now stores metadata as a list of (ID, DisplayMetaData) tuples and explicitly guards against metadata lookups before IDs have been resolved.
  • esphome/components/lvgl/__init__.py performs final validation using display metadata for byte_order, has_writer, rotation, and draw_rounding.
  • mipi_spi, mipi_rgb, and mipi_dsi all populate the expanded metadata fields.

Please create a pull request against branch lvgl-endian that adds pytest cases for the missing/high-value coverage areas below.

Required tests to add:

  1. Display metadata guard tests
  • Add tests for the new assertion guards in esphome/components/display/__init__.py:
    • get_display_metadata() should assert if metadata contains an unresolved ID (i.e. id_.id is None).
    • get_all_display_metadata() should assert if any stored metadata entry has an unresolved ID.
  • Use realistic ID objects rather than string stand-ins.
  1. Duplicate metadata registration test
  • Add a test ensuring add_metadata() rejects duplicate registration for the same ID object.
  • Assert on the failure/exception behavior introduced by the new duplicate check.
  1. LVGL cross-display byte-order validation test
  • Add a test that verifies lvgl.final_validation() rejects a single LVGL instance configured with multiple displays whose metadata advertises different byte_order values.
  • Prefer a focused unit/component test that directly exercises final validation with realistic config structures and resolved IDs, rather than a broad integration test if that is simpler and more stable.
  1. LVGL default byte-order fallback test
  • Add a test ensuring that when LVGL config omits byte_order and no display metadata contributes an override, final validation defaults LVGL to big_endian.
  • Keep the test narrowly scoped and deterministic.

Implementation guidance:

  • Keep the new tests minimal and consistent with the existing test style in this repository.
  • Reuse or extend existing test modules if appropriate (for example under tests/component_tests/display/ and tests/component_tests/lvgl/).
  • Avoid changing production code unless strictly required to make the tests meaningful.
  • If any existing tests are stale because of the ID-based metadata API change, update them as needed as part of the PR so the suite reflects the current behavior.

Success criteria:

  • New tests fail on the pre-change behavior and pass with the current refactor.
  • Tests clearly validate the intended metadata contract and LVGL final-validation behavior.
  • PR includes only test changes or the smallest necessary supporting test adjustments.

The following is the prior conversation context from the user's chat exploration (may be truncated):

User: Review the changes just pushed to branch lvgl-endian

Assistant: The latest push on lvgl-endian looks reviewable but not merge-ready as-is because the branch also contains a very large unrelated drift from dev. The most recent commit itself is focused and reasonable; the branch overall is not.

PR Summary

There doesn’t appear to be an open PR for clydebarrow:lvgl-endian, so I reviewed the latest pushed commit plus the branch diff against the repo’s default branch dev.

  • Repo default branch: dev
  • Branch head commit: 3edb476c2d6f3501ec34047b7c4aeae24f9de004
  • Latest commit title: [lvgl][mipi_spi][mipi_rgb][mipi_dsi] Metadata validation
  • Latest commit stats: 7 files changed, +423 / -127 overall, but only 6 source/test files are directly tied to the LVGL/display metadata change; the rest of branch diff contains lots of unrelated upstream changes.
  • Open PR found: none
  • Risk:
    • Latest commit only: low-to-medium
    • Whole branch vs dev: high, because it includes a huge amount of unrelated change

Core Changes

The latest commit introduces a cleaner display metadata contract so LVGL can validate compatibility using metadata rather than peeking into raw display config structures.

What changed in the latest commit

  1. display metadata expanded
    • DisplayMetaData now includes:
      • byte_order
      • rotation
      • draw_rounding
      • has_writer
      • has_hardware_rotation
  2. Metadata registration moved earlier
    • mipi_spi, mipi_rgb, and mipi_dsi now call display.add_metadata(...) during schema/config processing rather than later codegen paths.
  3. LVGL final validation now uses metadata
    • It:
      • auto-infers byte_order from attached displays
      • rejects mixed display byte orders in one LVGL instance
      • rejects displays marked...

This pull request was created from Copilot chat.

Copilot AI changed the title [WIP] Add pytest coverage for display metadata validation Add focused pytest coverage for display and LVGL metadata validation May 27, 2026
Copilot AI requested a review from clydebarrow May 27, 2026 11:18
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.

2 participants