1
0
mirror of https://github.com/esphome/esphome.git synced 2026-02-08 00:31:58 +00:00

Add build info to image (#12425)

Co-authored-by: J. Nick Koston <nick+github@koston.org>
Co-authored-by: J. Nick Koston <nick@home-assistant.io>
Co-authored-by: J. Nick Koston <nick@koston.org>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
This commit is contained in:
David Woodhouse
2025-12-18 00:06:52 +00:00
committed by GitHub
parent 2b337aa306
commit 9de7df7b5b
27 changed files with 1458 additions and 53 deletions

View File

@@ -892,3 +892,74 @@ async def test_add_includes_overwrites_existing_files(
mock_copy_file_if_changed.assert_called_once_with(
include_file, CORE.build_path / "src" / "header.h"
)
def test_config_hash_returns_int() -> None:
"""Test that config_hash returns an integer."""
CORE.reset()
CORE.config = {"esphome": {"name": "test"}}
assert isinstance(CORE.config_hash, int)
def test_config_hash_is_cached() -> None:
"""Test that config_hash is computed once and cached."""
CORE.reset()
CORE.config = {"esphome": {"name": "test"}}
# First access computes the hash
hash1 = CORE.config_hash
# Modify config (without resetting cache)
CORE.config = {"esphome": {"name": "different"}}
# Second access returns cached value
hash2 = CORE.config_hash
assert hash1 == hash2
def test_config_hash_reset_clears_cache() -> None:
"""Test that reset() clears the cached config_hash."""
CORE.reset()
CORE.config = {"esphome": {"name": "test"}}
hash1 = CORE.config_hash
# Reset clears the cache
CORE.reset()
CORE.config = {"esphome": {"name": "different"}}
hash2 = CORE.config_hash
# After reset, hash should be recomputed
assert hash1 != hash2
def test_config_hash_deterministic_key_order() -> None:
"""Test that config_hash is deterministic regardless of key insertion order."""
CORE.reset()
# Create two configs with same content but different key order
config1 = {"z_key": 1, "a_key": 2, "nested": {"z_nested": "z", "a_nested": "a"}}
config2 = {"a_key": 2, "z_key": 1, "nested": {"a_nested": "a", "z_nested": "z"}}
CORE.config = config1
hash1 = CORE.config_hash
CORE.reset()
CORE.config = config2
hash2 = CORE.config_hash
# Hashes should be equal because keys are sorted during serialization
assert hash1 == hash2
def test_config_hash_different_for_different_configs() -> None:
"""Test that different configs produce different hashes."""
CORE.reset()
CORE.config = {"esphome": {"name": "test1"}}
hash1 = CORE.config_hash
CORE.reset()
CORE.config = {"esphome": {"name": "test2"}}
hash2 = CORE.config_hash
assert hash1 != hash2