MCPcopy
hub / github.com/sqlalchemy/sqlalchemy / _check_output

Method _check_output

lib/sqlalchemy/testing/fixtures/mypy.py:178–247  ·  view source on GitHub ↗
(
        self, path, expected_messages, stdout: str, stderr, exitcode
    )

Source from the content-addressed store, hash-verified

176 return expected_messages
177
178 def _check_output(
179 self, path, expected_messages, stdout: str, stderr, exitcode
180 ):
181 not_located = []
182 filename = os.path.basename(path)
183 if expected_messages:
184 # mypy 0.990 changed how return codes work, so don't assume a
185 # 1 or a 0 return code here, could be either depending on if
186 # errors were generated or not
187
188 output = []
189
190 raw_lines = stdout.split("\n")
191 while raw_lines:
192 e = raw_lines.pop(0)
193 if re.match(r".+\.py:\d+: error: .*", e):
194 output.append(("error", e))
195 elif re.match(
196 r".+\.py:\d+: note: +(?:Possible overload|def ).*", e
197 ):
198 while raw_lines:
199 ol = raw_lines.pop(0)
200 if not re.match(r".+\.py:\d+: note: +def .*", ol):
201 raw_lines.insert(0, ol)
202 break
203 elif re.match(
204 r".+\.py:\d+: note: .*(?:perhaps|suggestion)", e, re.I
205 ):
206 pass
207 elif re.match(r".+\.py:\d+: note: .*", e):
208 output.append(("note", e))
209
210 for num, is_mypy, is_re, msg in expected_messages:
211 msg = msg.replace("'", '"')
212 prefix = "[SQLAlchemy Mypy plugin] " if not is_mypy else ""
213 for idx, (typ, errmsg) in enumerate(output):
214 if is_re:
215 if re.match(
216 rf".*{filename}\:{num}\: {typ}\: {prefix}{msg}",
217 errmsg,
218 ):
219 break
220 elif (
221 f"{filename}:{num}: {typ}: {prefix}{msg}"
222 in errmsg.replace("'", '"')
223 ):
224 break
225 else:
226 not_located.append(msg)
227 continue
228 del output[idx]
229
230 if not_located:
231 missing = "\n".join(not_located)
232 print("Couldn't locate expected messages:", missing, sep="\n")
233 if output:
234 extra = "\n".join(msg for _, msg in output)
235 print("Remaining messages:", extra, sep="\n")

Callers 1

runMethod · 0.95

Calls 8

eq_Function · 0.85
splitMethod · 0.80
popMethod · 0.45
matchMethod · 0.45
appendMethod · 0.45
insertMethod · 0.45
replaceMethod · 0.45
joinMethod · 0.45

Tested by

no test coverage detected