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

Method test_format_exception

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

Source from the content-addressed store, hash-verified

3313 self.assertEqual(extract(), [])
3314
3315 def test_format_exception(self):
3316 try:
3317 self.last_raises5()
3318 except Exception as e:
3319 exc = e
3320 # [1:-1] to exclude "Traceback (...)" header and
3321 # exception type and value
3322 def extract(**kwargs):
3323 return traceback.format_exception(exc, **kwargs)[1:-1]
3324
3325 with support.swap_attr(sys, 'tracebacklimit', 1000):
3326 nolim = extract()
3327 self.assertEqual(len(nolim), 5+1)
3328 self.assertEqual(extract(limit=2), nolim[:2])
3329 self.assertEqual(extract(limit=10), nolim)
3330 self.assertEqual(extract(limit=-2), nolim[-2:])
3331 self.assertEqual(extract(limit=-10), nolim)
3332 self.assertEqual(extract(limit=0), [])
3333 del sys.tracebacklimit
3334 self.assertEqual(extract(), nolim)
3335 sys.tracebacklimit = 2
3336 self.assertEqual(extract(), nolim[:2])
3337 self.assertEqual(extract(limit=3), nolim[:3])
3338 self.assertEqual(extract(limit=-3), nolim[-3:])
3339 sys.tracebacklimit = 0
3340 self.assertEqual(extract(), [])
3341 sys.tracebacklimit = -1
3342 self.assertEqual(extract(), [])
3343
3344
3345class MiscTracebackCases(unittest.TestCase):

Callers

nothing calls this directly

Calls 4

last_raises5Method · 0.95
extractFunction · 0.85
lenFunction · 0.85
assertEqualMethod · 0.45

Tested by

no test coverage detected