mirror of
https://github.com/esphome/esphome.git
synced 2026-10-07 11:26:39 +00:00
Fix test_build_components crash with top-level !include test files
The IncludeFile representer added in #15549 defers !include resolution, but the component test scripts assumed load_yaml always returns a dict. Test files using top-level !include (e.g. usb_uart) caused a TypeError: 'argument of type IncludeFile is not iterable'. Resolve IncludeFile objects by calling .load() before processing.
This commit is contained in:
@@ -221,6 +221,9 @@ def analyze_yaml_file(yaml_file: Path) -> dict[str, Any]:
|
|||||||
|
|
||||||
try:
|
try:
|
||||||
data = yaml_util.load_yaml(yaml_file)
|
data = yaml_util.load_yaml(yaml_file)
|
||||||
|
# Top-level !include returns an IncludeFile that must be resolved
|
||||||
|
if isinstance(data, yaml_util.IncludeFile):
|
||||||
|
data = data.load()
|
||||||
result["loaded"] = True
|
result["loaded"] = True
|
||||||
except Exception: # pylint: disable=broad-exception-caught
|
except Exception: # pylint: disable=broad-exception-caught
|
||||||
return result
|
return result
|
||||||
|
|||||||
@@ -27,6 +27,7 @@ sys.path.insert(0, str(Path(__file__).parent.parent))
|
|||||||
|
|
||||||
from esphome import yaml_util
|
from esphome import yaml_util
|
||||||
from esphome.config_helpers import merge_config
|
from esphome.config_helpers import merge_config
|
||||||
|
from esphome.yaml_util import IncludeFile
|
||||||
from script.analyze_component_buses import PACKAGE_DEPENDENCIES, get_common_bus_packages
|
from script.analyze_component_buses import PACKAGE_DEPENDENCIES, get_common_bus_packages
|
||||||
|
|
||||||
# Prefix for dependency markers in package tracking
|
# Prefix for dependency markers in package tracking
|
||||||
@@ -46,7 +47,12 @@ def load_yaml_file(yaml_file: Path) -> dict:
|
|||||||
if not yaml_file.exists():
|
if not yaml_file.exists():
|
||||||
raise FileNotFoundError(f"YAML file not found: {yaml_file}")
|
raise FileNotFoundError(f"YAML file not found: {yaml_file}")
|
||||||
|
|
||||||
return yaml_util.load_yaml(yaml_file)
|
data = yaml_util.load_yaml(yaml_file)
|
||||||
|
# Top-level !include (e.g., `!include common.yaml`) returns an IncludeFile
|
||||||
|
# that must be resolved before we can work with it as a dict.
|
||||||
|
if isinstance(data, IncludeFile):
|
||||||
|
data = data.load()
|
||||||
|
return data
|
||||||
|
|
||||||
|
|
||||||
@lru_cache(maxsize=256)
|
@lru_cache(maxsize=256)
|
||||||
|
|||||||
Reference in New Issue
Block a user