Expose lazy UART tables in dir() and pin the contract with a test

This commit is contained in:
J. Nick Koston
2026-08-13 08:39:24 -05:00
parent 4abfdbbb15
commit 986123c5ee
2 changed files with 42 additions and 7 deletions
@@ -0,0 +1,24 @@
"""Tests for the logger component's lazy platform tables."""
import sys
def test_uart_selection_tables_exposed_for_external_tooling() -> None:
"""device-builder introspects these names off the module; keep them
accessible (and discoverable) without importing the platform packages."""
for mod in ("esphome.components.esp32", "esphome.components.libretiny"):
sys.modules.pop(mod, None)
from esphome.components import logger
assert "UART_SELECTION_ESP32" in dir(logger)
assert "UART_SELECTION_LIBRETINY" in dir(logger)
assert logger.UART_SELECTION_ESP32["ESP32C3"] == [
"UART0",
"UART1",
"USB_CDC",
"USB_SERIAL_JTAG",
]
assert "bk72xx" in logger.UART_SELECTION_LIBRETINY
# Repeated access returns the same cached object
assert logger.UART_SELECTION_ESP32 is logger.UART_SELECTION_ESP32