Surface silently dropped inputs and anchor the platform defaults to shared constants

This commit is contained in:
J. Nick Koston
2026-08-20 05:21:41 -05:00
parent 4f11db4232
commit ff7161d7eb
5 changed files with 64 additions and 47 deletions
@@ -2,14 +2,10 @@
from __future__ import annotations
from collections.abc import Generator
import pytest
from esphome.components.esp8266 import (
ARDUINO_4_PLATFORM_VERSION,
_format_framework_arduino_version,
_parse_platform_version,
ARDUINO_FRAMEWORK_SCHEMA,
_validate_native_toolchain,
)
import esphome.config_validation as cv
@@ -26,26 +22,17 @@ from esphome.types import ConfigType
@pytest.fixture(autouse=True)
def _arduino_toolchain() -> Generator[None]:
def _arduino_toolchain() -> None:
# The suite-wide reset_core fixture clears CORE.toolchain after each test
CORE.toolchain = Toolchain.ARDUINO
yield
CORE.toolchain = None
def _config(
version: str = "3.1.2",
source: str | None = None,
platform_version: str | None = None,
board: str = "nodemcuv2",
) -> ConfigType:
def _config(board: str = "nodemcuv2", **framework: str) -> ConfigType:
framework.setdefault(CONF_VERSION, "3.1.2")
# The real schema fills the source/platform_version defaults, so these
# tests validate against what config validation actually emits
return {
CONF_FRAMEWORK: {
CONF_VERSION: version,
CONF_SOURCE: source
or _format_framework_arduino_version(cv.Version.parse(version)),
CONF_PLATFORM_VERSION: platform_version
or _parse_platform_version(str(ARDUINO_4_PLATFORM_VERSION)),
},
CONF_FRAMEWORK: ARDUINO_FRAMEWORK_SCHEMA(framework),
CONF_BOARD: board,
}
@@ -57,35 +44,42 @@ def test_valid_config_passes() -> None:
def test_platformio_toolchain_skips_checks() -> None:
CORE.toolchain = Toolchain.PLATFORMIO
config = _config(version="2.7.4", board="not_a_board")
config = _config(board="not_a_board", **{CONF_VERSION: "2.7.4"})
assert _validate_native_toolchain(config) is config
def test_version_floor_is_3_1_1() -> None:
def test_version_below_floor_rejected() -> None:
# 3.1.0 has no registry package, so the native floor is 3.1.1
with pytest.raises(cv.Invalid, match="3.1.1 or newer"):
_validate_native_toolchain(_config(version="3.1.0"))
_validate_native_toolchain(_config(version="3.1.1"))
_validate_native_toolchain(_config(**{CONF_VERSION: "3.1.0"}))
def test_custom_platform_version_warns(caplog: pytest.LogCaptureFixture) -> None:
_validate_native_toolchain(
_config(platform_version="platformio/espressif8266@4.0.1")
)
def test_version_at_floor_accepted() -> None:
_validate_native_toolchain(_config(**{CONF_VERSION: "3.1.1"}))
def test_custom_platform_version_warns_and_is_dropped(
caplog: pytest.LogCaptureFixture,
) -> None:
config = _config(**{CONF_PLATFORM_VERSION: "platformio/espressif8266@4.0.1"})
_validate_native_toolchain(config)
assert "'platform_version' is ignored" in caplog.text
assert CONF_PLATFORM_VERSION not in config[CONF_FRAMEWORK]
def test_default_platform_version_does_not_warn(
caplog: pytest.LogCaptureFixture,
) -> None:
_validate_native_toolchain(_config())
config = _config()
_validate_native_toolchain(config)
assert "'platform_version' is ignored" not in caplog.text
assert CONF_PLATFORM_VERSION not in config[CONF_FRAMEWORK]
def test_custom_source_rejected() -> None:
with pytest.raises(cv.Invalid, match="custom framework source"):
_validate_native_toolchain(
_config(source="https://github.com/esp8266/Arduino.git")
_config(**{CONF_SOURCE: "https://github.com/esp8266/Arduino.git"})
)