From 623cdac689517fa771898ceb09f902fe1ec5caf5 Mon Sep 17 00:00:00 2001 From: Javier Peletier Date: Wed, 3 Dec 2025 18:36:35 +0100 Subject: [PATCH] [tests] Add testing of command line substitutions (#12210) Co-authored-by: J. Nick Koston Co-authored-by: Jonathan Swoboda <154711427+swoboda1337@users.noreply.github.com> --- .../fixtures/substitutions/00-simple_var.approved.yaml | 4 ++++ .../fixtures/substitutions/00-simple_var.input.yaml | 9 +++++++++ tests/unit_tests/test_substitutions.py | 4 +++- 3 files changed, 16 insertions(+), 1 deletion(-) diff --git a/tests/unit_tests/fixtures/substitutions/00-simple_var.approved.yaml b/tests/unit_tests/fixtures/substitutions/00-simple_var.approved.yaml index 6f3bae1ac..9ed9b99c4 100644 --- a/tests/unit_tests/fixtures/substitutions/00-simple_var.approved.yaml +++ b/tests/unit_tests/fixtures/substitutions/00-simple_var.approved.yaml @@ -8,6 +8,8 @@ substitutions: position: x: 79 y: 82 + a: 15 + b: 20 esphome: name: test @@ -34,3 +36,5 @@ test_list: - '{{{"AA"}}}' - '"HELLO"' - '{ 79, 82 }' + - a: 15 should be 15, overridden from command line + b: 20 should stay as 20, not overridden diff --git a/tests/unit_tests/fixtures/substitutions/00-simple_var.input.yaml b/tests/unit_tests/fixtures/substitutions/00-simple_var.input.yaml index 306119b75..64701c03d 100644 --- a/tests/unit_tests/fixtures/substitutions/00-simple_var.input.yaml +++ b/tests/unit_tests/fixtures/substitutions/00-simple_var.input.yaml @@ -11,6 +11,13 @@ substitutions: position: x: 79 y: 82 + a: 10 + b: 20 + +# The following key is only used by the test framework +# to simulate command line substitutions +command_line_substitutions: + a: 15 test_list: - "$var1" @@ -35,3 +42,5 @@ test_list: - ${ '{{{"AA"}}}' } - ${ '"HELLO"' } - '{ ${position.x}, ${position.y} }' + - a: ${a} should be 15, overridden from command line + b: ${b} should stay as 20, not overridden diff --git a/tests/unit_tests/test_substitutions.py b/tests/unit_tests/test_substitutions.py index eb9ef5443..cba1e398c 100644 --- a/tests/unit_tests/test_substitutions.py +++ b/tests/unit_tests/test_substitutions.py @@ -138,9 +138,11 @@ def test_substitutions_fixtures( # Load using ESPHome's YAML loader config = yaml_util.load_yaml(source_path) + command_line_substitutions = config.pop("command_line_substitutions", None) + config = do_packages_pass(config) - substitutions.do_substitution_pass(config, None) + substitutions.do_substitution_pass(config, command_line_substitutions) resolve_extend_remove(config) verify_database_result = verify_database(config)