Skip to content
Open
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
41 changes: 38 additions & 3 deletions codeflash/models/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -372,23 +372,58 @@ 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)
return next(
(
test_file
for test_file in self.test_files
if test_file.original_file_path is not None
and normalized == self._normalize_path_for_comparison(test_file.original_file_path)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can refactor self._normalize_path_for_comparison(test_file.original_file_path) out for better readability

),
None,
)

def get_test_type_by_instrumented_file_path(self, file_path: Path) -> TestType | None:
normalized = self._normalize_path_for_comparison(file_path)
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))
if normalized == self._normalize_path_for_comparison(test_file.instrumented_behavior_file_path)
or (
test_file.benchmarking_file_path is not None
and normalized == self._normalize_path_for_comparison(test_file.benchmarking_file_path)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same feedback as previous comment

)
),
None,
)

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

@staticmethod
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