Make the testing-mode require explicit, reject a missing declared srcDir, and validate installs before marking success

This commit is contained in:
J. Nick Koston
2026-08-20 08:08:29 -05:00
parent 0defff2c81
commit 4eeceded0d
7 changed files with 63 additions and 17 deletions
@@ -49,7 +49,7 @@ def test_relocate_ratetable_requires_anchor() -> None:
def test_testing_memory_patches_enlarge_segments() -> None:
patched = apply_testing_memory_patches(_FLASH_LD_SNIPPET)
patched = apply_testing_memory_patches(_FLASH_LD_SNIPPET, require=())
assert (
"iram1_0_seg : org = 0x40100000, len = 0x200000"
in patched
@@ -83,4 +83,5 @@ def test_testing_memory_patches_require() -> None:
"MEMORY { }", require=("dram0_0_seg", "irom0_0_seg")
)
# Segments a file does not require are patched opportunistically only
assert apply_testing_memory_patches("MEMORY { }") == "MEMORY { }"
# With nothing required, unmatched content passes through unchanged
assert apply_testing_memory_patches("MEMORY { }", require=()) == "MEMORY { }"
+13 -9
View File
@@ -9,7 +9,7 @@ import pytest
from esphome.arduino8266 import component
from esphome.const import KEY_CORE, KEY_TARGET_PLATFORM, PLATFORM_ESP8266
from esphome.core import CORE, Library
from esphome.core import CORE, EsphomeError, Library
from esphome.platformio.library import ConvertedLibrary, LibraryBackend
@@ -257,16 +257,20 @@ def test_library_info_missing_explicit_include_warns(
assert "include dir nope which does not exist" in caplog.text
def test_library_info_missing_declared_dirs_warn(
tmp_path: Path, caplog: pytest.LogCaptureFixture
) -> None:
"""Explicitly declared srcDir/includeDir that do not exist warn by name."""
def test_library_info_missing_declared_src_dir_raises(tmp_path: Path) -> None:
"""An explicitly declared srcDir that does not exist is a manifest error."""
read_path = tmp_path / "lib"
read_path.mkdir()
component._library_info(
"x", read_path, {"build": {"srcDir": "nosrc", "includeDir": "noinc"}}
)
assert "srcDir nosrc which does not exist" in caplog.text
with pytest.raises(EsphomeError, match="srcDir nosrc which does not exist"):
component._library_info("x", read_path, {"build": {"srcDir": "nosrc"}})
def test_library_info_missing_declared_include_dir_warns(
tmp_path: Path, caplog: pytest.LogCaptureFixture
) -> None:
read_path = tmp_path / "lib"
read_path.mkdir()
component._library_info("x", read_path, {"build": {"includeDir": "noinc"}})
assert "include dir noinc which does not exist" in caplog.text
@@ -376,3 +376,29 @@ def test_ccache_env(tmp_path: Path) -> None:
assert env["CCACHE_DEPEND"] == "1"
assert env["CCACHE_BASEDIR"] == str(Path(CORE.build_path).resolve())
assert env["CCACHE_DIR"].endswith("ccache")
def test_install_package_validates_expected_layout(tmp_path: Path) -> None:
"""The success marker is only written when the extracted tree is usable."""
dest = tmp_path / "pkg"
with (
patch.object(framework, "download_from_mirrors"),
patch.object(framework, "archive_extract_all") as mock_extract,
patch.object(framework, "_pio_system", return_value="linux_x86_64"),
):
mock_extract.side_effect = lambda *_a, **_kw: (dest / "bin").mkdir(parents=True)
framework._install_package("pkg", "1.0.0", dest, ["http://m"], expect=("bin",))
assert (dest / ".esphome_extracted").is_file()
def test_install_package_unexpected_layout_raises(tmp_path: Path) -> None:
dest = tmp_path / "pkg"
with (
patch.object(framework, "download_from_mirrors"),
patch.object(framework, "archive_extract_all") as mock_extract,
patch.object(framework, "_pio_system", return_value="linux_x86_64"),
pytest.raises(EsphomeError, match="without the expected bin"),
):
mock_extract.side_effect = lambda *_a, **_kw: dest.mkdir()
framework._install_package("pkg", "1.0.0", dest, ["http://m"], expect=("bin",))
assert not (dest / ".esphome_extracted").exists()