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

Method test_colorized_traceback

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

Source from the content-addressed store, hash-verified

5275 maxDiff = None
5276
5277 def test_colorized_traceback(self):
5278 def foo(*args):
5279 x = {'a':{'b': None}}
5280 y = x['a']['b']['c']
5281
5282 def baz2(*args):
5283 return (lambda *args: foo(*args))(1,2,3,4)
5284
5285 def baz1(*args):
5286 return baz2(1,2,3,4)
5287
5288 def bar():
5289 return baz1(1,
5290 2,3
5291 ,4)
5292 try:
5293 bar()
5294 except Exception as e:
5295 exc = traceback.TracebackException.from_exception(
5296 e, capture_locals=True
5297 )
5298 lines = "".join(exc.format(colorize=True))
5299 red = colors["e"]
5300 boldr = colors["E"]
5301 reset = colors["z"]
5302 self.assertIn("y = " + red + "x['a']['b']" + reset + boldr + "['c']" + reset, lines)
5303 self.assertIn("return " + red + "(lambda *args: foo(*args))" + reset + boldr + "(1,2,3,4)" + reset, lines)
5304 self.assertIn("return (lambda *args: " + red + "foo" + reset + boldr + "(*args)" + reset + ")(1,2,3,4)", lines)
5305 self.assertIn("return baz2(1,2,3,4)", lines)
5306 self.assertIn("return baz1(1,\n 2,3\n ,4)", lines)
5307 self.assertIn(red + "bar" + reset + boldr + "()" + reset, lines)
5308
5309 def test_colorized_exception_notes(self):
5310 def foo():

Callers

nothing calls this directly

Calls 5

from_exceptionMethod · 0.80
assertInMethod · 0.80
barFunction · 0.50
joinMethod · 0.45
formatMethod · 0.45

Tested by

no test coverage detected