Skip to content

Commit ed970ea

Browse files
committed
add more unit tests
1 parent 1a4f60e commit ed970ea

File tree

2 files changed

+31
-1
lines changed

2 files changed

+31
-1
lines changed

tests/test_instrument_all_and_run.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,18 @@ def test_sort():
193193
)
194194
assert test_results[1].runtime > 0
195195
assert test_results[1].did_pass
196+
results2, _ = func_optimizer.run_and_parse_tests(
197+
testing_type=TestingMode.BEHAVIOR,
198+
test_env=test_env,
199+
test_files=func_optimizer.test_files,
200+
optimization_iteration=0,
201+
pytest_min_loops=1,
202+
pytest_max_loops=1,
203+
testing_time=0.1,
204+
)
205+
assert "codeflash stdout: Sorting list" in results2[0].stdout
206+
assert "result: [0, 1, 2, 3, 4, 5]" in results2[0].stdout
207+
assert compare_test_results(test_results, results2)
196208
finally:
197209
fto_path.write_text(original_code, "utf-8")
198210
test_path.unlink(missing_ok=True)
@@ -377,6 +389,18 @@ def test_sort():
377389
assert test_results[3].runtime > 0
378390
assert test_results[3].did_pass
379391

392+
results2, _ = func_optimizer.run_and_parse_tests(
393+
testing_type=TestingMode.BEHAVIOR,
394+
test_env=test_env,
395+
test_files=func_optimizer.test_files,
396+
optimization_iteration=0,
397+
pytest_min_loops=1,
398+
pytest_max_loops=1,
399+
testing_time=0.1,
400+
)
401+
402+
assert compare_test_results(test_results, results2)
403+
380404
# Replace with optimized code that mutated instance attribute
381405
optimized_code = """
382406
class BubbleSorter:

tests/test_instrument_tests.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -482,6 +482,8 @@ def test_sort():
482482
)
483483
assert test_results_perf[1].runtime > 0
484484
assert test_results_perf[1].did_pass
485+
assert "codeflash stdout: Sorting list" in test_results_perf[1].stdout
486+
assert "result: [0, 1, 2, 3, 4, 5]" in test_results_perf[1].stdout
485487
finally:
486488
test_path.unlink(missing_ok=True)
487489
test_path_perf.unlink(missing_ok=True)
@@ -693,6 +695,9 @@ def test_sort_parametrized(input, expected_output):
693695
assert test_results_perf[1].runtime > 0
694696
assert test_results_perf[1].did_pass
695697

698+
assert "codeflash stdout: Sorting list" in test_results_perf[1].stdout
699+
assert "result: [0.0, 1.0, 2.0, 3.0, 4.0, 5.0]" in test_results_perf[1].stdout
700+
696701
assert test_results_perf[2].id.function_getting_tested == "sorter"
697702
assert test_results_perf[2].id.iteration_id == "0_2"
698703
assert test_results_perf[2].id.test_class_name is None
@@ -1230,7 +1235,8 @@ def test_sort():
12301235
assert test_results[0].runtime > 0
12311236
assert test_results[0].did_pass
12321237
assert test_results[0].return_value is None
1233-
1238+
assert "codeflash stdout: Sorting list" in test_results[0].stdout
1239+
assert "result: [0.0, 1.0, 2.0, 3.0, 4.0, 5.0]" in test_results[0].stdout
12341240
assert test_results[1].id.function_getting_tested == "sorter"
12351241
assert test_results[1].id.iteration_id == "2_2_1"
12361242
assert test_results[1].id.test_class_name is None

0 commit comments

Comments
 (0)