(self)
| 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(): |
nothing calls this directly
no test coverage detected