1
0
mirror of https://github.com/esphome/esphome.git synced 2025-11-16 14:55:50 +00:00

Merge branch 'integration' into memory_api

This commit is contained in:
J. Nick Koston
2025-11-15 10:27:05 -06:00
2 changed files with 10 additions and 19 deletions

View File

@@ -1,5 +1,7 @@
"""Tests for the binary sensor component.""" """Tests for the binary sensor component."""
from esphome.core import CORE
def test_text_is_setup(generate_main): def test_text_is_setup(generate_main):
""" """
@@ -61,7 +63,6 @@ def test_text_config_lamda_is_set(generate_main):
Test if lambda is set for lambda mode (optimized with stateless lambda and deduplication) Test if lambda is set for lambda mode (optimized with stateless lambda and deduplication)
""" """
# Given # Given
from esphome.core import CORE
# When # When
main_cpp = generate_main("tests/component_tests/text/test_text.yaml") main_cpp = generate_main("tests/component_tests/text/test_text.yaml")

View File

@@ -1,20 +1,10 @@
"""Tests for lambda deduplication in cpp_generator.""" """Tests for lambda deduplication in cpp_generator."""
import pytest
from esphome import cpp_generator as cg from esphome import cpp_generator as cg
from esphome.core import CORE from esphome.core import CORE
@pytest.fixture(autouse=True) def test_deduplicate_identical_lambdas() -> None:
def reset_core():
"""Reset CORE.data before each test."""
CORE.reset()
yield
CORE.reset()
def test_deduplicate_identical_lambdas():
"""Test that identical stateless lambdas are deduplicated.""" """Test that identical stateless lambdas are deduplicated."""
# Create two identical lambda expressions # Create two identical lambda expressions
lambda1 = cg.LambdaExpression( lambda1 = cg.LambdaExpression(
@@ -40,7 +30,7 @@ def test_deduplicate_identical_lambdas():
assert func_name1 == "shared_lambda_0" assert func_name1 == "shared_lambda_0"
def test_different_lambdas_not_deduplicated(): def test_different_lambdas_not_deduplicated() -> None:
"""Test that different lambdas get different function names.""" """Test that different lambdas get different function names."""
lambda1 = cg.LambdaExpression( lambda1 = cg.LambdaExpression(
parts=["return 42;"], parts=["return 42;"],
@@ -65,7 +55,7 @@ def test_different_lambdas_not_deduplicated():
assert func_name2 == "shared_lambda_1" assert func_name2 == "shared_lambda_1"
def test_different_return_types_not_deduplicated(): def test_different_return_types_not_deduplicated() -> None:
"""Test that lambdas with different return types are not deduplicated.""" """Test that lambdas with different return types are not deduplicated."""
lambda1 = cg.LambdaExpression( lambda1 = cg.LambdaExpression(
parts=["return 42;"], parts=["return 42;"],
@@ -88,7 +78,7 @@ def test_different_return_types_not_deduplicated():
assert func_name1 != func_name2 assert func_name1 != func_name2
def test_different_parameters_not_deduplicated(): def test_different_parameters_not_deduplicated() -> None:
"""Test that lambdas with different parameters are not deduplicated.""" """Test that lambdas with different parameters are not deduplicated."""
lambda1 = cg.LambdaExpression( lambda1 = cg.LambdaExpression(
parts=["return x;"], parts=["return x;"],
@@ -111,7 +101,7 @@ def test_different_parameters_not_deduplicated():
assert func_name1 != func_name2 assert func_name1 != func_name2
def test_flush_lambda_dedup_declarations(): def test_flush_lambda_dedup_declarations() -> None:
"""Test that deferred declarations are properly stored for later flushing.""" """Test that deferred declarations are properly stored for later flushing."""
# Create a lambda which will create a deferred declaration # Create a lambda which will create a deferred declaration
lambda1 = cg.LambdaExpression( lambda1 = cg.LambdaExpression(
@@ -136,7 +126,7 @@ def test_flush_lambda_dedup_declarations():
# during real code generation, so we don't test that here # during real code generation, so we don't test that here
def test_shared_function_lambda_expression(): def test_shared_function_lambda_expression() -> None:
"""Test SharedFunctionLambdaExpression behaves correctly.""" """Test SharedFunctionLambdaExpression behaves correctly."""
shared_lambda = cg.SharedFunctionLambdaExpression( shared_lambda = cg.SharedFunctionLambdaExpression(
func_name="shared_lambda_0", func_name="shared_lambda_0",
@@ -154,7 +144,7 @@ def test_shared_function_lambda_expression():
assert shared_lambda.content == "" assert shared_lambda.content == ""
def test_lambda_deduplication_counter(): def test_lambda_deduplication_counter() -> None:
"""Test that lambda counter increments correctly.""" """Test that lambda counter increments correctly."""
# Create 3 different lambdas # Create 3 different lambdas
for i in range(3): for i in range(3):
@@ -168,7 +158,7 @@ def test_lambda_deduplication_counter():
assert func_name == f"shared_lambda_{i}" assert func_name == f"shared_lambda_{i}"
def test_lambda_format_body(): def test_lambda_format_body() -> None:
"""Test that format_body correctly formats lambda body with source.""" """Test that format_body correctly formats lambda body with source."""
# Without source # Without source
lambda1 = cg.LambdaExpression( lambda1 = cg.LambdaExpression(