mirror of
https://github.com/esphome/esphome.git
synced 2026-10-05 10:31:29 +00:00
[core] Move comment to PROGMEM on ESP8266
This commit is contained in:
@@ -1357,36 +1357,67 @@ def test_generate_build_info_data_h_format() -> None:
|
||||
config_hash = 0x12345678
|
||||
build_time = 1700000000
|
||||
build_time_str = "2023-11-14 22:13:20 +0000"
|
||||
comment = "Test comment"
|
||||
|
||||
result = generate_build_info_data_h(config_hash, build_time, build_time_str)
|
||||
result = generate_build_info_data_h(
|
||||
config_hash, build_time, build_time_str, comment
|
||||
)
|
||||
|
||||
assert "#pragma once" in result
|
||||
assert "#define ESPHOME_CONFIG_HASH 0x12345678U" in result
|
||||
assert "#define ESPHOME_BUILD_TIME 1700000000" in result
|
||||
assert "#define ESPHOME_COMMENT_SIZE 13" in result # len("Test comment") + 1
|
||||
assert 'ESPHOME_BUILD_TIME_STR[] = "2023-11-14 22:13:20 +0000"' in result
|
||||
assert 'ESPHOME_COMMENT_STR[] = "Test comment"' in result
|
||||
|
||||
|
||||
def test_generate_build_info_data_h_esp8266_progmem() -> None:
|
||||
"""Test generate_build_info_data_h includes PROGMEM for ESP8266."""
|
||||
result = generate_build_info_data_h(0xABCDEF01, 1700000000, "test")
|
||||
result = generate_build_info_data_h(0xABCDEF01, 1700000000, "test", "comment")
|
||||
|
||||
# Should have ESP8266 PROGMEM conditional
|
||||
assert "#ifdef USE_ESP8266" in result
|
||||
assert "#include <pgmspace.h>" in result
|
||||
assert "PROGMEM" in result
|
||||
# Both build time and comment should have PROGMEM versions
|
||||
assert 'ESPHOME_BUILD_TIME_STR[] PROGMEM = "test"' in result
|
||||
assert 'ESPHOME_COMMENT_STR[] PROGMEM = "comment"' in result
|
||||
|
||||
|
||||
def test_generate_build_info_data_h_hash_formatting() -> None:
|
||||
"""Test generate_build_info_data_h formats hash with leading zeros."""
|
||||
# Test with small hash value that needs leading zeros
|
||||
result = generate_build_info_data_h(0x00000001, 0, "test")
|
||||
result = generate_build_info_data_h(0x00000001, 0, "test", "")
|
||||
assert "#define ESPHOME_CONFIG_HASH 0x00000001U" in result
|
||||
|
||||
# Test with larger hash value
|
||||
result = generate_build_info_data_h(0xFFFFFFFF, 0, "test")
|
||||
result = generate_build_info_data_h(0xFFFFFFFF, 0, "test", "")
|
||||
assert "#define ESPHOME_CONFIG_HASH 0xffffffffU" in result
|
||||
|
||||
|
||||
def test_generate_build_info_data_h_comment_escaping() -> None:
|
||||
"""Test generate_build_info_data_h properly escapes special characters in comment."""
|
||||
# Test backslash escaping
|
||||
result = generate_build_info_data_h(0, 0, "test", "backslash\\here")
|
||||
assert 'ESPHOME_COMMENT_STR[] = "backslash\\\\here"' in result
|
||||
|
||||
# Test quote escaping
|
||||
result = generate_build_info_data_h(0, 0, "test", 'has "quotes"')
|
||||
assert 'ESPHOME_COMMENT_STR[] = "has \\"quotes\\""' in result
|
||||
|
||||
# Test newline escaping
|
||||
result = generate_build_info_data_h(0, 0, "test", "line1\nline2")
|
||||
assert 'ESPHOME_COMMENT_STR[] = "line1\\nline2"' in result
|
||||
|
||||
|
||||
def test_generate_build_info_data_h_empty_comment() -> None:
|
||||
"""Test generate_build_info_data_h handles empty comment."""
|
||||
result = generate_build_info_data_h(0, 0, "test", "")
|
||||
|
||||
assert "#define ESPHOME_COMMENT_SIZE 1" in result # Just null terminator
|
||||
assert 'ESPHOME_COMMENT_STR[] = ""' in result
|
||||
|
||||
|
||||
@patch("esphome.writer.CORE")
|
||||
@patch("esphome.writer.iter_components")
|
||||
@patch("esphome.writer.walk_files")
|
||||
@@ -1445,6 +1476,7 @@ def test_copy_src_tree_writes_build_info_files(
|
||||
mock_core.relative_build_path.side_effect = lambda *args: build_path.joinpath(*args)
|
||||
mock_core.defines = []
|
||||
mock_core.config_hash = 0xDEADBEEF
|
||||
mock_core.comment = "Test comment"
|
||||
mock_core.target_platform = "test_platform"
|
||||
mock_core.config = {}
|
||||
mock_iter_components.return_value = [("core", mock_component)]
|
||||
@@ -1466,6 +1498,8 @@ def test_copy_src_tree_writes_build_info_files(
|
||||
assert "#define ESPHOME_CONFIG_HASH 0xdeadbeefU" in build_info_h_content
|
||||
assert "#define ESPHOME_BUILD_TIME" in build_info_h_content
|
||||
assert "ESPHOME_BUILD_TIME_STR" in build_info_h_content
|
||||
assert "#define ESPHOME_COMMENT_SIZE" in build_info_h_content
|
||||
assert "ESPHOME_COMMENT_STR" in build_info_h_content
|
||||
|
||||
# Verify build_info.json was written
|
||||
build_info_json_path = build_path / "build_info.json"
|
||||
@@ -1517,6 +1551,7 @@ def test_copy_src_tree_detects_config_hash_change(
|
||||
mock_core.relative_build_path.side_effect = lambda *args: build_path.joinpath(*args)
|
||||
mock_core.defines = []
|
||||
mock_core.config_hash = 0xDEADBEEF # Different from existing
|
||||
mock_core.comment = ""
|
||||
mock_core.target_platform = "test_platform"
|
||||
mock_core.config = {}
|
||||
mock_iter_components.return_value = []
|
||||
@@ -1578,6 +1613,7 @@ def test_copy_src_tree_detects_version_change(
|
||||
mock_core.relative_build_path.side_effect = lambda *args: build_path.joinpath(*args)
|
||||
mock_core.defines = []
|
||||
mock_core.config_hash = 0xDEADBEEF
|
||||
mock_core.comment = ""
|
||||
mock_core.target_platform = "test_platform"
|
||||
mock_core.config = {}
|
||||
mock_iter_components.return_value = []
|
||||
@@ -1627,6 +1663,7 @@ def test_copy_src_tree_handles_invalid_build_info_json(
|
||||
mock_core.relative_build_path.side_effect = lambda *args: build_path.joinpath(*args)
|
||||
mock_core.defines = []
|
||||
mock_core.config_hash = 0xDEADBEEF
|
||||
mock_core.comment = ""
|
||||
mock_core.target_platform = "test_platform"
|
||||
mock_core.config = {}
|
||||
mock_iter_components.return_value = []
|
||||
@@ -1700,6 +1737,7 @@ def test_copy_src_tree_build_info_timestamp_behavior(
|
||||
mock_core.relative_build_path.side_effect = lambda *args: build_path.joinpath(*args)
|
||||
mock_core.defines = []
|
||||
mock_core.config_hash = 0xDEADBEEF
|
||||
mock_core.comment = ""
|
||||
mock_core.target_platform = "test_platform"
|
||||
mock_core.config = {}
|
||||
mock_iter_components.return_value = [("test", mock_component)]
|
||||
@@ -1794,6 +1832,7 @@ def test_copy_src_tree_detects_removed_source_file(
|
||||
mock_core.relative_build_path.side_effect = lambda *args: build_path.joinpath(*args)
|
||||
mock_core.defines = []
|
||||
mock_core.config_hash = 0xDEADBEEF
|
||||
mock_core.comment = ""
|
||||
mock_core.target_platform = "test_platform"
|
||||
mock_core.config = {}
|
||||
mock_iter_components.return_value = [] # No components = file should be removed
|
||||
@@ -1855,6 +1894,7 @@ def test_copy_src_tree_ignores_removed_generated_file(
|
||||
mock_core.relative_build_path.side_effect = lambda *args: build_path.joinpath(*args)
|
||||
mock_core.defines = []
|
||||
mock_core.config_hash = 0xDEADBEEF
|
||||
mock_core.comment = ""
|
||||
mock_core.target_platform = "test_platform"
|
||||
mock_core.config = {}
|
||||
mock_iter_components.return_value = []
|
||||
|
||||
Reference in New Issue
Block a user