mirror of
https://github.com/esphome/esphome.git
synced 2026-10-06 10:56:43 +00:00
[espidf] Read the ESP-IDF version in process instead of starting idf_tools (#19998)
This commit is contained in:
@@ -16,7 +16,7 @@ import check_idf_py_equivalence as guard # noqa: E402
|
||||
|
||||
from esphome.build_gen import espidf as build_gen # noqa: E402
|
||||
from esphome.core import CORE # noqa: E402
|
||||
from esphome.espidf import toolchain # noqa: E402
|
||||
from esphome.espidf import framework, toolchain # noqa: E402
|
||||
|
||||
|
||||
@pytest.fixture(autouse=True)
|
||||
@@ -74,10 +74,12 @@ def _run_check(
|
||||
esphome_rcs: tuple[int, int] = (0, 0),
|
||||
macro_matches: bool = True,
|
||||
envs: list[dict[str, str]] | None = None,
|
||||
versions: tuple[str | None, str | None, str] = ("5.5", "5.5", "5.5"),
|
||||
) -> tuple[list[str], list[list[str]]]:
|
||||
"""Run check() with idf.py replaced by ``side_effect``; return problems, calls.
|
||||
|
||||
``envs`` collects the env each idf.py call receives.
|
||||
``envs`` collects the env each idf.py call receives. ``versions`` is what
|
||||
version.txt, the version header and idf_tools report for the framework.
|
||||
"""
|
||||
calls: list[list[str]] = []
|
||||
|
||||
@@ -98,6 +100,9 @@ def _run_check(
|
||||
patch.object(toolchain, "run_reconfigure", return_value=esphome_rcs[0]),
|
||||
patch.object(toolchain, "_run_ninja", return_value=esphome_rcs[1]),
|
||||
patch.object(build_gen, "idf_macro_matches", return_value=macro_matches),
|
||||
patch.object(framework, "read_idf_version_txt", return_value=versions[0]),
|
||||
patch.object(framework, "read_idf_version_header", return_value=versions[1]),
|
||||
patch.object(framework, "idf_tools_version", return_value=versions[2]),
|
||||
patch.object(guard.subprocess, "run", side_effect=run),
|
||||
patch.dict(os.environ),
|
||||
):
|
||||
@@ -285,6 +290,24 @@ def test_check_fails_loudly_when_the_idf_macro_changed(tmp_path: Path) -> None:
|
||||
assert calls == []
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
("versions", "source"),
|
||||
[(("5.4", "5.5", "5.5"), "txt"), (("5.5", None, "5.5"), "header")],
|
||||
)
|
||||
def test_check_fails_loudly_when_the_version_read_drifts(
|
||||
tmp_path: Path, versions: tuple[str | None, str | None, str], source: str
|
||||
) -> None:
|
||||
"""An IDF bump that changes how idf_tools reads its version must fail CI;
|
||||
both sources are checked since a managed tree never reaches the header."""
|
||||
tree = _make_tree(tmp_path)
|
||||
problems, calls = _run_check(tree, versions=versions)
|
||||
ours = versions[0] if source == "txt" else versions[1]
|
||||
assert problems == [
|
||||
guard.VERSION_DRIFT.format(ours=ours, source=source, theirs="5.5")
|
||||
]
|
||||
assert calls == []
|
||||
|
||||
|
||||
def test_main_without_build_trees(
|
||||
tmp_path: Path, capsys: pytest.CaptureFixture[str]
|
||||
) -> None:
|
||||
|
||||
Reference in New Issue
Block a user