This commit is contained in:
J. Nick Koston
2025-12-29 16:24:10 -10:00
parent c9c0bdb1c6
commit 1472914527
+108
View File
@@ -28,6 +28,7 @@ from esphome.writer import (
generate_build_info_data_h,
get_build_info,
storage_should_clean,
storage_should_update_cmake_cache,
update_storage_json,
write_cpp,
write_gitignore,
@@ -171,6 +172,113 @@ def test_storage_edge_case_from_empty_integrations(
assert storage_should_clean(old, new) is False
# Tests for storage_should_update_cmake_cache
def test_storage_should_update_cmake_cache_when_integration_added_esp32(
create_storage: Callable[..., StorageJSON],
) -> None:
"""Test cmake cache update triggered when integration added on ESP32."""
old = create_storage(
loaded_integrations=["api", "wifi"],
core_platform="esp32",
framework="arduino",
)
new = create_storage(
loaded_integrations=["api", "wifi", "restart"],
core_platform="esp32",
framework="arduino",
)
assert storage_should_update_cmake_cache(old, new) is True
def test_storage_should_update_cmake_cache_when_integration_added_esp32_idf(
create_storage: Callable[..., StorageJSON],
) -> None:
"""Test cmake cache update triggered when integration added on ESP32-IDF."""
old = create_storage(
loaded_integrations=["api", "wifi"],
core_platform="esp32",
framework="esp-idf",
)
new = create_storage(
loaded_integrations=["api", "wifi", "restart"],
core_platform="esp32",
framework="esp-idf",
)
assert storage_should_update_cmake_cache(old, new) is True
def test_storage_should_update_cmake_cache_when_platform_changed_esp32(
create_storage: Callable[..., StorageJSON],
) -> None:
"""Test cmake cache update triggered when platforms change on ESP32."""
old = create_storage(
loaded_integrations=["api", "wifi"],
loaded_platforms={"sensor"},
core_platform="esp32",
framework="arduino",
)
new = create_storage(
loaded_integrations=["api", "wifi"],
loaded_platforms={"sensor", "binary_sensor"},
core_platform="esp32",
framework="arduino",
)
assert storage_should_update_cmake_cache(old, new) is True
def test_storage_should_not_update_cmake_cache_when_nothing_changes(
create_storage: Callable[..., StorageJSON],
) -> None:
"""Test cmake cache not updated when nothing changes."""
old = create_storage(
loaded_integrations=["api", "wifi"],
core_platform="esp32",
framework="arduino",
)
new = create_storage(
loaded_integrations=["api", "wifi"],
core_platform="esp32",
framework="arduino",
)
assert storage_should_update_cmake_cache(old, new) is False
def test_storage_should_not_update_cmake_cache_for_esp8266(
create_storage: Callable[..., StorageJSON],
) -> None:
"""Test cmake cache not updated for ESP8266 (uses different build system)."""
old = create_storage(
loaded_integrations=["api", "wifi"],
core_platform="esp8266",
framework="arduino",
)
new = create_storage(
loaded_integrations=["api", "wifi", "restart"],
core_platform="esp8266",
framework="arduino",
)
assert storage_should_update_cmake_cache(old, new) is False
def test_storage_should_not_update_cmake_cache_for_rp2040(
create_storage: Callable[..., StorageJSON],
) -> None:
"""Test cmake cache not updated for RP2040."""
old = create_storage(
loaded_integrations=["api", "wifi"],
core_platform="rp2040",
framework="arduino",
)
new = create_storage(
loaded_integrations=["api", "wifi", "restart"],
core_platform="rp2040",
framework="arduino",
)
assert storage_should_update_cmake_cache(old, new) is False
@patch("esphome.writer.clean_build")
@patch("esphome.writer.StorageJSON")
@patch("esphome.writer.storage_path")