Skip to content

Commit f2379ce

Browse files
committed
add async codeflash wrap string
1 parent cc6e633 commit f2379ce

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed

tests/test_instrument_all_and_run.py

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,36 @@
4646
return return_value
4747
"""
4848

49+
async_codeflash_wrap_string = """async def codeflash_wrap(wrapped, test_module_name, test_class_name, test_name, function_name, line_id, loop_index, codeflash_cur, codeflash_con, *args, **kwargs):
50+
test_id = f'{{test_module_name}}:{{test_class_name}}:{{test_name}}:{{line_id}}:{{loop_index}}'
51+
if not hasattr(codeflash_wrap, 'index'):
52+
codeflash_wrap.index = {{}}
53+
if test_id in codeflash_wrap.index:
54+
codeflash_wrap.index[test_id] += 1
55+
else:
56+
codeflash_wrap.index[test_id] = 0
57+
codeflash_test_index = codeflash_wrap.index[test_id]
58+
invocation_id = f'{{line_id}}_{{codeflash_test_index}}'
59+
test_stdout_tag = f"{{test_module_name}}:{{(test_class_name + '.' if test_class_name else '')}}{{test_name}}:{{function_name}}:{{loop_index}}:{{invocation_id}}"
60+
print(f"!$######{{test_stdout_tag}}######$!")
61+
exception = None
62+
gc.disable()
63+
try:
64+
counter = time.perf_counter_ns()
65+
return_value = await wrapped(*args, **kwargs)
66+
codeflash_duration = time.perf_counter_ns() - counter
67+
except Exception as e:
68+
codeflash_duration = time.perf_counter_ns() - counter
69+
exception = e
70+
gc.enable()
71+
print(f"!######{{test_stdout_tag}}######!")
72+
pickled_return_value = pickle.dumps(exception) if exception else pickle.dumps(return_value)
73+
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'))
74+
codeflash_con.commit()
75+
if exception:
76+
raise exception
77+
return return_value
78+
"""
4979

5080
def test_bubble_sort_behavior_results() -> None:
5181
code = """from code_to_optimize.bubble_sort import sorter

0 commit comments

Comments
 (0)