Skip to content

Commit 4e8187c

Browse files
aseembits93Codeflash Bot
authored andcommitted
crosscheck
1 parent 2a83013 commit 4e8187c

File tree

3 files changed

+395
-11
lines changed

3 files changed

+395
-11
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+
"__unit_test_" in str(gen_test_result.file_name)
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: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
import subprocess
99
import time
1010
import uuid
11-
from collections import Counter, defaultdict
11+
from collections import defaultdict
1212
from pathlib import Path
1313
from typing import TYPE_CHECKING
1414

@@ -1401,13 +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 = Counter()
1405-
for gen_test_result in original_code_baseline.behavior_test_results:
1406-
if (
1407-
"__unit_test_" in str(gen_test_result.file_name)
1408-
and gen_test_result.id.test_function_name not in test_functions_to_remove
1409-
):
1410-
map_gen_test_file_to_no_of_tests[gen_test_result.file_name] += 1
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+
)
14111407

14121408
original_runtime_by_test = original_code_baseline.benchmarking_test_results.usable_runtime_data_by_test_case()
14131409
optimized_runtime_by_test = (
@@ -1573,7 +1569,8 @@ def establish_original_code_baseline(
15731569
) -> Result[tuple[OriginalCodeBaseline, list[str]], str]:
15741570
line_profile_results = {"timings": {}, "unit": 0, "str_out": ""}
15751571
# For the original function - run the tests and get the runtime, plus coverage
1576-
assert (test_framework := self.args.test_framework) in {"pytest", "unittest"} # noqa: RUF018
1572+
test_framework = self.args.test_framework
1573+
assert test_framework in {"pytest", "unittest"}
15771574
success = True
15781575

15791576
test_env = self.get_test_env(codeflash_loop_index=0, codeflash_test_iteration=0, codeflash_tracer_disable=1)
@@ -1751,7 +1748,8 @@ def run_optimized_candidate(
17511748
original_helper_code: dict[Path, str],
17521749
file_path_to_helper_classes: dict[Path, set[str]],
17531750
) -> Result[OptimizedCandidateResult, str]:
1754-
assert (test_framework := self.args.test_framework) in {"pytest", "unittest"} # noqa: RUF018
1751+
test_framework = self.args.test_framework
1752+
assert test_framework in {"pytest", "unittest"}
17551753

17561754
with progress_bar("Testing optimization candidate"):
17571755
test_env = self.get_test_env(

0 commit comments

Comments
 (0)