MCPcopy Index your code
hub / github.com/python/cpython / check_script_error

Method check_script_error

Lib/test/test_source_encoding.py:527–541  ·  view source on GitHub ↗
(self, src, expected, lineno=...)

Source from the content-addressed store, hash-verified

525 self.assertEqual(res.out.rstrip(), expected)
526
527 def check_script_error(self, src, expected, lineno=...):
528 with tempfile.TemporaryDirectory() as tmpd:
529 fn = os.path.join(tmpd, 'test.py')
530 with open(fn, 'wb') as fp:
531 fp.write(src)
532 res = script_helper.assert_python_failure(fn)
533 err = res.err.rstrip()
534 self.assertRegex(err.splitlines()[-1], b'SyntaxError: ' + expected)
535 if lineno is not ...:
536 self.assertIn(f', line {lineno}\n'.encode(),
537 err.replace(os.linesep.encode(), b'\n'))
538 line = src.splitlines()[lineno-1].decode(errors='replace')
539 if lineno == 1:
540 line = line.removeprefix('\ufeff')
541 self.assertIn(line.encode(), err)
542
543
544

Calls 12

assert_python_failureMethod · 0.80
assertRegexMethod · 0.80
assertInMethod · 0.80
openFunction · 0.50
joinMethod · 0.45
writeMethod · 0.45
rstripMethod · 0.45
splitlinesMethod · 0.45
encodeMethod · 0.45
replaceMethod · 0.45
decodeMethod · 0.45
removeprefixMethod · 0.45

Tested by

no test coverage detected