mirror of
https://github.com/python/cpython.git
synced 2025-10-08 08:01:55 +00:00
#17442: Add chained traceback support to InteractiveInterpreter.
Patch by Claudiu Popa.
This commit is contained in:
parent
4d75a01798
commit
c31e6227f9
5 changed files with 70 additions and 12 deletions
|
@ -1,6 +1,7 @@
|
|||
"Test InteractiveConsole and InteractiveInterpreter from code module"
|
||||
import sys
|
||||
import unittest
|
||||
from textwrap import dedent
|
||||
from contextlib import ExitStack
|
||||
from unittest import mock
|
||||
from test import support
|
||||
|
@ -78,6 +79,40 @@ class TestInteractiveConsole(unittest.TestCase):
|
|||
self.console.interact(banner='')
|
||||
self.assertEqual(len(self.stderr.method_calls), 1)
|
||||
|
||||
def test_cause_tb(self):
|
||||
self.infunc.side_effect = ["raise ValueError('') from AttributeError",
|
||||
EOFError('Finished')]
|
||||
self.console.interact()
|
||||
output = ''.join(''.join(call[1]) for call in self.stderr.method_calls)
|
||||
expected = dedent("""
|
||||
AttributeError
|
||||
|
||||
The above exception was the direct cause of the following exception:
|
||||
|
||||
Traceback (most recent call last):
|
||||
File "<console>", line 1, in <module>
|
||||
ValueError
|
||||
""")
|
||||
self.assertIn(expected, output)
|
||||
|
||||
def test_context_tb(self):
|
||||
self.infunc.side_effect = ["try: ham\nexcept: eggs\n",
|
||||
EOFError('Finished')]
|
||||
self.console.interact()
|
||||
output = ''.join(''.join(call[1]) for call in self.stderr.method_calls)
|
||||
expected = dedent("""
|
||||
Traceback (most recent call last):
|
||||
File "<console>", line 1, in <module>
|
||||
NameError: name 'ham' is not defined
|
||||
|
||||
During handling of the above exception, another exception occurred:
|
||||
|
||||
Traceback (most recent call last):
|
||||
File "<console>", line 2, in <module>
|
||||
NameError: name 'eggs' is not defined
|
||||
""")
|
||||
self.assertIn(expected, output)
|
||||
|
||||
|
||||
def test_main():
|
||||
support.run_unittest(TestInteractiveConsole)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue