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
5 changes: 3 additions & 2 deletions codeflash/github/PrComment.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,14 @@ class PrComment:
original_async_throughput: Optional[int] = None
best_async_throughput: Optional[int] = None

def to_json(self) -> dict[str, Union[str, int, dict[str, dict[str, int]], list[BenchmarkDetail], None]]:
def to_json(self) -> dict[str, Union[str, int, dict[str, dict[str, int]], list[BenchmarkDetail], list[str], None]]:
report_table = {
test_type.to_name(): result
for test_type, result in self.winning_behavior_test_results.get_test_pass_fail_report_by_type().items()
if test_type.to_name()
}

result: dict[str, Union[str, int, dict[str, dict[str, int]], list[BenchmarkDetail], None]] = {
result: dict[str, Union[str, int, dict[str, dict[str, int]], list[BenchmarkDetail], list[str], None]] = {
"optimization_explanation": self.optimization_explanation,
"best_runtime": humanize_runtime(self.best_runtime),
"original_runtime": humanize_runtime(self.original_runtime),
Expand All @@ -41,6 +41,7 @@ def to_json(self) -> dict[str, Union[str, int, dict[str, dict[str, int]], list[B
"speedup_pct": self.speedup_pct,
"loop_count": self.winning_benchmarking_test_results.number_of_loops(),
"report_table": report_table,
"passed_existing_tests": self.winning_behavior_test_results.get_passed_existing_test_names(),
"benchmark_details": self.benchmark_details if self.benchmark_details else None,
}

Expand Down
18 changes: 18 additions & 0 deletions codeflash/models/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -686,6 +686,24 @@ def get_test_pass_fail_report_by_type(self) -> dict[TestType, dict[str, int]]:
report[test_result.test_type]["failed"] += 1
return report

def get_passed_existing_test_names(self) -> list[str]:
"""Get a list of passed existing unit test names.

Only considers tests from the first loop (loop_index == 1) to avoid duplicates.
Returns test names in the format: module_path::ClassName.test_name or module_path::test_name
"""
passed_tests: list[str] = []
for test_result in self.test_results:
if (
test_result.loop_index == 1
and test_result.did_pass
and test_result.test_type == TestType.EXISTING_UNIT_TEST
):
class_prefix = f"{test_result.id.test_class_name}." if test_result.id.test_class_name else ""
test_name = f"{test_result.id.test_module_path}::{class_prefix}{test_result.id.test_function_name}"
passed_tests.append(test_name)
return passed_tests

@staticmethod
def report_to_string(report: dict[TestType, dict[str, int]]) -> str:
return " ".join(
Expand Down
Loading