Update script/helpers.py to use ESPHome YAML parser for integration fixtures (#9544)

This commit is contained in:
J. Nick Koston 2025-07-16 00:19:27 -10:00 committed by GitHub
parent d0b45f7cb6
commit 9e621a1769
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 15 additions and 17 deletions

View File

@ -530,27 +530,26 @@ def get_components_from_integration_fixtures() -> set[str]:
Returns: Returns:
Set of component names used in integration test fixtures Set of component names used in integration test fixtures
""" """
import yaml from esphome import yaml_util
components: set[str] = set() components: set[str] = set()
fixtures_dir = Path(__file__).parent.parent / "tests" / "integration" / "fixtures" fixtures_dir = Path(__file__).parent.parent / "tests" / "integration" / "fixtures"
for yaml_file in fixtures_dir.glob("*.yaml"): for yaml_file in fixtures_dir.glob("*.yaml"):
with open(yaml_file) as f: config: dict[str, any] | None = yaml_util.load_yaml(str(yaml_file))
config: dict[str, any] | None = yaml.safe_load(f) if not config:
if not config: continue
# Add all top-level component keys
components.update(config.keys())
# Add platform components (e.g., output.template)
for value in config.values():
if not isinstance(value, list):
continue continue
# Add all top-level component keys for item in value:
components.update(config.keys()) if isinstance(item, dict) and "platform" in item:
components.add(item["platform"])
# Add platform components (e.g., output.template)
for value in config.values():
if not isinstance(value, list):
continue
for item in value:
if isinstance(item, dict) and "platform" in item:
components.add(item["platform"])
return components return components

View File

@ -986,8 +986,7 @@ def test_get_components_from_integration_fixtures() -> None:
with ( with (
patch("pathlib.Path.glob") as mock_glob, patch("pathlib.Path.glob") as mock_glob,
patch("builtins.open", create=True), patch("esphome.yaml_util.load_yaml", return_value=yaml_content),
patch("yaml.safe_load", return_value=yaml_content),
): ):
mock_glob.return_value = [mock_yaml_file] mock_glob.return_value = [mock_yaml_file]