Skip to content

Commit d7f9bbd

Browse files
committed
update tests again
1 parent 8e516fc commit d7f9bbd

File tree

8 files changed

+75
-72
lines changed

8 files changed

+75
-72
lines changed

codeflash/optimization/function_optimizer.py

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1411,7 +1411,7 @@ def establish_original_code_baseline(
14111411
instrument_codeflash_capture(
14121412
self.function_to_optimize, file_path_to_helper_classes, self.test_cfg.tests_root
14131413
)
1414-
behavioral_results, coverage_results, _ = self.run_and_parse_tests(
1414+
behavioral_results, coverage_results = self.run_and_parse_tests(
14151415
testing_type=TestingMode.BEHAVIOR,
14161416
test_env=test_env,
14171417
test_files=self.test_files,
@@ -1455,7 +1455,7 @@ def establish_original_code_baseline(
14551455
)
14561456

14571457
try:
1458-
benchmarking_results, _, _ = self.run_and_parse_tests(
1458+
benchmarking_results, _ = self.run_and_parse_tests(
14591459
testing_type=TestingMode.PERFORMANCE,
14601460
test_env=test_env,
14611461
test_files=self.test_files,
@@ -1479,7 +1479,7 @@ def establish_original_code_baseline(
14791479
# * 1.5 to give unittest a bit more time to run
14801480
break
14811481
test_env["CODEFLASH_LOOP_INDEX"] = str(i + 1)
1482-
unittest_loop_results, _, _ = self.run_and_parse_tests(
1482+
unittest_loop_results, _ = self.run_and_parse_tests(
14831483
testing_type=TestingMode.PERFORMANCE,
14841484
test_env=test_env,
14851485
test_files=self.test_files,
@@ -1602,7 +1602,7 @@ def run_optimized_candidate(
16021602
instrument_codeflash_capture(
16031603
self.function_to_optimize, file_path_to_helper_classes, self.test_cfg.tests_root
16041604
)
1605-
candidate_behavior_results, _, _ = self.run_and_parse_tests(
1605+
candidate_behavior_results, _ = self.run_and_parse_tests(
16061606
testing_type=TestingMode.BEHAVIOR,
16071607
test_env=test_env,
16081608
test_files=self.test_files,
@@ -1648,7 +1648,7 @@ def run_optimized_candidate(
16481648
)
16491649

16501650
try:
1651-
candidate_benchmarking_results, _, _ = self.run_and_parse_tests(
1651+
candidate_benchmarking_results, _ = self.run_and_parse_tests(
16521652
testing_type=TestingMode.PERFORMANCE,
16531653
test_env=test_env,
16541654
test_files=self.test_files,
@@ -1681,7 +1681,7 @@ def run_optimized_candidate(
16811681
# * 1.5 to give unittest a bit more time to run
16821682
break
16831683
test_env["CODEFLASH_LOOP_INDEX"] = str(i + 1)
1684-
unittest_loop_results, cov, _ = self.run_and_parse_tests(
1684+
unittest_loop_results, cov = self.run_and_parse_tests(
16851685
testing_type=TestingMode.PERFORMANCE,
16861686
test_env=test_env,
16871687
test_files=self.test_files,
@@ -1746,7 +1746,7 @@ def run_and_parse_tests(
17461746
code_context: CodeOptimizationContext | None = None,
17471747
unittest_loop_index: int | None = None,
17481748
line_profiler_output_file: Path | None = None,
1749-
) -> tuple[TestResults | dict, CoverageData | None, TestResults | None]:
1749+
) -> tuple[TestResults | dict, CoverageData | None]:
17501750
coverage_database_file = None
17511751
coverage_config_file = None
17521752
try:
@@ -1792,7 +1792,7 @@ def run_and_parse_tests(
17921792
logger.exception(
17931793
f"Error running tests in {', '.join(str(f) for f in test_files.test_files)}.\nTimeout Error"
17941794
)
1795-
return TestResults(), None, None
1795+
return TestResults(), None
17961796
if run_result.returncode != 0 and testing_type == TestingMode.BEHAVIOR:
17971797
logger.debug(
17981798
f"Nonzero return code {run_result.returncode} when running tests in "
@@ -1820,9 +1820,9 @@ def run_and_parse_tests(
18201820
coverage_database_file=coverage_database_file,
18211821
coverage_config_file=coverage_config_file,
18221822
)
1823-
return results, coverage_results, None
1823+
return results, coverage_results
18241824
results, coverage_results = parse_line_profile_results(line_profiler_output_file=line_profiler_output_file)
1825-
return results, coverage_results, None
1825+
return results, coverage_results
18261826

18271827
def submit_test_generation_tasks(
18281828
self,
@@ -1881,7 +1881,7 @@ def line_profiler_step(
18811881
codeflash_loop_index=0, codeflash_test_iteration=candidate_index, codeflash_tracer_disable=1
18821882
)
18831883
line_profiler_output_file = add_decorator_imports(self.function_to_optimize, code_context)
1884-
line_profile_results, _, _ = self.run_and_parse_tests(
1884+
line_profile_results, _ = self.run_and_parse_tests(
18851885
testing_type=TestingMode.LINE_PROFILE,
18861886
test_env=test_env,
18871887
test_files=self.test_files,

codeflash/result/critic.py

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -75,18 +75,21 @@ def speedup_critic(
7575

7676
# Async throughput evaluation (if throughput data is available)
7777
throughput_improved = True # Default to True if no throughput data
78-
throughput_is_best = True # Default to True if no throughput data
78+
throughput_is_best = True # Default to True if no throughput data
7979

8080
if original_async_throughput is not None and candidate_result.async_throughput is not None:
8181
if original_async_throughput > 0: # Avoid division by zero
8282
throughput_gain_value = throughput_gain(
83-
original_throughput=original_async_throughput,
84-
optimized_throughput=candidate_result.async_throughput
83+
original_throughput=original_async_throughput, optimized_throughput=candidate_result.async_throughput
8584
)
8685
throughput_improved = throughput_gain_value > MIN_THROUGHPUT_IMPROVEMENT_THRESHOLD
87-
logger.debug(f"Async throughput gain: {throughput_gain_value * 100:.1f}% (original: {original_async_throughput}, optimized: {candidate_result.async_throughput})")
86+
logger.debug(
87+
f"Async throughput gain: {throughput_gain_value * 100:.1f}% (original: {original_async_throughput}, optimized: {candidate_result.async_throughput})"
88+
)
8889

89-
throughput_is_best = best_throughput_until_now is None or candidate_result.async_throughput > best_throughput_until_now
90+
throughput_is_best = (
91+
best_throughput_until_now is None or candidate_result.async_throughput > best_throughput_until_now
92+
)
9093

9194
# For async functions with throughput data, both runtime and throughput should improve
9295
# For sync functions or when throughput data is unavailable, only runtime matters

tests/test_async_run_and_parse_tests.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ async def test_async_sort():
9292
]
9393
)
9494

95-
test_results, coverage_data, _ = func_optimizer.run_and_parse_tests(
95+
test_results, coverage_data = func_optimizer.run_and_parse_tests(
9696
testing_type=TestingMode.BEHAVIOR,
9797
test_env=test_env,
9898
test_files=func_optimizer.test_files,
@@ -211,7 +211,7 @@ async def test_async_class_sort():
211211
]
212212
)
213213

214-
test_results, coverage_data, _ = func_optimizer.run_and_parse_tests(
214+
test_results, coverage_data = func_optimizer.run_and_parse_tests(
215215
testing_type=TestingMode.BEHAVIOR,
216216
test_env=test_env,
217217
test_files=func_optimizer.test_files,
@@ -320,7 +320,7 @@ async def test_async_perf():
320320
]
321321
)
322322

323-
test_results, coverage_data, _ = func_optimizer.run_and_parse_tests(
323+
test_results, coverage_data = func_optimizer.run_and_parse_tests(
324324
testing_type=TestingMode.PERFORMANCE,
325325
test_env=test_env,
326326
test_files=func_optimizer.test_files,
@@ -473,7 +473,7 @@ async def async_error_function(lst):
473473
]
474474
)
475475

476-
test_results, _, _ = func_optimizer.run_and_parse_tests(
476+
test_results, _ = func_optimizer.run_and_parse_tests(
477477
testing_type=TestingMode.BEHAVIOR,
478478
test_env=test_env,
479479
test_files=func_optimizer.test_files,
@@ -567,7 +567,7 @@ async def test_async_multi():
567567
]
568568
)
569569

570-
test_results, _, _ = func_optimizer.run_and_parse_tests(
570+
test_results, _ = func_optimizer.run_and_parse_tests(
571571
testing_type=TestingMode.BEHAVIOR,
572572
test_env=test_env,
573573
test_files=func_optimizer.test_files,
@@ -678,7 +678,7 @@ async def test_async_edge_cases():
678678
]
679679
)
680680

681-
test_results, _, _ = func_optimizer.run_and_parse_tests(
681+
test_results, _ = func_optimizer.run_and_parse_tests(
682682
testing_type=TestingMode.BEHAVIOR,
683683
test_env=test_env,
684684
test_files=func_optimizer.test_files,
@@ -810,7 +810,7 @@ def test_sync_sort():
810810
]
811811
)
812812

813-
test_results, _, _ = func_optimizer.run_and_parse_tests(
813+
test_results, _ = func_optimizer.run_and_parse_tests(
814814
testing_type=TestingMode.BEHAVIOR,
815815
test_env=test_env,
816816
test_files=func_optimizer.test_files,
@@ -976,7 +976,7 @@ async def test_mixed_sorting():
976976
]
977977
)
978978

979-
test_results, _, _ = func_optimizer.run_and_parse_tests(
979+
test_results, _ = func_optimizer.run_and_parse_tests(
980980
testing_type=TestingMode.BEHAVIOR,
981981
test_env=test_env,
982982
test_files=func_optimizer.test_files,

tests/test_codeflash_capture.py

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -459,7 +459,7 @@ def __init__(self, x=2):
459459
)
460460
]
461461
)
462-
test_results, coverage_data, _ = func_optimizer.run_and_parse_tests(
462+
test_results, coverage_data = func_optimizer.run_and_parse_tests(
463463
testing_type=TestingMode.BEHAVIOR,
464464
test_env=test_env,
465465
test_files=func_optimizer.test_files,
@@ -492,7 +492,7 @@ def __init__(self, x=2):
492492
assert test_results[2].id.function_getting_tested == "some_function"
493493
assert test_results[2].id.iteration_id == "16_0"
494494

495-
test_results2, _, _ = func_optimizer.run_and_parse_tests(
495+
test_results2, _ = func_optimizer.run_and_parse_tests(
496496
testing_type=TestingMode.BEHAVIOR,
497497
test_env=test_env,
498498
test_files=func_optimizer.test_files,
@@ -580,7 +580,7 @@ def __init__(self, *args, **kwargs):
580580
)
581581
]
582582
)
583-
test_results, coverage_data, _ = func_optimizer.run_and_parse_tests(
583+
test_results, coverage_data = func_optimizer.run_and_parse_tests(
584584
testing_type=TestingMode.BEHAVIOR,
585585
test_env=test_env,
586586
test_files=func_optimizer.test_files,
@@ -614,7 +614,7 @@ def __init__(self, *args, **kwargs):
614614
assert test_results[2].id.function_getting_tested == "some_function"
615615
assert test_results[2].id.iteration_id == "16_0"
616616

617-
results2, _, _ = func_optimizer.run_and_parse_tests(
617+
results2, _ = func_optimizer.run_and_parse_tests(
618618
testing_type=TestingMode.BEHAVIOR,
619619
test_env=test_env,
620620
test_files=func_optimizer.test_files,
@@ -705,7 +705,7 @@ def __init__(self, x=2):
705705
)
706706
]
707707
)
708-
test_results, coverage_data, _ = func_optimizer.run_and_parse_tests(
708+
test_results, coverage_data = func_optimizer.run_and_parse_tests(
709709
testing_type=TestingMode.BEHAVIOR,
710710
test_env=test_env,
711711
test_files=func_optimizer.test_files,
@@ -741,7 +741,7 @@ def __init__(self, x=2):
741741
assert test_results[2].id.function_getting_tested == "some_function"
742742
assert test_results[2].id.iteration_id == "12_2" # Third call
743743

744-
test_results2, _, _ = func_optimizer.run_and_parse_tests(
744+
test_results2, _ = func_optimizer.run_and_parse_tests(
745745
testing_type=TestingMode.BEHAVIOR,
746746
test_env=test_env,
747747
test_files=func_optimizer.test_files,
@@ -867,7 +867,7 @@ def another_helper(self):
867867
]
868868
)
869869

870-
test_results, coverage_data, _ = func_optimizer.run_and_parse_tests(
870+
test_results, coverage_data = func_optimizer.run_and_parse_tests(
871871
testing_type=TestingMode.BEHAVIOR,
872872
test_env=test_env,
873873
test_files=func_optimizer.test_files,
@@ -888,7 +888,7 @@ def another_helper(self):
888888
assert test_results[3].id.function_getting_tested == "AnotherHelperClass.__init__"
889889
assert test_results[3].verification_type == VerificationType.INIT_STATE_HELPER
890890

891-
results2, _, _ = func_optimizer.run_and_parse_tests(
891+
results2, _ = func_optimizer.run_and_parse_tests(
892892
testing_type=TestingMode.BEHAVIOR,
893893
test_env=test_env,
894894
test_files=func_optimizer.test_files,
@@ -1026,7 +1026,7 @@ def another_helper(self):
10261026
}
10271027
instrument_codeflash_capture(fto, file_path_to_helper_classes, tests_root)
10281028

1029-
test_results, coverage_data, _ = func_optimizer.run_and_parse_tests(
1029+
test_results, coverage_data = func_optimizer.run_and_parse_tests(
10301030
testing_type=TestingMode.BEHAVIOR,
10311031
test_env=test_env,
10321032
test_files=func_optimizer.test_files,
@@ -1078,7 +1078,7 @@ def target_function(self):
10781078
Path(helper_path_2): {"HelperClass2", "AnotherHelperClass"},
10791079
}
10801080
instrument_codeflash_capture(fto, file_path_to_helper_classes, tests_root)
1081-
modified_test_results, coverage_data, _ = func_optimizer.run_and_parse_tests(
1081+
modified_test_results, coverage_data = func_optimizer.run_and_parse_tests(
10821082
testing_type=TestingMode.BEHAVIOR,
10831083
test_env=test_env,
10841084
test_files=func_optimizer.test_files,
@@ -1117,7 +1117,7 @@ def target_function(self):
11171117
Path(helper_path_2): {"HelperClass2", "AnotherHelperClass"},
11181118
}
11191119
instrument_codeflash_capture(fto, file_path_to_helper_classes, tests_root)
1120-
mutated_test_results, coverage_data, _ = func_optimizer.run_and_parse_tests(
1120+
mutated_test_results, coverage_data = func_optimizer.run_and_parse_tests(
11211121
testing_type=TestingMode.BEHAVIOR,
11221122
test_env=test_env,
11231123
test_files=func_optimizer.test_files,
@@ -1155,7 +1155,7 @@ def target_function(self):
11551155
Path(helper_path_2): {"HelperClass2", "AnotherHelperClass"},
11561156
}
11571157
instrument_codeflash_capture(fto, file_path_to_helper_classes, tests_root)
1158-
no_helper1_test_results, coverage_data, _ = func_optimizer.run_and_parse_tests(
1158+
no_helper1_test_results, coverage_data = func_optimizer.run_and_parse_tests(
11591159
testing_type=TestingMode.BEHAVIOR,
11601160
test_env=test_env,
11611161
test_files=func_optimizer.test_files,

tests/test_instrument_all_and_run.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ def test_sort():
160160
)
161161
]
162162
)
163-
test_results, coverage_data, _ = func_optimizer.run_and_parse_tests(
163+
test_results, coverage_data = func_optimizer.run_and_parse_tests(
164164
testing_type=TestingMode.BEHAVIOR,
165165
test_env=test_env,
166166
test_files=func_optimizer.test_files,
@@ -205,7 +205,7 @@ def test_sort():
205205
result: [0.0, 1.0, 2.0, 3.0, 4.0, 5.0]
206206
"""
207207
assert test_results[1].stdout == out_str
208-
results2, _, _ = func_optimizer.run_and_parse_tests(
208+
results2, _ = func_optimizer.run_and_parse_tests(
209209
testing_type=TestingMode.BEHAVIOR,
210210
test_env=test_env,
211211
test_files=func_optimizer.test_files,
@@ -331,7 +331,7 @@ def test_sort():
331331
)
332332
]
333333
)
334-
test_results, coverage_data, _ = func_optimizer.run_and_parse_tests(
334+
test_results, coverage_data = func_optimizer.run_and_parse_tests(
335335
testing_type=TestingMode.BEHAVIOR,
336336
test_env=test_env,
337337
test_files=func_optimizer.test_files,
@@ -376,7 +376,7 @@ def test_sort():
376376
assert test_results[3].did_pass
377377
assert test_results[3].stdout == """codeflash stdout : BubbleSorter.sorter() called\n"""
378378

379-
results2, _, _ = func_optimizer.run_and_parse_tests(
379+
results2, _ = func_optimizer.run_and_parse_tests(
380380
testing_type=TestingMode.BEHAVIOR,
381381
test_env=test_env,
382382
test_files=func_optimizer.test_files,
@@ -439,7 +439,7 @@ def sorter(self, arr):
439439
)
440440
]
441441
)
442-
new_test_results, coverage_data, _ = func_optimizer.run_and_parse_tests(
442+
new_test_results, coverage_data = func_optimizer.run_and_parse_tests(
443443
testing_type=TestingMode.BEHAVIOR,
444444
test_env=test_env,
445445
test_files=func_optimizer.test_files,

0 commit comments

Comments
 (0)