Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
54 changes: 42 additions & 12 deletions codeflash/models/models.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from __future__ import annotations

from collections import Counter, defaultdict
from functools import lru_cache
from typing import TYPE_CHECKING

import libcst as cst
Expand Down Expand Up @@ -372,22 +373,51 @@ def add(self, test_file: TestFile) -> None:
raise ValueError(msg)

def get_by_original_file_path(self, file_path: Path) -> TestFile | None:
return next((test_file for test_file in self.test_files if test_file.original_file_path == file_path), None)
normalized = self._normalize_path_for_comparison(file_path)
for test_file in self.test_files:
if test_file.original_file_path is None:
continue
normalized_test_path = self._normalize_path_for_comparison(test_file.original_file_path)
if normalized == normalized_test_path:
return test_file
return None

def get_test_type_by_instrumented_file_path(self, file_path: Path) -> TestType | None:
return next(
(
test_file.test_type
for test_file in self.test_files
if (file_path in (test_file.instrumented_behavior_file_path, test_file.benchmarking_file_path))
),
None,
)
normalized = self._normalize_path_for_comparison(file_path)
for test_file in self.test_files:
normalized_behavior_path = self._normalize_path_for_comparison(test_file.instrumented_behavior_file_path)
if normalized == normalized_behavior_path:
return test_file.test_type
if test_file.benchmarking_file_path is not None:
normalized_benchmark_path = self._normalize_path_for_comparison(test_file.benchmarking_file_path)
if normalized == normalized_benchmark_path:
return test_file.test_type
return None

def get_test_type_by_original_file_path(self, file_path: Path) -> TestType | None:
return next(
(test_file.test_type for test_file in self.test_files if test_file.original_file_path == file_path), None
)
normalized = self._normalize_path_for_comparison(file_path)
for test_file in self.test_files:
if test_file.original_file_path is None:
continue
normalized_test_path = self._normalize_path_for_comparison(test_file.original_file_path)
if normalized == normalized_test_path:
return test_file.test_type
return None

@staticmethod
@lru_cache(maxsize=4096)
def _normalize_path_for_comparison(path: Path) -> str:
"""Normalize a path for cross-platform comparison.

Resolves the path to an absolute path and handles Windows case-insensitivity.
"""
try:
resolved = str(path.resolve())
except (OSError, RuntimeError):
# If resolve fails (e.g., file doesn't exist), use absolute path
resolved = str(path.absolute())
# Only lowercase on Windows where filesystem is case-insensitive
return resolved.lower() if sys.platform == "win32" else resolved

def __iter__(self) -> Iterator[TestFile]:
return iter(self.test_files)
Expand Down
9 changes: 8 additions & 1 deletion codeflash/verification/parse_test_output.py
Original file line number Diff line number Diff line change
Expand Up @@ -316,7 +316,14 @@ def parse_test_xml(
logger.warning(f"Could not find the test for file name - {test_file_path} ")
continue
test_type = test_files.get_test_type_by_instrumented_file_path(test_file_path)
assert test_type is not None, f"Test type not found for {test_file_path}"
if test_type is None:
# Log registered paths for debugging
registered_paths = [str(tf.instrumented_behavior_file_path) for tf in test_files.test_files]
logger.warning(
f"Test type not found for '{test_file_path}'. "
f"Registered test files: {registered_paths}. Skipping test case."
)
continue
test_module_path = module_name_from_file_path(test_file_path, test_config.tests_project_rootdir)
result = testcase.is_passed # TODO: See for the cases of ERROR and SKIPPED
test_class = None
Expand Down
Loading