summaryrefslogtreecommitdiffstats
path: root/Lib/test/test_code_module.py
diff options
context:
space:
mode:
authorR David Murray <rdmurray@bitdance.com>2014-09-29 15:25:00 (GMT)
committerR David Murray <rdmurray@bitdance.com>2014-09-29 15:25:00 (GMT)
commitc31e6227f94c2bb0290336c739873173672a8991 (patch)
treed0ae5b35cf326fa9605608f0860d6789bc115d78 /Lib/test/test_code_module.py
parent4d75a01798cf0ff112335804382bd4bf50f7bf78 (diff)
downloadcpython-c31e6227f94c2bb0290336c739873173672a8991.zip
cpython-c31e6227f94c2bb0290336c739873173672a8991.tar.gz
cpython-c31e6227f94c2bb0290336c739873173672a8991.tar.bz2
#17442: Add chained traceback support to InteractiveInterpreter.
Patch by Claudiu Popa.
Diffstat (limited to 'Lib/test/test_code_module.py')
-rw-r--r--Lib/test/test_code_module.py35
1 files changed, 35 insertions, 0 deletions
diff --git a/Lib/test/test_code_module.py b/Lib/test/test_code_module.py
index 7a80a80..9b17767 100644
--- a/Lib/test/test_code_module.py
+++ b/Lib/test/test_code_module.py
@@ -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)