Skip to content

Commit f397289

Browse files
committed
address review.
1 parent ed970ea commit f397289

File tree

4 files changed

+39
-6
lines changed

4 files changed

+39
-6
lines changed

code_to_optimize/bubble_sort_method.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
import sys
2+
3+
14
class BubbleSorter:
25
def __init__(self, x=0):
36
self.x = x
@@ -10,4 +13,5 @@ def sorter(self, arr):
1013
temp = arr[j]
1114
arr[j] = arr[j + 1]
1215
arr[j + 1] = temp
16+
print("stderr test", file=sys.stderr)
1317
return arr

tests/test_instrument_all_and_run.py

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -168,8 +168,17 @@ def test_sort():
168168
pytest_max_loops=1,
169169
testing_time=0.1,
170170
)
171-
assert "codeflash stdout: Sorting list" in test_results[0].stdout
172-
assert "result: [0, 1, 2, 3, 4, 5]" in test_results[0].stdout
171+
172+
out_str = """--------------------------------- Captured Log ---------------------------------
173+
174+
--------------------------------- Captured Out ---------------------------------
175+
176+
codeflash stdout: Sorting list
177+
result: [0, 1, 2, 3, 4, 5]
178+
179+
codeflash stdout: Sorting list
180+
result: [0.0, 1.0, 2.0, 3.0, 4.0, 5.0]"""
181+
assert out_str == test_results[0].stdout.strip()
173182
assert test_results[0].id.function_getting_tested == "sorter"
174183
assert test_results[0].id.iteration_id == "1_0"
175184
assert test_results[0].id.test_class_name is None
@@ -181,8 +190,8 @@ def test_sort():
181190
assert test_results[0].runtime > 0
182191
assert test_results[0].did_pass
183192
assert test_results[0].return_value == ([0, 1, 2, 3, 4, 5],)
184-
assert "codeflash stdout: Sorting list" in test_results[1].stdout
185-
assert "result: [0.0, 1.0, 2.0, 3.0, 4.0, 5.0]" in test_results[1].stdout
193+
assert out_str == test_results[1].stdout.strip()
194+
186195
assert test_results[1].id.function_getting_tested == "sorter"
187196
assert test_results[1].id.iteration_id == "4_0"
188197
assert test_results[1].id.test_class_name is None

tests/test_instrument_tests.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -482,8 +482,16 @@ 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
485+
out_str = """--------------------------------- Captured Log ---------------------------------
486+
487+
--------------------------------- Captured Out ---------------------------------
488+
codeflash stdout: Sorting list
489+
result: [0, 1, 2, 3, 4, 5]
490+
491+
codeflash stdout: Sorting list
492+
result: [0.0, 1.0, 2.0, 3.0, 4.0, 5.0]"""
493+
assert out_str == test_results_perf[1].stdout
494+
487495
finally:
488496
test_path.unlink(missing_ok=True)
489497
test_path_perf.unlink(missing_ok=True)

tests/test_instrumentation_run_results_aiservice.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -187,6 +187,9 @@ def test_single_element_list():
187187

188188
# Replace with optimized code that mutated instance attribute
189189
optimized_code_mutated_attr = """
190+
import sys
191+
192+
190193
class BubbleSorter:
191194
192195
def __init__(self, x=1):
@@ -200,6 +203,7 @@ def sorter(self, arr):
200203
temp = arr[j]
201204
arr[j] = arr[j + 1]
202205
arr[j + 1] = temp
206+
print("stderr test", file=sys.stderr)
203207
return arr
204208
"""
205209
fto_path.write_text(optimized_code_mutated_attr, "utf-8")
@@ -332,6 +336,9 @@ def test_single_element_list():
332336
assert test_results[1].return_value[2] == [1, 2, 3]
333337
# Replace with optimized code that mutated instance attribute
334338
optimized_code_mutated_attr = """
339+
import sys
340+
341+
335342
class BubbleSorter:
336343
337344
def __init__(self, x=1):
@@ -345,6 +352,7 @@ def sorter(self, arr):
345352
temp = arr[j]
346353
arr[j] = arr[j + 1]
347354
arr[j + 1] = temp
355+
print("stderr test", file=sys.stderr)
348356
return arr
349357
"""
350358
fto_path.write_text(optimized_code_mutated_attr, "utf-8")
@@ -388,6 +396,9 @@ def sorter(self, arr):
388396
) # The test should fail because the instance attribute was mutated
389397
# Replace with optimized code that did not mutate existing instance attribute, but added a new one
390398
optimized_code_new_attr = """
399+
import sys
400+
401+
391402
class BubbleSorter:
392403
def __init__(self, x=0):
393404
self.x = x
@@ -401,6 +412,7 @@ def sorter(self, arr):
401412
temp = arr[j]
402413
arr[j] = arr[j + 1]
403414
arr[j + 1] = temp
415+
print("stderr test", file=sys.stderr)
404416
return arr
405417
"""
406418
fto_path.write_text(optimized_code_new_attr, "utf-8")

0 commit comments

Comments
 (0)