From 3366f80f854ba75e00da2f44b18c1acf6a08ac1a 2014-07-07 05:10:29 From: Justyna Ilczuk Date: 2014-07-07 05:10:29 Subject: [PATCH] i1673 add tests for python3 exceptions --- diff --git a/IPython/core/tests/test_ultratb.py b/IPython/core/tests/test_ultratb.py index 07c9ba5..c823d76 100644 --- a/IPython/core/tests/test_ultratb.py +++ b/IPython/core/tests/test_ultratb.py @@ -9,6 +9,7 @@ from IPython.testing import tools as tt from IPython.testing.decorators import onlyif_unicode_paths from IPython.utils.syspathcontext import prepended_to_syspath from IPython.utils.tempdir import TemporaryDirectory +from IPython.utils.py3compat import PY3 ip = get_ipython() @@ -147,3 +148,37 @@ class SyntaxErrorTest(unittest.TestCase): except ValueError: with tt.AssertPrints('QWERTY'): ip.showsyntaxerror() + + +class Python3ChainedExceptionsTest(unittest.TestCase): + DIRECT_CAUSE_ERROR_CODE = """ +try: + x = 1 + 2 + print(not_defined_here) +except Exception as e: + x += 55 + x - 1 + y = {} + raise KeyError('uh') from e + """ + + EXCEPTION_DURING_HANDLING_CODE = """ +try: + x = 1 + 2 + print(not_defined_here) +except Exception as e: + x += 55 + x - 1 + y = {} + raise KeyError('uh') + """ + + def test_direct_cause_error(self): + if PY3: + with tt.AssertPrints(["KeyError", "NameError", "direct cause"]): + ip.run_cell(self.DIRECT_CAUSE_ERROR_CODE) + + def test_exception_during_handling_error(self): + if PY3: + with tt.AssertPrints(["KeyError", "NameError", "During handling"]): + ip.run_cell(self.EXCEPTION_DURING_HANDLING_CODE)