Merge branch 'dev' into store-yaml-firmware

This commit is contained in:
J. Nick Koston
2026-07-03 19:04:12 -05:00
committed by GitHub
1326 changed files with 27006 additions and 16857 deletions
@@ -45,6 +45,36 @@ def test_process_stacktrace_esp8266_backtrace(
assert state is False
def test_process_stacktrace_esp8266_crash_handler(
setup_core: Path, mock_esp8266_decode_pc: Mock
) -> None:
"""Test process_stacktrace handles ESP8266 crash handler backtrace lines."""
from esphome.components.esp8266 import process_stacktrace
config = {"name": "test"}
# Simulate crash handler log lines as they appear from the API/serial
line_pc = "[E][esp8266:191]: PC: 0x40220060"
state = process_stacktrace(config, line_pc, False)
mock_esp8266_decode_pc.assert_called_once_with(config, "40220060")
assert state is False
mock_esp8266_decode_pc.reset_mock()
# Near-null data address (wild pointer) is not a code address, must be ignored
line_excvaddr = "[E][esp8266:193]: EXCVADDR: 0x0000008A"
state = process_stacktrace(config, line_excvaddr, False)
mock_esp8266_decode_pc.assert_not_called()
assert state is False
mock_esp8266_decode_pc.reset_mock()
line_bt0 = "[E][esp8266:196]: BT0: 0x40212345"
state = process_stacktrace(config, line_bt0, False)
mock_esp8266_decode_pc.assert_called_once_with(config, "40212345")
assert state is False
def test_process_stacktrace_esp32_backtrace(
setup_core: Path, mock_esp32_decode_pc: Mock
) -> None:
+42
View File
@@ -1,6 +1,8 @@
"""Tests for time component cron expression parsing."""
import errno
import subprocess
import sys
from unittest.mock import MagicMock, patch
import pytest
@@ -143,3 +145,43 @@ def test_validate_tz_accepts_posix_string_when_read_bytes_raises_einval() -> Non
_mock_resources_with_error(OSError(errno.EINVAL, "Invalid argument")),
):
assert validate_tz("<+08>-8") == "<+08>-8"
def _modules_after(code: str) -> set[str]:
"""Run code in a fresh interpreter and return the imported module names.
A subprocess is required because the test process itself has already
imported aioesphomeapi via other tests, so sys.modules here is useless.
"""
result = subprocess.run(
[sys.executable, "-c", f"import sys\n{code}\nprint('\\n'.join(sys.modules))"],
capture_output=True,
text=True,
check=True,
)
return set(result.stdout.split())
def test_importing_time_does_not_import_aioesphomeapi() -> None:
"""Importing the time component must not drag in aioesphomeapi.
aioesphomeapi is a heavy import (it builds a large number of dataclasses at
import time). The time component is auto-loaded by many components, so
importing it for its schema during config validation must not pay that
cost. The import is deferred to the functions that actually need it.
"""
modules = _modules_after("import esphome.components.time")
assert "aioesphomeapi" not in modules
def test_validate_tz_imports_aioesphomeapi_lazily() -> None:
"""Validating a non-empty timezone is what triggers the lazy import.
Documents the boundary: the cost is only paid when a timezone is actually
validated, not merely by loading the component.
"""
modules = _modules_after(
"from esphome.components.time import validate_tz\n"
"validate_tz('EST5EDT,M3.2.0,M11.1.0')"
)
assert "aioesphomeapi" in modules