Skip to content

Commit 16ff462

Browse files
authored
Merge pull request #900 from codeflash-ai/cf-835
dont display generated file if there are no test functions passing for that file
2 parents 4a6eaab + bb7b2c9 commit 16ff462

File tree

3 files changed

+494
-7
lines changed

3 files changed

+494
-7
lines changed

codeflash/models/models.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
from __future__ import annotations
22

3-
from collections import defaultdict
3+
from collections import Counter, defaultdict
44
from typing import TYPE_CHECKING
55

66
from rich.tree import Tree
@@ -675,6 +675,16 @@ def total_passed_runtime(self) -> int:
675675
[min(usable_runtime_data) for _, usable_runtime_data in self.usable_runtime_data_by_test_case().items()]
676676
)
677677

678+
def file_to_no_of_tests(self, test_functions_to_remove: list[str]) -> Counter[Path]:
679+
map_gen_test_file_to_no_of_tests = Counter()
680+
for gen_test_result in self.test_results:
681+
if (
682+
gen_test_result.test_type == TestType.GENERATED_REGRESSION
683+
and gen_test_result.id.test_function_name not in test_functions_to_remove
684+
):
685+
map_gen_test_file_to_no_of_tests[gen_test_result.file_name] += 1
686+
return map_gen_test_file_to_no_of_tests
687+
678688
def __iter__(self) -> Iterator[FunctionTestInvocation]:
679689
return iter(self.test_results)
680690

codeflash/optimization/function_optimizer.py

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1401,6 +1401,9 @@ def process_review(
14011401
generated_tests = remove_functions_from_generated_tests(
14021402
generated_tests=generated_tests, test_functions_to_remove=test_functions_to_remove
14031403
)
1404+
map_gen_test_file_to_no_of_tests = original_code_baseline.behavior_test_results.file_to_no_of_tests(
1405+
test_functions_to_remove
1406+
)
14041407

14051408
original_runtime_by_test = original_code_baseline.benchmarking_test_results.usable_runtime_data_by_test_case()
14061409
optimized_runtime_by_test = (
@@ -1413,11 +1416,12 @@ def process_review(
14131416

14141417
generated_tests_str = ""
14151418
for test in generated_tests.generated_tests:
1416-
formatted_generated_test = format_generated_code(
1417-
test.generated_original_test_source, self.args.formatter_cmds
1418-
)
1419-
generated_tests_str += f"```python\n{formatted_generated_test}\n```"
1420-
generated_tests_str += "\n\n"
1419+
if map_gen_test_file_to_no_of_tests[test.behavior_file_path] > 0:
1420+
formatted_generated_test = format_generated_code(
1421+
test.generated_original_test_source, self.args.formatter_cmds
1422+
)
1423+
generated_tests_str += f"```python\n{formatted_generated_test}\n```"
1424+
generated_tests_str += "\n\n"
14211425

14221426
if concolic_test_str:
14231427
formatted_generated_test = format_generated_code(concolic_test_str, self.args.formatter_cmds)
@@ -1537,7 +1541,7 @@ def process_review(
15371541
trace_id=self.function_trace_id, is_optimization_found=best_optimization is not None
15381542
)
15391543

1540-
# If worktree mode, do not revert code and helpers,, otherwise we would have an empty diff when writing the patch in the lsp
1544+
# If worktree mode, do not revert code and helpers, otherwise we would have an empty diff when writing the patch in the lsp
15411545
if self.args.worktree:
15421546
return
15431547

0 commit comments

Comments
 (0)