1
0
mirror of https://github.com/esphome/esphome.git synced 2025-10-21 19:23:45 +01:00
This commit is contained in:
J. Nick Koston
2025-10-17 15:22:06 -10:00
parent daa03e5b3c
commit 3bc0041b94

View File

@@ -82,13 +82,14 @@ def show_disk_space_if_ci(esphome_command: str) -> None:
def find_component_tests( def find_component_tests(
components_dir: Path, component_pattern: str = "*" components_dir: Path, component_pattern: str = "*", base_only: bool = False
) -> dict[str, list[Path]]: ) -> dict[str, list[Path]]:
"""Find all component test files. """Find all component test files.
Args: Args:
components_dir: Path to tests/components directory components_dir: Path to tests/components directory
component_pattern: Glob pattern for component names component_pattern: Glob pattern for component names
base_only: If True, only find base test files (test.*.yaml), not variant files (test-*.yaml)
Returns: Returns:
Dictionary mapping component name to list of test files Dictionary mapping component name to list of test files
@@ -99,8 +100,9 @@ def find_component_tests(
if not comp_dir.is_dir(): if not comp_dir.is_dir():
continue continue
# Find test files matching test.*.yaml or test-*.yaml patterns # Find test files - either base only (test.*.yaml) or all (test[.-]*.yaml)
for test_file in comp_dir.glob("test[.-]*.yaml"): pattern = "test.*.yaml" if base_only else "test[.-]*.yaml"
for test_file in comp_dir.glob(pattern):
component_tests[comp_dir.name].append(test_file) component_tests[comp_dir.name].append(test_file)
return dict(component_tests) return dict(component_tests)
@@ -931,6 +933,7 @@ def test_components(
continue_on_fail: bool, continue_on_fail: bool,
enable_grouping: bool = True, enable_grouping: bool = True,
isolated_components: set[str] | None = None, isolated_components: set[str] | None = None,
base_only: bool = False,
) -> int: ) -> int:
"""Test components with optional intelligent grouping. """Test components with optional intelligent grouping.
@@ -944,6 +947,7 @@ def test_components(
These are tested WITHOUT --testing-mode to enable full validation These are tested WITHOUT --testing-mode to enable full validation
(pin conflicts, etc). This is used in CI for directly changed components (pin conflicts, etc). This is used in CI for directly changed components
to catch issues that would be missed with --testing-mode. to catch issues that would be missed with --testing-mode.
base_only: If True, only test base test files (test.*.yaml), not variant files (test-*.yaml)
Returns: Returns:
Exit code (0 for success, 1 for failure) Exit code (0 for success, 1 for failure)
@@ -961,7 +965,7 @@ def test_components(
# Find all component tests # Find all component tests
all_tests = {} all_tests = {}
for pattern in component_patterns: for pattern in component_patterns:
all_tests.update(find_component_tests(tests_dir, pattern)) all_tests.update(find_component_tests(tests_dir, pattern, base_only))
if not all_tests: if not all_tests:
print(f"No components found matching: {component_patterns}") print(f"No components found matching: {component_patterns}")
@@ -1122,6 +1126,11 @@ def main() -> int:
"These are tested WITHOUT --testing-mode to enable full validation. " "These are tested WITHOUT --testing-mode to enable full validation. "
"Used in CI for directly changed components to catch pin conflicts and other issues.", "Used in CI for directly changed components to catch pin conflicts and other issues.",
) )
parser.add_argument(
"--base-only",
action="store_true",
help="Only test base test files (test.*.yaml), not variant files (test-*.yaml)",
)
args = parser.parse_args() args = parser.parse_args()
@@ -1140,6 +1149,7 @@ def main() -> int:
continue_on_fail=args.continue_on_fail, continue_on_fail=args.continue_on_fail,
enable_grouping=not args.no_grouping, enable_grouping=not args.no_grouping,
isolated_components=isolated_components, isolated_components=isolated_components,
base_only=args.base_only,
) )