Show More
@@ -1,75 +1,95 b'' | |||
|
1 | 1 | # encoding: utf-8 |
|
2 | 2 | """Tests for IPython.core.ultratb |
|
3 | 3 | """ |
|
4 | 4 | import io |
|
5 | 5 | import os.path |
|
6 | 6 | import unittest |
|
7 | 7 | |
|
8 | 8 | from IPython.testing import tools as tt |
|
9 | 9 | from IPython.utils.syspathcontext import prepended_to_syspath |
|
10 | 10 | from IPython.utils.tempdir import TemporaryDirectory |
|
11 | 11 | |
|
12 | 12 | ip = get_ipython() |
|
13 | 13 | |
|
14 | 14 | file_1 = """1 |
|
15 | 15 | 2 |
|
16 | 16 | 3 |
|
17 | 17 | def f(): |
|
18 | 18 | 1/0 |
|
19 | 19 | """ |
|
20 | 20 | |
|
21 | 21 | file_2 = """def f(): |
|
22 | 22 | 1/0 |
|
23 | 23 | """ |
|
24 | 24 | |
|
25 | 25 | class ChangedPyFileTest(unittest.TestCase): |
|
26 | 26 | def test_changing_py_file(self): |
|
27 | 27 | """Traceback produced if the line where the error occurred is missing? |
|
28 | 28 | |
|
29 | 29 | https://github.com/ipython/ipython/issues/1456 |
|
30 | 30 | """ |
|
31 | 31 | with TemporaryDirectory() as td: |
|
32 | 32 | fname = os.path.join(td, "foo.py") |
|
33 | 33 | with open(fname, "w") as f: |
|
34 | 34 | f.write(file_1) |
|
35 | 35 | |
|
36 | 36 | with prepended_to_syspath(td): |
|
37 | 37 | ip.run_cell("import foo") |
|
38 | 38 | |
|
39 | 39 | with tt.AssertPrints("ZeroDivisionError"): |
|
40 | 40 | ip.run_cell("foo.f()") |
|
41 | 41 | |
|
42 | 42 | # Make the file shorter, so the line of the error is missing. |
|
43 | 43 | with open(fname, "w") as f: |
|
44 | 44 | f.write(file_2) |
|
45 | 45 | |
|
46 | 46 | # For some reason, this was failing on the *second* call after |
|
47 | 47 | # changing the file, so we call f() twice. |
|
48 | 48 | with tt.AssertNotPrints("Internal Python error", channel='stderr'): |
|
49 | 49 | with tt.AssertPrints("ZeroDivisionError"): |
|
50 | 50 | ip.run_cell("foo.f()") |
|
51 | 51 | with tt.AssertPrints("ZeroDivisionError"): |
|
52 | 52 | ip.run_cell("foo.f()") |
|
53 | 53 | |
|
54 | 54 | iso_8859_5_file = u'''# coding: iso-8859-5 |
|
55 | 55 | |
|
56 | 56 | def fail(): |
|
57 | 57 | """дбИЖ""" |
|
58 | 58 | 1/0 # дбИЖ |
|
59 | 59 | ''' |
|
60 | 60 | |
|
61 | 61 | class NonAsciiTest(unittest.TestCase): |
|
62 | 62 | def test_iso8859_5(self): |
|
63 | 63 | # Non-ascii directory name as well. |
|
64 | 64 | with TemporaryDirectory(suffix=u'é') as td: |
|
65 | 65 | fname = os.path.join(td, 'dfghjkl.py') |
|
66 | 66 | |
|
67 | 67 | with io.open(fname, 'w', encoding='iso-8859-5') as f: |
|
68 | 68 | f.write(iso_8859_5_file) |
|
69 | 69 | |
|
70 | 70 | with prepended_to_syspath(td): |
|
71 | 71 | ip.run_cell("from dfghjkl import fail") |
|
72 | 72 | |
|
73 | 73 | with tt.AssertPrints("ZeroDivisionError"): |
|
74 | 74 | with tt.AssertPrints(u'дбИЖ', suppress=False): |
|
75 | 75 | ip.run_cell('fail()') |
|
76 | ||
|
77 | indentationerror_file = """if True: | |
|
78 | zoon() | |
|
79 | """ | |
|
80 | ||
|
81 | class IndentationErrorTest(unittest.TestCase): | |
|
82 | def test_indentationerror_shows_line(self): | |
|
83 | # See issue gh-2398 | |
|
84 | with tt.AssertPrints("IndentationError"): | |
|
85 | with tt.AssertPrints("zoon()", suppress=False): | |
|
86 | ip.run_cell(indentationerror_file) | |
|
87 | ||
|
88 | with TemporaryDirectory() as td: | |
|
89 | fname = os.path.join(td, "foo.py") | |
|
90 | with open(fname, "w") as f: | |
|
91 | f.write(indentationerror_file) | |
|
92 | ||
|
93 | with tt.AssertPrints("IndentationError"): | |
|
94 | with tt.AssertPrints("zoon()", suppress=False): | |
|
95 | ip.magic('run %s' % fname) |
General Comments 0
You need to be logged in to leave comments.
Login now