Skip to content

Commit 66381bd

Browse files
committed
tests passing
1 parent dd44def commit 66381bd

File tree

1 file changed

+45
-37
lines changed

1 file changed

+45
-37
lines changed

tests/test_add_runtime_comments.py

Lines changed: 45 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -60,18 +60,15 @@ def test_basic_runtime_comment_addition(self, test_config):
6060
behavior_file_path=Path("/project/tests/test_module.py"),
6161
perf_file_path=Path("/project/tests/test_module_perf.py"),
6262
)
63-
"""add_runtime_comments_to_generated_tests(
64-
test_config, generated_tests, original_runtimes, optimized_runtimes
65-
)"""
6663
generated_tests = GeneratedTestsList(generated_tests=[generated_test])
6764

6865
# Create test results
6966
original_test_results = TestResults()
7067
optimized_test_results = TestResults()
7168

7269
# Add test invocations with different runtimes
73-
original_invocation = self.create_test_invocation("test_bubble_sort", 500_000) # 500μs
74-
optimized_invocation = self.create_test_invocation("test_bubble_sort", 300_000) # 300μs
70+
original_invocation = self.create_test_invocation("test_bubble_sort", 500_000, iteration_id='0') # 500μs
71+
optimized_invocation = self.create_test_invocation("test_bubble_sort", 300_000, iteration_id='0') # 300μs
7572

7673
original_test_results.add(original_invocation)
7774
optimized_test_results.add(optimized_invocation)
@@ -114,11 +111,11 @@ def helper_function():
114111
optimized_test_results = TestResults()
115112

116113
# Add test invocations for both test functions
117-
original_test_results.add(self.create_test_invocation("test_bubble_sort", 500_000))
118-
original_test_results.add(self.create_test_invocation("test_quick_sort", 800_000))
114+
original_test_results.add(self.create_test_invocation("test_bubble_sort", 500_000, iteration_id='0'))
115+
original_test_results.add(self.create_test_invocation("test_quick_sort", 800_000, iteration_id='0'))
119116

120-
optimized_test_results.add(self.create_test_invocation("test_bubble_sort", 300_000))
121-
optimized_test_results.add(self.create_test_invocation("test_quick_sort", 600_000))
117+
optimized_test_results.add(self.create_test_invocation("test_bubble_sort", 300_000, iteration_id='0'))
118+
optimized_test_results.add(self.create_test_invocation("test_quick_sort", 600_000, iteration_id='0'))
122119

123120
original_runtimes = original_test_results.usable_runtime_data_by_test_case()
124121
optimized_runtimes = optimized_test_results.usable_runtime_data_by_test_case()
@@ -150,6 +147,7 @@ def test_different_time_formats(self, test_config):
150147

151148
for original_time, optimized_time, expected_comment in test_cases:
152149
test_source = """def test_function():
150+
#this comment will be removed in ast form
153151
codeflash_output = some_function()
154152
assert codeflash_output is not None
155153
"""
@@ -168,8 +166,8 @@ def test_different_time_formats(self, test_config):
168166
original_test_results = TestResults()
169167
optimized_test_results = TestResults()
170168

171-
original_test_results.add(self.create_test_invocation("test_function", original_time))
172-
optimized_test_results.add(self.create_test_invocation("test_function", optimized_time))
169+
original_test_results.add(self.create_test_invocation("test_function", original_time, iteration_id='0'))
170+
optimized_test_results.add(self.create_test_invocation("test_function", optimized_time, iteration_id='0'))
173171

174172
original_runtimes = original_test_results.usable_runtime_data_by_test_case()
175173
optimized_runtimes = optimized_test_results.usable_runtime_data_by_test_case()
@@ -233,7 +231,7 @@ def test_partial_test_results(self, test_config):
233231
original_test_results = TestResults()
234232
optimized_test_results = TestResults()
235233

236-
original_test_results.add(self.create_test_invocation("test_bubble_sort", 500_000))
234+
original_test_results.add(self.create_test_invocation("test_bubble_sort", 500_000, iteration_id='0'))
237235
# No optimized results
238236
original_runtimes = original_test_results.usable_runtime_data_by_test_case()
239237
optimized_runtimes = optimized_test_results.usable_runtime_data_by_test_case()
@@ -266,13 +264,13 @@ def test_multiple_runtimes_uses_minimum(self, test_config):
266264
optimized_test_results = TestResults()
267265

