2525 codeflash_wrap.index[test_id] = 0
2626 codeflash_test_index = codeflash_wrap.index[test_id]
2727 invocation_id = f'{{line_id}}_{{codeflash_test_index}}'
28- print(f"!######{{test_module_name}}:{{(test_class_name + '.' if test_class_name else '')}}{{test_name}}:{{function_name}}:{{loop_index}}:{{invocation_id}}######!")
28+ test_stdout_tag = f"{{test_module_name}}:{{(test_class_name + '.' if test_class_name else '')}}{{test_name}}:{{function_name}}:{{loop_index}}:{{invocation_id}}"
29+ print(f"!$######{{test_stdout_tag}}######$!")
2930 exception = None
3031 gc.disable()
3132 try:
3637 codeflash_duration = time.perf_counter_ns() - counter
3738 exception = e
3839 gc.enable()
40+ print(f"!######{{test_stdout_tag}}######!")
3941 pickled_return_value = pickle.dumps(exception) if exception else pickle.dumps(return_value)
4042 codeflash_cur.execute('INSERT INTO test_results VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)', (test_module_name, test_class_name, test_name, function_name, loop_index, invocation_id, codeflash_duration, pickled_return_value, 'function_call'))
4143 codeflash_con.commit()
@@ -170,9 +172,8 @@ def test_sort():
170172
171173 out_str = """codeflash stdout: Sorting list
172174result: [0, 1, 2, 3, 4, 5]
173-
174- codeflash stdout: Sorting list
175- result: [0.0, 1.0, 2.0, 3.0, 4.0, 5.0]"""
175+ """
176+ assert test_results [0 ].stdout == out_str
176177 assert out_str == test_results [0 ].stdout
177178 assert test_results [0 ].id .function_getting_tested == "sorter"
178179 assert test_results [0 ].id .iteration_id == "1_0"
@@ -185,7 +186,10 @@ def test_sort():
185186 assert test_results [0 ].runtime > 0
186187 assert test_results [0 ].did_pass
187188 assert test_results [0 ].return_value == ([0 , 1 , 2 , 3 , 4 , 5 ],)
188- assert out_str == test_results [1 ].stdout .strip ()
189+ out_str = """codeflash stdout: Sorting list
190+ result: [0.0, 1.0, 2.0, 3.0, 4.0, 5.0]
191+ """
192+ assert out_str == test_results [1 ].stdout
189193
190194 assert test_results [1 ].id .function_getting_tested == "sorter"
191195 assert test_results [1 ].id .iteration_id == "4_0"
@@ -197,6 +201,10 @@ def test_sort():
197201 )
198202 assert test_results [1 ].runtime > 0
199203 assert test_results [1 ].did_pass
204+ out_str = """codeflash stdout: Sorting list
205+ result: [0.0, 1.0, 2.0, 3.0, 4.0, 5.0]
206+ """
207+ assert test_results [1 ].stdout == out_str
200208 results2 , _ = func_optimizer .run_and_parse_tests (
201209 testing_type = TestingMode .BEHAVIOR ,
202210 test_env = test_env ,
@@ -208,10 +216,8 @@ def test_sort():
208216 )
209217 out_str = """codeflash stdout: Sorting list
210218result: [0, 1, 2, 3, 4, 5]
211-
212- codeflash stdout: Sorting list
213- result: [0.0, 1.0, 2.0, 3.0, 4.0, 5.0]"""
214- assert out_str == results2 [0 ].stdout .strip ()
219+ """
220+ assert out_str == results2 [0 ].stdout
215221 assert compare_test_results (test_results , results2 )
216222 finally :
217223 fto_path .write_text (original_code , "utf-8" )
@@ -234,50 +240,18 @@ def test_sort():
234240 output = sort_class.sorter(input)
235241 assert output == [0.0, 1.0, 2.0, 3.0, 4.0, 5.0]"""
236242
237- expected = """import gc
243+ expected = (
244+ """import gc
238245import os
239246import sqlite3
240247import time
241248
242249import dill as pickle
243250
244251from code_to_optimize.bubble_sort_method import BubbleSorter
245-
246-
247- def codeflash_wrap(wrapped, test_module_name, test_class_name, test_name, function_name, line_id, loop_index, codeflash_cur, codeflash_con, *args, **kwargs):
248- test_id = f'{{test_module_name}}:{{test_class_name}}:{{test_name}}:{{line_id}}:{{loop_index}}'
249- if not hasattr(codeflash_wrap, 'index'):
250- codeflash_wrap.index = {{}}
251- if test_id in codeflash_wrap.index:
252- codeflash_wrap.index[test_id] += 1
253- else:
254- codeflash_wrap.index[test_id] = 0
255- codeflash_test_index = codeflash_wrap.index[test_id]
256- invocation_id = f'{{line_id}}_{{codeflash_test_index}}'
257- """
258- if sys .version_info < (3 , 12 ):
259- expected += """print(f"!######{{test_module_name}}:{{(test_class_name + '.' if test_class_name else '')}}{{test_name}}:{{function_name}}:{{loop_index}}:{{invocation_id}}######!")"""
260- else :
261- expected += """print(f'!######{{test_module_name}}:{{(test_class_name + '.' if test_class_name else '')}}{{test_name}}:{{function_name}}:{{loop_index}}:{{invocation_id}}######!')"""
262- expected += """
263- exception = None
264- gc.disable()
265- try:
266- counter = time.perf_counter_ns()
267- return_value = wrapped(*args, **kwargs)
268- codeflash_duration = time.perf_counter_ns() - counter
269- except Exception as e:
270- codeflash_duration = time.perf_counter_ns() - counter
271- exception = e
272- gc.enable()
273- pickled_return_value = pickle.dumps(exception) if exception else pickle.dumps(return_value)
274- codeflash_cur.execute('INSERT INTO test_results VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)', (test_module_name, test_class_name, test_name, function_name, loop_index, invocation_id, codeflash_duration, pickled_return_value, 'function_call'))
275- codeflash_con.commit()
276- if exception:
277- raise exception
278- return return_value
279252"""
280- expected += """
253+ + codeflash_wrap_string
254+ + """
281255def test_sort():
282256 codeflash_loop_index = int(os.environ['CODEFLASH_LOOP_INDEX'])
283257 codeflash_iteration = os.environ['CODEFLASH_TEST_ITERATION']
@@ -294,6 +268,7 @@ def test_sort():
294268 assert output == [0.0, 1.0, 2.0, 3.0, 4.0, 5.0]
295269 codeflash_con.close()
296270"""
271+ )
297272 fto_path = (Path (__file__ ).parent .resolve () / "../code_to_optimize/bubble_sort_method.py" ).resolve ()
298273 original_code = fto_path .read_text ("utf-8" )
299274 fto = FunctionToOptimize (
@@ -379,7 +354,9 @@ def test_sort():
379354 assert test_results [1 ].runtime > 0
380355 assert test_results [1 ].did_pass
381356 assert test_results [1 ].return_value == ([0 , 1 , 2 , 3 , 4 , 5 ],)
382- out_str = """codeflash stdout : BubbleSorter.sorter() called\n \n \n codeflash stdout : BubbleSorter.sorter() called"""
357+ out_str = (
358+ """codeflash stdout : BubbleSorter.sorter() called\n \n \n codeflash stdout : BubbleSorter.sorter() called"""
359+ )
383360 assert test_results [1 ].stdout == out_str
384361 assert compare_test_results (test_results , test_results )
385362 assert test_results [2 ].id .function_getting_tested == "BubbleSorter.__init__"
0 commit comments