Skip to content

Commit 06137a8

Browse files
committed
Revert "stdout comparison"
oops, used to our internal protection rules. This reverts commit a441dfd.
1 parent a441dfd commit 06137a8

File tree

4 files changed

+14
-44
lines changed

4 files changed

+14
-44
lines changed

codeflash/verification/equivalence.py

Lines changed: 0 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,10 @@
1-
import re
21
import sys
32

43
from codeflash.cli_cmds.console import logger
54
from codeflash.verification.comparator import comparator
65
from codeflash.verification.test_results import TestResults, TestType, VerificationType
76

87
INCREASED_RECURSION_LIMIT = 5000
9-
percentage_pattern = re.compile(r"\.\s+\[\d+%\]")
10-
passed_pattern = re.compile(r"\d+\s+passed\s+in\s+\d+\.\d+s")
11-
not_allowed = {"test", "codeflash"}
12-
13-
14-
def cleanup_stdout(stdout: str) -> str:
15-
return (
16-
"\n".join(
17-
line
18-
for line in stdout.splitlines()
19-
if not any(word in line for word in not_allowed)
20-
and not percentage_pattern.search(line)
21-
and not passed_pattern.search(line)
22-
)
23-
+ "\n"
24-
)
258

269

2710
def compare_test_results(original_results: TestResults, candidate_results: TestResults) -> bool:
@@ -39,7 +22,6 @@ def compare_test_results(original_results: TestResults, candidate_results: TestR
3922
for test_id in test_ids_superset:
4023
original_test_result = original_results.get_by_unique_invocation_loop_id(test_id)
4124
cdd_test_result = candidate_results.get_by_unique_invocation_loop_id(test_id)
42-
4325
if cdd_test_result is not None and original_test_result is None:
4426
continue
4527
# If helper function instance_state verification is not present, that's ok. continue
@@ -84,10 +66,6 @@ def compare_test_results(original_results: TestResults, candidate_results: TestR
8466
):
8567
are_equal = False
8668
break
87-
if not comparator(cleanup_stdout(original_test_result.stdout), cleanup_stdout(cdd_test_result.stdout)):
88-
are_equal = False
89-
break
90-
9169
sys.setrecursionlimit(original_recursion_limit)
9270
if did_all_timeout:
9371
return False

codeflash/verification/parse_test_output.py

Lines changed: 11 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@
3939
def parse_func(file_path: Path) -> XMLParser:
4040
"""Parse the XML file with lxml.etree.XMLParser as the backend."""
4141
xml_parser = XMLParser(huge_tree=True)
42-
return parse(file_path, xml_parser) # type: ignore # noqa: PGH003, S320
42+
return parse(file_path, xml_parser)
4343

4444

4545
def parse_test_return_values_bin(file_location: Path, test_files: TestFiles, test_config: TestConfig) -> TestResults:
@@ -259,10 +259,6 @@ def parse_test_xml(
259259
message = testcase.result[0].message.lower()
260260
if "timed out" in message:
261261
timed_out = True
262-
263-
stdout = run_result.stdout if run_result and run_result.stdout else None
264-
stderr = run_result.stderr if run_result and run_result.stderr else None
265-
266262
matches = re.findall(r"!######(.*?):(.*?)([^\.:]*?):(.*?):(.*?):(.*?)######!", testcase.system_out or "")
267263
if not matches or not len(matches):
268264
test_results.add(
@@ -282,10 +278,9 @@ def parse_test_xml(
282278
test_type=test_type,
283279
return_value=None,
284280
timed_out=timed_out,
285-
stdout=stdout,
286-
stderr=stderr,
287281
)
288282
)
283+
289284
else:
290285
for match in matches:
291286
split_val = match[5].split(":")
@@ -311,17 +306,21 @@ def parse_test_xml(
311306
test_type=test_type,
312307
return_value=None,
313308
timed_out=timed_out,
314-
stdout=stdout,
315-
stderr=stderr,
316309
)
317310
)
318311

319312
if not test_results:
320313
logger.info(
321314
f"Tests '{[test_file.original_file_path for test_file in test_files.test_files]}' failed to run, skipping"
322315
)
323-
stdout, stderr = run_result.stdout, run_result.stderr
324-
logger.debug(f"Test log - STDOUT : {stdout} \n STDERR : {stderr}")
316+
if run_result is not None:
317+
stdout, stderr = "", ""
318+
try:
319+
stdout = run_result.stdout.decode()
320+
stderr = run_result.stderr.decode()
321+
except AttributeError:
322+
stdout = run_result.stderr
323+
logger.debug(f"Test log - STDOUT : {stdout} \n STDERR : {stderr}")
325324
return test_results
326325

327326

@@ -336,11 +335,7 @@ def merge_test_results(
336335
# This is done to match the right iteration_id which might not be available in the xml
337336
for result in xml_test_results:
338337
if test_framework == "pytest":
339-
if (
340-
result.id.test_function_name
341-
and result.id.test_function_name.endswith("]")
342-
and "[" in result.id.test_function_name
343-
): # parameterized test
338+
if result.id.test_function_name.endswith("]") and "[" in result.id.test_function_name: # parameterized test
344339
test_function_name = result.id.test_function_name[: result.id.test_function_name.index("[")]
345340
else:
346341
test_function_name = result.id.test_function_name

codeflash/verification/test_results.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -85,10 +85,8 @@ class FunctionTestInvocation:
8585
test_framework: str # unittest or pytest
8686
test_type: TestType
8787
return_value: Optional[object] # The return value of the function invocation
88-
time_out: Optional[bool]
89-
verification_type: Optional[VerificationType] = VerificationType.FUNCTION_CALL
90-
stdout: Optional[str] = None
91-
stderr: Optional[str] = None
88+
timed_out: Optional[bool]
89+
verification_type: Optional[str] = VerificationType.FUNCTION_CALL
9290

9391
@property
9492
def unique_invocation_loop_id(self) -> str:

pyproject.toml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -174,8 +174,7 @@ ignore = [
174174
"TD002",
175175
"TD003",
176176
"TD004",
177-
"PLR2004",
178-
"UP007" # remove once we drop 3.9 support.
177+
"PLR2004"
179178
]
180179

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

0 commit comments

Comments
 (0)