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

Method do_test

Lib/test/test_traceback.py:428–456  ·  view source on GitHub ↗
(firstlines, message, charset, lineno)

Source from the content-addressed store, hash-verified

426 output_encoding = str(stdout, 'ascii').splitlines()[0]
427
428 def do_test(firstlines, message, charset, lineno):
429 # Raise the message in a subprocess, and catch the output
430 try:
431 with open(TESTFN, "w", encoding=charset) as output:
432 output.write("""{0}if 1:
433 import traceback;
434 raise RuntimeError('{1}')
435 """.format(firstlines, message))
436
437 process = subprocess.Popen([sys.executable, TESTFN],
438 stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
439 stdout, stderr = process.communicate()
440 stdout = stdout.decode(output_encoding).splitlines()
441 finally:
442 unlink(TESTFN)
443
444 # The source lines are encoded with the 'backslashreplace' handler
445 encoded_message = message.encode(output_encoding,
446 'backslashreplace')
447 # and we just decoded them with the output_encoding.
448 message_ascii = encoded_message.decode(output_encoding)
449
450 err_line = "raise RuntimeError('{0}')".format(message_ascii)
451 err_msg = "RuntimeError: {0}".format(message_ascii)
452
453 self.assertIn("line %s" % lineno, stdout[1])
454 self.assertEndsWith(stdout[2], err_line)
455 actual_err_msg = stdout[3]
456 self.assertEqual(actual_err_msg, err_msg)
457
458 do_test("", "foo", "ascii", 3)
459 for charset in ("ascii", "iso-8859-1", "utf-8", "GBK"):

Callers

nothing calls this directly

Calls 11

communicateMethod · 0.95
unlinkFunction · 0.90
assertInMethod · 0.80
openFunction · 0.50
writeMethod · 0.45
formatMethod · 0.45
splitlinesMethod · 0.45
decodeMethod · 0.45
encodeMethod · 0.45
assertEndsWithMethod · 0.45
assertEqualMethod · 0.45

Tested by

no test coverage detected