Show More
@@ -9,6 +9,7 b' from IPython.testing import tools as tt' | |||
|
9 | 9 | from IPython.testing.decorators import onlyif_unicode_paths |
|
10 | 10 | from IPython.utils.syspathcontext import prepended_to_syspath |
|
11 | 11 | from IPython.utils.tempdir import TemporaryDirectory |
|
12 | from IPython.utils.py3compat import PY3 | |
|
12 | 13 | |
|
13 | 14 | ip = get_ipython() |
|
14 | 15 | |
@@ -147,3 +148,37 b' class SyntaxErrorTest(unittest.TestCase):' | |||
|
147 | 148 | except ValueError: |
|
148 | 149 | with tt.AssertPrints('QWERTY'): |
|
149 | 150 | ip.showsyntaxerror() |
|
151 | ||
|
152 | ||
|
153 | class Python3ChainedExceptionsTest(unittest.TestCase): | |
|
154 | DIRECT_CAUSE_ERROR_CODE = """ | |
|
155 | try: | |
|
156 | x = 1 + 2 | |
|
157 | print(not_defined_here) | |
|
158 | except Exception as e: | |
|
159 | x += 55 | |
|
160 | x - 1 | |
|
161 | y = {} | |
|
162 | raise KeyError('uh') from e | |
|
163 | """ | |
|
164 | ||
|
165 | EXCEPTION_DURING_HANDLING_CODE = """ | |
|
166 | try: | |
|
167 | x = 1 + 2 | |
|
168 | print(not_defined_here) | |
|
169 | except Exception as e: | |
|
170 | x += 55 | |
|
171 | x - 1 | |
|
172 | y = {} | |
|
173 | raise KeyError('uh') | |
|
174 | """ | |
|
175 | ||
|
176 | def test_direct_cause_error(self): | |
|
177 | if PY3: | |
|
178 | with tt.AssertPrints(["KeyError", "NameError", "direct cause"]): | |
|
179 | ip.run_cell(self.DIRECT_CAUSE_ERROR_CODE) | |
|
180 | ||
|
181 | def test_exception_during_handling_error(self): | |
|
182 | if PY3: | |
|
183 | with tt.AssertPrints(["KeyError", "NameError", "During handling"]): | |
|
184 | ip.run_cell(self.EXCEPTION_DURING_HANDLING_CODE) |
General Comments 0
You need to be logged in to leave comments.
Login now