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