mirror of
https://github.com/esphome/esphome.git
synced 2025-10-12 23:03:46 +01:00
fix
This commit is contained in:
@@ -284,50 +284,35 @@ def run_grouped_test(
|
||||
return False
|
||||
|
||||
|
||||
def test_components(
|
||||
component_patterns: list[str],
|
||||
def run_grouped_component_tests(
|
||||
all_tests: dict[str, list[Path]],
|
||||
platform_filter: str | None,
|
||||
platform_bases: dict[str, list[Path]],
|
||||
tests_dir: Path,
|
||||
build_dir: Path,
|
||||
esphome_command: str,
|
||||
continue_on_fail: bool,
|
||||
enable_grouping: bool = True,
|
||||
) -> int:
|
||||
"""Test components with optional intelligent grouping.
|
||||
) -> tuple[set[tuple[str, str]], list[str], list[str]]:
|
||||
"""Run grouped component tests.
|
||||
|
||||
Args:
|
||||
component_patterns: List of component name patterns
|
||||
all_tests: Dictionary mapping component names to test files
|
||||
platform_filter: Optional platform to filter by
|
||||
platform_bases: Platform base files mapping
|
||||
tests_dir: Path to tests/components directory
|
||||
build_dir: Path to build directory
|
||||
esphome_command: ESPHome command (config/compile)
|
||||
continue_on_fail: Whether to continue on failure
|
||||
enable_grouping: Whether to enable component grouping
|
||||
|
||||
Returns:
|
||||
Exit code (0 for success, 1 for failure)
|
||||
Tuple of (tested_components, passed_tests, failed_tests)
|
||||
"""
|
||||
# Setup paths
|
||||
repo_root = Path(__file__).parent.parent
|
||||
tests_dir = repo_root / "tests" / "components"
|
||||
build_components_dir = repo_root / "tests" / "test_build_components"
|
||||
build_dir = build_components_dir / "build"
|
||||
build_dir.mkdir(parents=True, exist_ok=True)
|
||||
|
||||
# Get platform base files
|
||||
platform_bases = get_platform_base_files(build_components_dir)
|
||||
|
||||
# Find all component tests
|
||||
all_tests = {}
|
||||
for pattern in component_patterns:
|
||||
all_tests.update(find_component_tests(tests_dir, pattern))
|
||||
|
||||
if not all_tests:
|
||||
print(f"No components found matching: {component_patterns}")
|
||||
return 1
|
||||
|
||||
print(f"Found {len(all_tests)} components to test")
|
||||
tested_components = set()
|
||||
passed_tests = []
|
||||
failed_tests = []
|
||||
|
||||
# Group components by platform and bus signature
|
||||
grouped_components: dict[tuple[str, str], list[str]] = defaultdict(list)
|
||||
|
||||
if enable_grouping:
|
||||
print("\n" + "=" * 80)
|
||||
print("Analyzing components for intelligent grouping...")
|
||||
print("=" * 80)
|
||||
@@ -395,9 +380,7 @@ def test_components(
|
||||
)
|
||||
|
||||
if individual_tests:
|
||||
print(
|
||||
f"\n○ {len(individual_tests)} components will be tested individually:"
|
||||
)
|
||||
print(f"\n○ {len(individual_tests)} components will be tested individually:")
|
||||
for comp in sorted(individual_tests[:10]):
|
||||
print(f" - {comp}")
|
||||
if len(individual_tests) > 10:
|
||||
@@ -417,13 +400,7 @@ def test_components(
|
||||
)
|
||||
print("=" * 80 + "\n")
|
||||
|
||||
# Run tests
|
||||
failed_tests = []
|
||||
passed_tests = []
|
||||
tested_components = set() # Track which components were tested in groups
|
||||
|
||||
# First, run grouped tests if grouping is enabled
|
||||
if enable_grouping:
|
||||
# Execute grouped tests
|
||||
for (platform, signature), components in grouped_components.items():
|
||||
# Only group if we have multiple components with same signature
|
||||
if len(components) <= 1:
|
||||
@@ -476,6 +453,66 @@ def test_components(
|
||||
else:
|
||||
failed_tests.append(test_id)
|
||||
|
||||
return tested_components, passed_tests, failed_tests
|
||||
|
||||
|
||||
def test_components(
|
||||
component_patterns: list[str],
|
||||
platform_filter: str | None,
|
||||
esphome_command: str,
|
||||
continue_on_fail: bool,
|
||||
enable_grouping: bool = True,
|
||||
) -> int:
|
||||
"""Test components with optional intelligent grouping.
|
||||
|
||||
Args:
|
||||
component_patterns: List of component name patterns
|
||||
platform_filter: Optional platform to filter by
|
||||
esphome_command: ESPHome command (config/compile)
|
||||
continue_on_fail: Whether to continue on failure
|
||||
enable_grouping: Whether to enable component grouping
|
||||
|
||||
Returns:
|
||||
Exit code (0 for success, 1 for failure)
|
||||
"""
|
||||
# Setup paths
|
||||
repo_root = Path(__file__).parent.parent
|
||||
tests_dir = repo_root / "tests" / "components"
|
||||
build_components_dir = repo_root / "tests" / "test_build_components"
|
||||
build_dir = build_components_dir / "build"
|
||||
build_dir.mkdir(parents=True, exist_ok=True)
|
||||
|
||||
# Get platform base files
|
||||
platform_bases = get_platform_base_files(build_components_dir)
|
||||
|
||||
# Find all component tests
|
||||
all_tests = {}
|
||||
for pattern in component_patterns:
|
||||
all_tests.update(find_component_tests(tests_dir, pattern))
|
||||
|
||||
if not all_tests:
|
||||
print(f"No components found matching: {component_patterns}")
|
||||
return 1
|
||||
|
||||
print(f"Found {len(all_tests)} components to test")
|
||||
|
||||
# Run tests
|
||||
failed_tests = []
|
||||
passed_tests = []
|
||||
tested_components = set() # Track which components were tested in groups
|
||||
|
||||
# First, run grouped tests if grouping is enabled
|
||||
if enable_grouping:
|
||||
tested_components, passed_tests, failed_tests = run_grouped_component_tests(
|
||||
all_tests=all_tests,
|
||||
platform_filter=platform_filter,
|
||||
platform_bases=platform_bases,
|
||||
tests_dir=tests_dir,
|
||||
build_dir=build_dir,
|
||||
esphome_command=esphome_command,
|
||||
continue_on_fail=continue_on_fail,
|
||||
)
|
||||
|
||||
# Then run individual tests for components not in groups
|
||||
for component, test_files in sorted(all_tests.items()):
|
||||
for test_file in test_files:
|
||||
|
Reference in New Issue
Block a user