Skip to content

Commit 6dd2fee

Browse files
committed
progress
1 parent f6fd450 commit 6dd2fee

File tree

3 files changed

+111
-43
lines changed

3 files changed

+111
-43
lines changed

codeflash/code_utils/instrument_existing_tests.py

Lines changed: 95 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -462,50 +462,96 @@ def create_wrapper_function(mode: TestingMode = TestingMode.BEHAVIOR) -> ast.Fun
462462
),
463463
*(
464464
[
465+
ast.Assign(
466+
targets=[
467+
ast.Name(id='test_stdout_tag', ctx=ast.Store())],
468+
value=ast.JoinedStr(
469+
values=[
470+
ast.FormattedValue(
471+
value=ast.Name(id='test_module_name', ctx=ast.Load()),
472+
conversion=-1),
473+
ast.Constant(value=':'),
474+
ast.FormattedValue(
475+
value=ast.IfExp(
476+
test=ast.Name(id='test_class_name', ctx=ast.Load()),
477+
body=ast.BinOp(
478+
left=ast.Name(id='test_class_name', ctx=ast.Load()),
479+
op=ast.Add(),
480+
right=ast.Constant(value='.')),
481+
orelse=ast.Constant(value='')),
482+
conversion=-1),
483+
ast.FormattedValue(
484+
value=ast.Name(id='test_name', ctx=ast.Load()),
485+
conversion=-1),
486+
ast.Constant(value=':'),
487+
ast.FormattedValue(
488+
value=ast.Name(id='function_name', ctx=ast.Load()),
489+
conversion=-1),
490+
ast.Constant(value=':'),
491+
ast.FormattedValue(
492+
value=ast.Name(id='loop_index', ctx=ast.Load()),
493+
conversion=-1),
494+
ast.Constant(value=':'),
495+
ast.FormattedValue(
496+
value=ast.Name(id='invocation_id', ctx=ast.Load()),
497+
conversion=-1)]),
498+
lineno=lineno + 9,),
465499
ast.Expr(
466500
value=ast.Call(
467-
func=ast.Name(id="print", ctx=ast.Load()),
501+
func=ast.Name(id='print', ctx=ast.Load()),
468502
args=[
469503
ast.JoinedStr(
470504
values=[
471-
ast.Constant(value="!######"),
505+
ast.Constant(value='!$######'),
472506
ast.FormattedValue(
473-
value=ast.Name(id="test_module_name", ctx=ast.Load()), conversion=-1
474-
),
475-
ast.Constant(value=":"),
476-
ast.FormattedValue(
477-
value=ast.IfExp(
478-
test=ast.Name(id="test_class_name", ctx=ast.Load()),
479-
body=ast.BinOp(
480-
left=ast.Name(id="test_class_name", ctx=ast.Load()),
481-
op=ast.Add(),
482-
right=ast.Constant(value="."),
483-
),
484-
orelse=ast.Constant(value=""),
485-
),
486-
conversion=-1,
487-
),
488-
ast.FormattedValue(value=ast.Name(id="test_name", ctx=ast.Load()), conversion=-1),
489-
ast.Constant(value=":"),
490-
ast.FormattedValue(
491-
value=ast.Name(id="function_name", ctx=ast.Load()), conversion=-1
492-
),
493-
ast.Constant(value=":"),
494-
ast.FormattedValue(value=ast.Name(id="loop_index", ctx=ast.Load()), conversion=-1),
495-
ast.Constant(value=":"),
496-
ast.FormattedValue(
497-
value=ast.Name(id="invocation_id", ctx=ast.Load()), conversion=-1
498-
),
499-
ast.Constant(value="######!"),
500-
]
501-
)
502-
],
503-
keywords=[],
504-
)
505-
)
507+
value=ast.Name(id='test_stdout_tag', ctx=ast.Load()),
508+
conversion=-1),
509+
ast.Constant(value='######$!')])],
510+
keywords=[])),
511+
# ast.Expr(
512+
# value=ast.Call(
513+
# func=ast.Name(id="print", ctx=ast.Load()),
514+
# args=[
515+
# ast.JoinedStr(
516+
# values=[
517+
# ast.Constant(value="!######"),
518+
# ast.FormattedValue(
519+
# value=ast.Name(id="test_module_name", ctx=ast.Load()), conversion=-1
520+
# ),
521+
# ast.Constant(value=":"),
522+
# ast.FormattedValue(
523+
# value=ast.IfExp(
524+
# test=ast.Name(id="test_class_name", ctx=ast.Load()),
525+
# body=ast.BinOp(
526+
# left=ast.Name(id="test_class_name", ctx=ast.Load()),
527+
# op=ast.Add(),
528+
# right=ast.Constant(value="."),
529+
# ),
530+
# orelse=ast.Constant(value=""),
531+
# ),
532+
# conversion=-1,
533+
# ),
534+
# ast.FormattedValue(value=ast.Name(id="test_name", ctx=ast.Load()), conversion=-1),
535+
# ast.Constant(value=":"),
536+
# ast.FormattedValue(
537+
# value=ast.Name(id="function_name", ctx=ast.Load()), conversion=-1
538+
# ),
539+
# ast.Constant(value=":"),
540+
# ast.FormattedValue(value=ast.Name(id="loop_index", ctx=ast.Load()), conversion=-1),
541+
# ast.Constant(value=":"),
542+
# ast.FormattedValue(
543+
# value=ast.Name(id="invocation_id", ctx=ast.Load()), conversion=-1
544+
# ),
545+
# ast.Constant(value="######!"),
546+
# ]
547+
# )
548+
# ],
549+
# keywords=[],
550+
# )
551+
# )
506552
]
507-
if mode == TestingMode.BEHAVIOR
508-
else []
553+
# if mode == TestingMode.BEHAVIOR
554+
# else []
509555
),
510556
ast.Assign(
511557
targets=[ast.Name(id="exception", ctx=ast.Store())], value=ast.Constant(value=None), lineno=lineno + 10
@@ -598,6 +644,18 @@ def create_wrapper_function(mode: TestingMode = TestingMode.BEHAVIOR) -> ast.Fun
598644
keywords=[],
599645
)
600646
),
647+
ast.Expr(
648+
value=ast.Call(
649+
func=ast.Name(id='print', ctx=ast.Load()),
650+
args=[
651+
ast.JoinedStr(
652+
values=[
653+
ast.Constant(value='!######'),
654+
ast.FormattedValue(
655+
value=ast.Name(id='test_stdout_tag', ctx=ast.Load()),
656+
conversion=-1),
657+
ast.Constant(value='######!')])],
658+
keywords=[])),
601659
*(
602660
[
603661
ast.Expr(

codeflash/verification/parse_test_output.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ def parse_func(file_path: Path) -> XMLParser:
3737

3838

3939
matches_re = re.compile(r"!######(.*?):(.*?)([^\.:]*?):(.*?):(.*?):(.*?)######!")
40-
stdout_re = re.compile(r"!######.*?######!\n(.*)!\$######.*?######\$!", re.DOTALL)
40+
stdout_re = re.compile(r"!\$######.*?######\$!\n(.*)!######.*?######!", re.DOTALL)
4141

4242

4343
def parse_test_return_values_bin(file_location: Path, test_files: TestFiles, test_config: TestConfig) -> TestResults:
@@ -268,7 +268,9 @@ def parse_test_xml(
268268
matches = matches_re.findall(sys_stdout)
269269

270270
if sys_stdout:
271-
sys_stdout = stdout_re.search(sys_stdout).group(1)
271+
print("sys_stdout: ", sys_stdout)
272+
stdout_match = stdout_re.search(sys_stdout)
273+
sys_stdout = stdout_match.group(1) if stdout_match else ""
272274

273275
if not matches or not len(matches):
274276
test_results.add(

tests/test_instrument_tests.py

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,8 @@
3737
codeflash_wrap.index[test_id] = 0
3838
codeflash_test_index = codeflash_wrap.index[test_id]
3939
invocation_id = f'{{line_id}}_{{codeflash_test_index}}'
40-
print(f"!######{{test_module_name}}:{{(test_class_name + '.' if test_class_name else '')}}{{test_name}}:{{function_name}}:{{loop_index}}:{{invocation_id}}######!")
40+
test_stdout_tag = f"{{test_module_name}}:{{(test_class_name + '.' if test_class_name else '')}}{{test_name}}:{{function_name}}:{{loop_index}}:{{invocation_id}}"
41+
print(f"!$######{test_stdout_tag}######$!")
4142
exception = None
4243
gc.disable()
4344
try:
@@ -48,6 +49,7 @@
4849
codeflash_duration = time.perf_counter_ns() - counter
4950
exception = e
5051
gc.enable()
52+
print(f"!######{test_stdout_tag}######!")
5153
pickled_return_value = pickle.dumps(exception) if exception else pickle.dumps(return_value)
5254
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'))
5355
codeflash_con.commit()
@@ -67,6 +69,8 @@
6769
codeflash_test_index = codeflash_wrap.index[test_id]
6870
invocation_id = f'{{line_id}}_{{codeflash_test_index}}'
6971
exception = None
72+
test_stdout_tag = f"{{test_module_name}}:{{(test_class_name + '.' if test_class_name else '')}}{{test_name}}:{{function_name}}:{{loop_index}}:{{invocation_id}}"
73+
print(f"!$######{{test_stdout_tag}}######$!")
7074
gc.disable()
7175
try:
7276
counter = time.perf_counter_ns()
@@ -76,7 +80,7 @@
7680
codeflash_duration = time.perf_counter_ns() - counter
7781
exception = e
7882
gc.enable()
79-
print(f"!######{{test_module_name}}:{{(test_class_name + '.' if test_class_name else '')}}{{test_name}}:{{function_name}}:{{loop_index}}:{{invocation_id}}:{{codeflash_duration}}######!")
83+
print(f"!######{{test_stdout_tag}}:{{codeflash_duration}}######!")
8084
if exception:
8185
raise exception
8286
return return_value
@@ -124,11 +128,14 @@ def codeflash_wrap(wrapped, test_module_name, test_class_name, test_name, functi
124128
codeflash_wrap.index[test_id] = 0
125129
codeflash_test_index = codeflash_wrap.index[test_id]
126130
invocation_id = f'{{line_id}}_{{codeflash_test_index}}'
131+
test_stdout_tag = f"{{test_module_name}}:{{(test_class_name + '.' if test_class_name else '')}}{{test_name}}:{{function_name}}:{{loop_index}}:{{invocation_id}}"
127132
"""
128133
if sys.version_info < (3, 12):
129-
expected += """print(f"!######{{test_module_name}}:{{(test_class_name + '.' if test_class_name else '')}}{{test_name}}:{{function_name}}:{{loop_index}}:{{invocation_id}}######!")"""
134+
expected += """test_stdout_tag = f"{{test_module_name}}:{{(test_class_name + '.' if test_class_name else '')}}{{test_name}}:{{function_name}}:{{loop_index}}:{{invocation_id}}"
135+
print(f"!$######{{test_stdout_tag}}######$!")"""
130136
else:
131-
expected += """print(f'!######{{test_module_name}}:{{(test_class_name + '.' if test_class_name else '')}}{{test_name}}:{{function_name}}:{{loop_index}}:{{invocation_id}}######!')"""
137+
expected += """print(f'!######{{test_module_name}}:{{(test_class_name + '.' if test_class_name else '')}}{{test_name}}:{{function_name}}:{{loop_index}}:{{invocation_id}}######!')
138+
print(f'!$######{{test_stdout_tag}}######$!')"""
132139
expected += """
133140
exception = None
134141
gc.disable()
@@ -140,6 +147,7 @@ def codeflash_wrap(wrapped, test_module_name, test_class_name, test_name, functi
140147
codeflash_duration = time.perf_counter_ns() - counter
141148
exception = e
142149
gc.enable()
150+
print(f"!######{{test_stdout_tag}}######!")
143151
pickled_return_value = pickle.dumps(exception) if exception else pickle.dumps(return_value)
144152
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'))
145153
codeflash_con.commit()

0 commit comments

Comments
 (0)