Skip to content

Commit f7960ff

Browse files
committed
stdout comparison
Update test_results.py Update parse_test_output.py Update equivalence.py
1 parent c93a7ca commit f7960ff

File tree

4 files changed

+27
-3
lines changed

4 files changed

+27
-3
lines changed

codeflash/verification/equivalence.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1+
import difflib
12
import sys
23

3-
from codeflash.cli_cmds.console import logger
4+
from codeflash.cli_cmds.console import console, logger
45
from codeflash.verification.comparator import comparator
56
from codeflash.verification.test_results import TestResults, TestType, VerificationType
67

@@ -61,6 +62,12 @@ def compare_test_results(original_results: TestResults, candidate_results: TestR
6162
cdd_test_result.return_value,
6263
)
6364
break
65+
if (original_test_result.stdout and cdd_test_result.stdout) and not comparator(
66+
original_test_result.stdout, cdd_test_result.stdout
67+
):
68+
are_equal = False
69+
break
70+
6471
if original_test_result.test_type in [TestType.EXISTING_UNIT_TEST, TestType.CONCOLIC_COVERAGE_TEST] and (
6572
cdd_test_result.did_pass != original_test_result.did_pass
6673
):

codeflash/verification/parse_test_output.py

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,10 @@ def parse_func(file_path: Path) -> XMLParser:
4242
return parse(file_path, xml_parser)
4343

4444

45+
matches_re = re.compile(r"!######(.*?):(.*?)([^\.:]*?):(.*?):(.*?):(.*?)######!")
46+
cleaner_re = re.compile(r"!######(.*?)######!")
47+
48+
4549
def parse_test_return_values_bin(file_location: Path, test_files: TestFiles, test_config: TestConfig) -> TestResults:
4650
test_results = TestResults()
4751
if not file_location.exists():
@@ -259,7 +263,13 @@ def parse_test_xml(
259263
message = testcase.result[0].message.lower()
260264
if "timed out" in message:
261265
timed_out = True
262-
matches = re.findall(r"!######(.*?):(.*?)([^\.:]*?):(.*?):(.*?):(.*?)######!", testcase.system_out or "")
266+
267+
sys_stdout = testcase.system_out or ""
268+
matches = matches_re.findall(sys_stdout)
269+
270+
if sys_stdout:
271+
sys_stdout = cleaner_re.sub("", sys_stdout)
272+
263273
if not matches or not len(matches):
264274
test_results.add(
265275
FunctionTestInvocation(
@@ -278,6 +288,7 @@ def parse_test_xml(
278288
test_type=test_type,
279289
return_value=None,
280290
timed_out=timed_out,
291+
stdout=sys_stdout,
281292
)
282293
)
283294

@@ -306,6 +317,7 @@ def parse_test_xml(
306317
test_type=test_type,
307318
return_value=None,
308319
timed_out=timed_out,
320+
stdout=sys_stdout,
309321
)
310322
)
311323

@@ -393,6 +405,7 @@ def merge_test_results(
393405
verification_type=VerificationType(result_bin.verification_type)
394406
if result_bin.verification_type
395407
else None,
408+
stdout=xml_result.stdout,
396409
)
397410
)
398411
elif xml_results.test_results[0].id.iteration_id is not None:
@@ -422,6 +435,7 @@ def merge_test_results(
422435
verification_type=VerificationType(bin_result.verification_type)
423436
if bin_result.verification_type
424437
else None,
438+
stdout=xml_result.stdout,
425439
)
426440
)
427441
else:
@@ -448,6 +462,7 @@ def merge_test_results(
448462
verification_type=VerificationType(bin_result.verification_type)
449463
if bin_result.verification_type
450464
else None,
465+
stdout=xml_result.stdout,
451466
)
452467
)
453468

codeflash/verification/test_results.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,7 @@ class FunctionTestInvocation:
8787
return_value: Optional[object] # The return value of the function invocation
8888
timed_out: Optional[bool]
8989
verification_type: Optional[str] = VerificationType.FUNCTION_CALL
90+
stdout: Optional[str] = None
9091

9192
@property
9293
def unique_invocation_loop_id(self) -> str:

pyproject.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,8 @@ ignore = [
175175
"TD002",
176176
"TD003",
177177
"TD004",
178-
"PLR2004"
178+
"PLR2004",
179+
"UP007" # remove once we drop 3.9 support.
179180
]
180181

181182
[tool.ruff.lint.flake8-type-checking]

0 commit comments

Comments
 (0)