Skip to content

Commit 29b2f21

Browse files
committed
fix more tests
1 parent 80baa78 commit 29b2f21

File tree

2 files changed

+20
-10
lines changed

2 files changed

+20
-10
lines changed

tests/test_instrument_all_and_run.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -247,8 +247,9 @@ def test_sort():
247247
import time
248248
249249
import dill as pickle
250-
251250
from code_to_optimize.bubble_sort_method import BubbleSorter
251+
252+
252253
"""
253254
+ codeflash_wrap_string
254255
+ """

tests/test_instrument_tests.py

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -307,10 +307,12 @@ def test_prepare_image_for_yolo():
307307
def test_perfinjector_bubble_sort_results() -> None:
308308
computed_fn_opt = False
309309
code = """from code_to_optimize.bubble_sort import sorter
310+
import datetime
310311
311312
312313
def test_sort():
313314
input = [5, 4, 3, 2, 1, 0]
315+
print(datetime.datetime.now().isoformat())
314316
output = sorter(input)
315317
assert output == [0, 1, 2, 3, 4, 5]
316318
@@ -319,7 +321,8 @@ def test_sort():
319321
assert output == [0.0, 1.0, 2.0, 3.0, 4.0, 5.0]"""
320322

321323
expected = (
322-
"""import gc
324+
"""import datetime
325+
import gc
323326
import os
324327
import sqlite3
325328
import time
@@ -339,17 +342,19 @@ def test_sort():
339342
codeflash_cur = codeflash_con.cursor()
340343
codeflash_cur.execute('CREATE TABLE IF NOT EXISTS test_results (test_module_path TEXT, test_class_name TEXT, test_function_name TEXT, function_getting_tested TEXT, loop_index INTEGER, iteration_id TEXT, runtime INTEGER, return_value BLOB, verification_type TEXT)')
341344
input = [5, 4, 3, 2, 1, 0]
342-
output = codeflash_wrap(sorter, '{module_path}', None, 'test_sort', 'sorter', '1', codeflash_loop_index, codeflash_cur, codeflash_con, input)
345+
print(datetime.datetime.now().isoformat())
346+
output = codeflash_wrap(sorter, '{module_path}', None, 'test_sort', 'sorter', '2', codeflash_loop_index, codeflash_cur, codeflash_con, input)
343347
assert output == [0, 1, 2, 3, 4, 5]
344348
input = [5.0, 4.0, 3.0, 2.0, 1.0, 0.0]
345-
output = codeflash_wrap(sorter, '{module_path}', None, 'test_sort', 'sorter', '4', codeflash_loop_index, codeflash_cur, codeflash_con, input)
349+
output = codeflash_wrap(sorter, '{module_path}', None, 'test_sort', 'sorter', '5', codeflash_loop_index, codeflash_cur, codeflash_con, input)
346350
assert output == [0.0, 1.0, 2.0, 3.0, 4.0, 5.0]
347351
codeflash_con.close()
348352
"""
349353
)
350354

351355
expected_perfonly = (
352-
"""import gc
356+
"""import datetime
357+
import gc
353358
import os
354359
import time
355360
@@ -362,10 +367,10 @@ def test_sort():
362367
def test_sort():
363368
codeflash_loop_index = int(os.environ['CODEFLASH_LOOP_INDEX'])
364369
input = [5, 4, 3, 2, 1, 0]
365-
output = codeflash_wrap(sorter, '{module_path}', None, 'test_sort', 'sorter', '1', codeflash_loop_index, input)
370+
output = codeflash_wrap(sorter, '{module_path}', None, 'test_sort', 'sorter', '2', codeflash_loop_index, input)
366371
assert output == [0, 1, 2, 3, 4, 5]
367372
input = [5.0, 4.0, 3.0, 2.0, 1.0, 0.0]
368-
output = codeflash_wrap(sorter, '{module_path}', None, 'test_sort', 'sorter', '4', codeflash_loop_index, input)
373+
output = codeflash_wrap(sorter, '{module_path}', None, 'test_sort', 'sorter', '5', codeflash_loop_index, input)
369374
assert output == [0.0, 1.0, 2.0, 3.0, 4.0, 5.0]
370375
"""
371376
)
@@ -390,7 +395,7 @@ def test_sort():
390395
os.chdir(run_cwd)
391396
success, new_test = inject_profiling_into_existing_test(
392397
test_path,
393-
[CodePosition(6, 13), CodePosition(10, 13)],
398+
[CodePosition(8, 13), CodePosition(12, 13)],
394399
func,
395400
project_root_path,
396401
"pytest",
@@ -560,6 +565,7 @@ def test_perfinjector_bubble_sort_parametrized_results() -> None:
560565
computed_fn_opt = False
561566
code = """from code_to_optimize.bubble_sort import sorter
562567
import pytest
568+
import datetime
563569
564570
565571
@pytest.mark.parametrize(
@@ -571,6 +577,7 @@ def test_perfinjector_bubble_sort_parametrized_results() -> None:
571577
],
572578
)
573579
def test_sort_parametrized(input, expected_output):
580+
print(datetime.datetime.now().isoformat())
574581
output = sorter(input)
575582
assert output == expected_output
576583
"""
@@ -606,6 +613,7 @@ def test_sort_parametrized(input, expected_output):
606613
"""import gc
607614
import os
608615
import time
616+
import datetime
609617
610618
import pytest
611619
@@ -618,6 +626,7 @@ def test_sort_parametrized(input, expected_output):
618626
@pytest.mark.parametrize('input, expected_output', [([5, 4, 3, 2, 1, 0], [0, 1, 2, 3, 4, 5]), ([5.0, 4.0, 3.0, 2.0, 1.0, 0.0], [0.0, 1.0, 2.0, 3.0, 4.0, 5.0]), (list(reversed(range(50))), list(range(50)))])
619627
def test_sort_parametrized(input, expected_output):
620628
codeflash_loop_index = int(os.environ['CODEFLASH_LOOP_INDEX'])
629+
print(datetime.datetime.now().isoformat())
621630
output = codeflash_wrap(sorter, '{module_path}', None, 'test_sort_parametrized', 'sorter', '0', codeflash_loop_index, input)
622631
assert output == expected_output
623632
"""
@@ -643,11 +652,11 @@ def test_sort_parametrized(input, expected_output):
643652
func = FunctionToOptimize(function_name="sorter", parents=[], file_path=code_path)
644653
os.chdir(run_cwd)
645654
success, new_test = inject_profiling_into_existing_test(
646-
test_path, [CodePosition(14, 13)], func, project_root_path, "pytest", mode=TestingMode.BEHAVIOR
655+
test_path, [CodePosition(16, 13)], func, project_root_path, "pytest", mode=TestingMode.BEHAVIOR
647656
)
648657
assert success
649658
success, new_test_perf = inject_profiling_into_existing_test(
650-
test_path, [CodePosition(14, 13)], func, project_root_path, "pytest", mode=TestingMode.PERFORMANCE
659+
test_path, [CodePosition(16, 13)], func, project_root_path, "pytest", mode=TestingMode.PERFORMANCE
651660
)
652661

653662
os.chdir(original_cwd)

0 commit comments

Comments
 (0)