Skip to content

Commit a19fc4b

Browse files
committed
address review.
1 parent 0d49970 commit a19fc4b

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
@@ -186,6 +186,9 @@ def test_single_element_list():
186186

187187
# Replace with optimized code that mutated instance attribute
188188
optimized_code_mutated_attr = """
189+
import sys
190+
191+
189192
class BubbleSorter:
190193
191194
def __init__(self, x=1):
@@ -199,6 +202,7 @@ def sorter(self, arr):
199202
temp = arr[j]
200203
arr[j] = arr[j + 1]
201204
arr[j + 1] = temp
205+
print("stderr test", file=sys.stderr)
202206
return arr
203207
"""
204208
fto_path.write_text(optimized_code_mutated_attr, "utf-8")
@@ -331,6 +335,9 @@ def test_single_element_list():
331335
assert test_results[1].return_value[2] == [1, 2, 3]
332336
# Replace with optimized code that mutated instance attribute
333337
optimized_code_mutated_attr = """
338+
import sys
339+
340+
334341
class BubbleSorter:
335342
336343
def __init__(self, x=1):
@@ -344,6 +351,7 @@ def sorter(self, arr):
344351
temp = arr[j]
345352
arr[j] = arr[j + 1]
346353
arr[j + 1] = temp
354+
print("stderr test", file=sys.stderr)
347355
return arr
348356
"""
349357
fto_path.write_text(optimized_code_mutated_attr, "utf-8")
@@ -387,6 +395,9 @@ def sorter(self, arr):
387395
) # The test should fail because the instance attribute was mutated
388396
# Replace with optimized code that did not mutate existing instance attribute, but added a new one
389397
optimized_code_new_attr = """
398+
import sys
399+
400+
390401
class BubbleSorter:
391402
def __init__(self, x=0):
392403
self.x = x
@@ -400,6 +411,7 @@ def sorter(self, arr):
400411
temp = arr[j]
401412
arr[j] = arr[j + 1]
402413
arr[j + 1] = temp
414+
print("stderr test", file=sys.stderr)
403415
return arr
404416
"""
405417
fto_path.write_text(optimized_code_new_attr, "utf-8")

0 commit comments

Comments
 (0)