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

Method test_summary_should_show_carets

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

Source from the content-addressed store, hash-verified

3569 )
3570
3571 def test_summary_should_show_carets(self):
3572 # See: https://github.com/python/cpython/issues/122353
3573
3574 # statement to execute and to get a ZeroDivisionError for a traceback
3575 statement = "abcdef = 1 / 0 and 2.0"
3576 colno = statement.index('1 / 0')
3577 end_colno = colno + len('1 / 0')
3578
3579 # Actual line to use when rendering the traceback
3580 # and whose AST will be extracted (it will be empty).
3581 cached_line = '# this line will be used during rendering'
3582 self.addCleanup(unlink, TESTFN)
3583 with open(TESTFN, "w") as file:
3584 file.write(cached_line)
3585 linecache.updatecache(TESTFN, {})
3586
3587 try:
3588 exec(compile(statement, TESTFN, "exec"))
3589 except ZeroDivisionError as exc:
3590 # This is the simplest way to create a StackSummary
3591 # whose FrameSummary items have their column offsets.
3592 s = traceback.TracebackException.from_exception(exc).stack
3593 self.assertIsInstance(s, traceback.StackSummary)
3594 with unittest.mock.patch.object(s, '_should_show_carets',
3595 wraps=s._should_show_carets) as ff:
3596 self.assertEqual(len(s), 2)
3597 self.assertListEqual(
3598 s.format_frame_summary(s[1]).splitlines(),
3599 [
3600 f' File "{TESTFN}", line 1, in <module>',
3601 f' {cached_line}'
3602 ]
3603 )
3604 ff.assert_called_with(colno, end_colno, [cached_line], None)
3605
3606class Unrepresentable:
3607 def __repr__(self) -> str:

Callers

nothing calls this directly

Calls 14

lenFunction · 0.85
addCleanupMethod · 0.80
from_exceptionMethod · 0.80
assertIsInstanceMethod · 0.80
assertListEqualMethod · 0.80
assert_called_withMethod · 0.80
openFunction · 0.50
execFunction · 0.50
compileFunction · 0.50
indexMethod · 0.45
writeMethod · 0.45
assertEqualMethod · 0.45

Tested by

no test coverage detected