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

Method test_summary_should_show_carets

Lib/test/test_traceback.py:3493–3526  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

3491 )
3492
3493 def test_summary_should_show_carets(self):
3494 # See: https://github.com/python/cpython/issues/122353
3495
3496 # statement to execute and to get a ZeroDivisionError for a traceback
3497 statement = "abcdef = 1 / 0 and 2.0"
3498 colno = statement.index('1 / 0')
3499 end_colno = colno + len('1 / 0')
3500
3501 # Actual line to use when rendering the traceback
3502 # and whose AST will be extracted (it will be empty).
3503 cached_line = '# this line will be used during rendering'
3504 self.addCleanup(unlink, TESTFN)
3505 with open(TESTFN, "w") as file:
3506 file.write(cached_line)
3507 linecache.updatecache(TESTFN, {})
3508
3509 try:
3510 exec(compile(statement, TESTFN, "exec"))
3511 except ZeroDivisionError as exc:
3512 # This is the simplest way to create a StackSummary
3513 # whose FrameSummary items have their column offsets.
3514 s = traceback.TracebackException.from_exception(exc).stack
3515 self.assertIsInstance(s, traceback.StackSummary)
3516 with unittest.mock.patch.object(s, '_should_show_carets',
3517 wraps=s._should_show_carets) as ff:
3518 self.assertEqual(len(s), 2)
3519 self.assertListEqual(
3520 s.format_frame_summary(s[1]).splitlines(),
3521 [
3522 f' File "{TESTFN}", line 1, in <module>',
3523 f' {cached_line}'
3524 ]
3525 )
3526 ff.assert_called_with(colno, end_colno, [cached_line], None)
3527
3528class Unrepresentable:
3529 def __repr__(self) -> str:

Callers

nothing calls this directly

Calls 12

addCleanupMethod · 0.80
from_exceptionMethod · 0.80
assertIsInstanceMethod · 0.80
assertListEqualMethod · 0.80
assert_called_withMethod · 0.80
openFunction · 0.50
compileFunction · 0.50
indexMethod · 0.45
writeMethod · 0.45
assertEqualMethod · 0.45
splitlinesMethod · 0.45
format_frame_summaryMethod · 0.45

Tested by

no test coverage detected