268266
# Add multiple runs with different runtimes
269-
original_test_results.add(self.create_test_invocation("test_bubble_sort", 600_000, loop_index=1))
270-
original_test_results.add(self.create_test_invocation("test_bubble_sort", 500_000, loop_index=2))
271-
original_test_results.add(self.create_test_invocation("test_bubble_sort", 550_000, loop_index=3))
267+
original_test_results.add(self.create_test_invocation("test_bubble_sort", 600_000, loop_index=1,iteration_id='0'))
268+
original_test_results.add(self.create_test_invocation("test_bubble_sort", 500_000, loop_index=2,iteration_id='0'))
269+
original_test_results.add(self.create_test_invocation("test_bubble_sort", 550_000, loop_index=3,iteration_id='0'))
272270

273-
optimized_test_results.add(self.create_test_invocation("test_bubble_sort", 350_000, loop_index=1))
274-
optimized_test_results.add(self.create_test_invocation("test_bubble_sort", 300_000, loop_index=2))
275-
optimized_test_results.add(self.create_test_invocation("test_bubble_sort", 320_000, loop_index=3))
271+
optimized_test_results.add(self.create_test_invocation("test_bubble_sort", 350_000, loop_index=1,iteration_id='0'))
272+
optimized_test_results.add(self.create_test_invocation("test_bubble_sort", 300_000, loop_index=2,iteration_id='0'))
273+
optimized_test_results.add(self.create_test_invocation("test_bubble_sort", 320_000, loop_index=3,iteration_id='0'))
276274

277275
original_runtimes = original_test_results.usable_runtime_data_by_test_case()
278276
optimized_runtimes = optimized_test_results.usable_runtime_data_by_test_case()
@@ -304,8 +302,8 @@ def test_no_codeflash_output_assignment(self, test_config):
304302
original_test_results = TestResults()
305303
optimized_test_results = TestResults()
306304

307-
original_test_results.add(self.create_test_invocation("test_bubble_sort", 500_000))
308-
optimized_test_results.add(self.create_test_invocation("test_bubble_sort", 300_000))
305+
original_test_results.add(self.create_test_invocation("test_bubble_sort", 500_000,iteration_id='-1'))
306+
optimized_test_results.add(self.create_test_invocation("test_bubble_sort", 300_000,iteration_id='-1'))
309307

310308
original_runtimes = original_test_results.usable_runtime_data_by_test_case()
311309
optimized_runtimes = optimized_test_results.usable_runtime_data_by_test_case()
@@ -320,9 +318,9 @@ def test_no_codeflash_output_assignment(self, test_config):
320318
def test_invalid_python_code_handling(self, test_config):
321319
"""Test behavior when test source code is invalid Python."""
322320
test_source = """def test_bubble_sort(:
323-
codeflash_output = bubble_sort([3, 1, 2])
321+
codeflash_output = bubble_sort([3, 1, 2])
324322
assert codeflash_output == [1, 2, 3]
325-
""" # Invalid syntax: extra colon
323+
""" # Invalid syntax: extra indentation
326324

327325
generated_test = GeneratedTests(
328326
generated_original_test_source=test_source,
@@ -338,8 +336,8 @@ def test_invalid_python_code_handling(self, test_config):
338336
original_test_results = TestResults()
339337
optimized_test_results = TestResults()
340338

341-
original_test_results.add(self.create_test_invocation("test_bubble_sort", 500_000))
342-
optimized_test_results.add(self.create_test_invocation("test_bubble_sort", 300_000))
339+
original_test_results.add(self.create_test_invocation("test_bubble_sort", 500_000,iteration_id='0'))
340+
optimized_test_results.add(self.create_test_invocation("test_bubble_sort", 300_000,iteration_id='0'))
343341

344342
original_runtimes = original_test_results.usable_runtime_data_by_test_case()
345343
optimized_runtimes = optimized_test_results.usable_runtime_data_by_test_case()
@@ -359,6 +357,9 @@ def test_multiple_generated_tests(self, test_config):
359357
"""
360358

361359
test_source_2 = """def test_quick_sort():
360+
a=1
361+
b=2
362+
c=3
362363
codeflash_output = quick_sort([5, 2, 8])
363364
assert codeflash_output == [2, 5, 8]
364365
"""
@@ -385,11 +386,11 @@ def test_multiple_generated_tests(self, test_config):
385386
original_test_results = TestResults()
386387
optimized_test_results = TestResults()
387388

