MCPcopy Index your code
hub / github.com/RustPython/RustPython / parse_results

Function parse_results

scripts/update_lib/cmd_auto_mark.py:87–172  ·  view source on GitHub ↗

Parse subprocess result into TestResult.

(result: subprocess.CompletedProcess)

Source from the content-addressed store, hash-verified

85
86
87def parse_results(result: subprocess.CompletedProcess) -> TestResult:
88 """Parse subprocess result into TestResult."""
89 lines = result.stdout.splitlines()
90 test_results = TestResult()
91 test_results.stdout = result.stdout
92 in_test_results = False
93 # For multiline format: "test_name (path)\ndocstring ... RESULT"
94 pending_test_info = None
95
96 for line in lines:
97 if re.search(r"Run \d+ tests? sequentially", line):
98 in_test_results = True
99 elif "== Tests result: " in line:
100 in_test_results = False
101
102 if in_test_results and " ... " in line:
103 stripped = line.strip()
104 # Skip lines that don't look like test results
105 if stripped.startswith("tests") or stripped.startswith("["):
106 pending_test_info = None
107 continue
108 # Parse: "test_name (path) [subtest] ... RESULT"
109 parts = stripped.split(" ... ")
110 if len(parts) >= 2:
111 test_info = parts[0]
112 result_str = parts[-1].lower()
113 # Only process FAIL or ERROR
114 if result_str not in ("fail", "error"):
115 pending_test_info = None
116 continue
117 # Try parsing from this line (single-line format)
118 parsed = _try_parse_test_info(test_info)
119 if not parsed and pending_test_info:
120 # Multiline format: previous line had test_name (path)
121 parsed = _try_parse_test_info(pending_test_info)
122 if parsed:
123 test = Test()
124 test.name, test.path = parsed
125 test.result = result_str
126 test_results.tests.append(test)
127 pending_test_info = None
128
129 elif in_test_results:
130 # Track test info for multiline format:
131 # test_name (path)
132 # docstring ... RESULT
133 stripped = line.strip()
134 if (
135 stripped
136 and "(" in stripped
137 and stripped.endswith(")")
138 and ":" not in stripped.split("(")[0]
139 ):
140 pending_test_info = stripped
141 else:
142 pending_test_info = None
143
144 # Also check for Tests result on non-" ... " lines

Calls 14

lenFunction · 0.85
_try_parse_test_infoFunction · 0.85
_parse_error_detailsFunction · 0.85
TestResultClass · 0.70
TestClass · 0.70
splitlinesMethod · 0.45
searchMethod · 0.45
stripMethod · 0.45
startswithMethod · 0.45
splitMethod · 0.45
lowerMethod · 0.45
appendMethod · 0.45