388-
original_test_results.add(self.create_test_invocation("test_bubble_sort", 500_000))
389-
original_test_results.add(self.create_test_invocation("test_quick_sort", 800_000))
389+
original_test_results.add(self.create_test_invocation("test_bubble_sort", 500_000,iteration_id='0'))
390+
original_test_results.add(self.create_test_invocation("test_quick_sort", 800_000,iteration_id='3'))
390391

391-
optimized_test_results.add(self.create_test_invocation("test_bubble_sort", 300_000))
392-
optimized_test_results.add(self.create_test_invocation("test_quick_sort", 600_000))
392+
optimized_test_results.add(self.create_test_invocation("test_bubble_sort", 300_000,iteration_id='0'))
393+
optimized_test_results.add(self.create_test_invocation("test_quick_sort", 600_000,iteration_id='3'))
393394

394395
original_runtimes = original_test_results.usable_runtime_data_by_test_case()
395396
optimized_runtimes = optimized_test_results.usable_runtime_data_by_test_case()
@@ -430,8 +431,8 @@ def test_preserved_test_attributes(self, test_config):
430431
original_test_results = TestResults()
431432
optimized_test_results = TestResults()
432433

433-
original_test_results.add(self.create_test_invocation("test_bubble_sort", 500_000))
434-
optimized_test_results.add(self.create_test_invocation("test_bubble_sort", 300_000))
434+
original_test_results.add(self.create_test_invocation("test_bubble_sort", 500_000,iteration_id='0'))
435+
optimized_test_results.add(self.create_test_invocation("test_bubble_sort", 300_000,iteration_id='0'))
435436

436437
original_runtimes = original_test_results.usable_runtime_data_by_test_case()
437438
optimized_runtimes = optimized_test_results.usable_runtime_data_by_test_case()
@@ -472,8 +473,8 @@ def test_multistatement_line_handling(self, test_config):
472473
original_test_results = TestResults()
473474
optimized_test_results = TestResults()
474475

475-
original_test_results.add(self.create_test_invocation("test_mutation_of_input", 19_000)) # 19μs
476-
optimized_test_results.add(self.create_test_invocation("test_mutation_of_input", 14_000)) # 14μs
476+
original_test_results.add(self.create_test_invocation("test_mutation_of_input", 19_000,iteration_id='1')) # 19μs
477+
optimized_test_results.add(self.create_test_invocation("test_mutation_of_input", 14_000,iteration_id='1')) # 14μs
477478

478479
original_runtimes = original_test_results.usable_runtime_data_by_test_case()
479480
optimized_runtimes = optimized_test_results.usable_runtime_data_by_test_case()
@@ -600,16 +601,23 @@ def test_add_runtime_comments_multiple_assignments(self, test_config):
600601

601602
generated_tests = GeneratedTestsList(generated_tests=[generated_test])
602603

603-
invocation_id = InvocationId(
604+
invocation_id1 = InvocationId(
604605
test_module_path="tests.test_module",
605606
test_class_name=None,
606607
test_function_name="test_function",
607608
function_getting_tested="some_function",
608-
iteration_id="0",
609+
iteration_id="1",
610+
)
611+
invocation_id2 = InvocationId(
612+
test_module_path="tests.test_module",
613+
test_class_name=None,
614+
test_function_name="test_function",
615+
function_getting_tested="another_function",
616+
iteration_id="3",
609617
)
610618

611-
original_runtimes = {invocation_id: [1500000000]} # 1.5s in nanoseconds
612-
optimized_runtimes = {invocation_id: [750000000]} # 0.75s in nanoseconds
619+
original_runtimes = {invocation_id1: [1500000000], invocation_id2: [10]} # 1.5s in nanoseconds
620+
optimized_runtimes = {invocation_id1: [750000000], invocation_id2: [5]} # 0.75s in nanoseconds
613621

614622
result = add_runtime_comments_to_generated_tests(
615623
test_config, generated_tests, original_runtimes, optimized_runtimes
@@ -619,7 +627,7 @@ def test_add_runtime_comments_multiple_assignments(self, test_config):
619627
setup_data = prepare_test()
620628
codeflash_output = some_function() # 1.50s -> 750ms (100% faster)
621629
assert codeflash_output == expected
622-
codeflash_output = another_function() # 1.50s -> 750ms (100% faster)
630+
codeflash_output = another_function() # 10ns -> 5ns (100% faster)
623631
assert codeflash_output == expected2
624632
'''
625633

0 commit comments

Comments
 (0)