Show More
@@ -1,51 +1,51 b'' | |||||
1 | #!/usr/bin/env python |
|
1 | #!/usr/bin/env python | |
2 | # coding: utf-8 |
|
2 | # coding: utf-8 | |
3 | """These tests have to be run separately from the main test suite (iptest), |
|
3 | """These tests have to be run separately from the main test suite (iptest), | |
4 | because that sets the default encoding to utf-8, and it cannot be changed after |
|
4 | because that sets the default encoding to utf-8, and it cannot be changed after | |
5 | the interpreter is up and running. The default encoding in a Python 2.x |
|
5 | the interpreter is up and running. The default encoding in a Python 2.x | |
6 | environment is ASCII.""" |
|
6 | environment is ASCII.""" | |
7 | import unittest |
|
7 | import unittest | |
8 | import sys, os.path |
|
8 | import sys, os.path | |
9 |
|
9 | |||
10 | from IPython.core import ipapi |
|
10 | from IPython.core import ipapi | |
11 | from IPython.core import compilerop |
|
11 | from IPython.core import compilerop | |
12 | from IPython.core.history import HistoryManager |
|
12 | from IPython.core.history import HistoryManager | |
13 | from IPython.utils.tempdir import TemporaryDirectory |
|
13 | from IPython.utils.tempdir import TemporaryDirectory | |
14 |
|
14 | |||
15 | assert sys.getdefaultencoding() == "ascii" |
|
15 | assert sys.getdefaultencoding() == "ascii" | |
16 |
|
16 | |||
17 | class CompileropTest(unittest.TestCase): |
|
17 | class CompileropTest(unittest.TestCase): | |
18 | def test_accept_unicode(self): |
|
18 | def test_accept_unicode(self): | |
19 | cp = compilerop.CachingCompiler() |
|
19 | cp = compilerop.CachingCompiler() | |
20 | cp(u"t = 'žćčšđ'", "single") |
|
20 | cp(u"t = 'žćčšđ'", "single") | |
21 |
|
21 | |||
22 | class HistoryTest(unittest.TestCase): |
|
22 | class HistoryTest(unittest.TestCase): | |
23 | def test_reload_unicode(self): |
|
23 | def test_reload_unicode(self): | |
24 | ip = ipapi.get() |
|
24 | ip = ipapi.get() | |
25 | with TemporaryDirectory() as tmpdir: |
|
25 | with TemporaryDirectory() as tmpdir: | |
26 | histfile = os.path.realpath(os.path.join(tmpdir, 'history.json')) |
|
26 | histfile = os.path.realpath(os.path.join(tmpdir, 'history.json')) | |
27 | # Ensure that we restore the history management that we mess with in |
|
27 | # Ensure that we restore the history management that we mess with in | |
28 |
# this test doesn't affect the IPython instance used by the test |
|
28 | # this test doesn't affect the IPython instance used by the test | |
29 | # beyond this test. |
|
29 | # suite beyond this test. | |
30 | hist_manager_ori = ip.history_manager |
|
30 | hist_manager_ori = ip.history_manager | |
31 | try: |
|
31 | try: | |
32 | ip.history_manager = HistoryManager(ip) |
|
32 | ip.history_manager = HistoryManager(ip) | |
33 | ip.history_manager.hist_file = histfile |
|
33 | ip.history_manager.hist_file = histfile | |
34 | print 'test',histfile |
|
34 | print 'test',histfile | |
35 | hist = [u"t = 'žćčšđ'"] |
|
35 | hist = [u"t = 'žćčšđ'"] | |
36 | # test save and load |
|
36 | # test save and load | |
37 | ip.history_manager.input_hist_raw[:] = [] |
|
37 | ip.history_manager.input_hist_raw[:] = [] | |
38 | for h in hist: |
|
38 | for h in hist: | |
39 | ip.history_manager.input_hist_raw.append(h) |
|
39 | ip.history_manager.input_hist_raw.append(h) | |
40 | ip.save_history() |
|
40 | ip.save_history() | |
41 | ip.history_manager.input_hist_raw[:] = [] |
|
41 | ip.history_manager.input_hist_raw[:] = [] | |
42 | ip.reload_history() |
|
42 | ip.reload_history() | |
43 |
self.assert |
|
43 | self.assertEqual(len(ip.history_manager.input_hist_raw), len(hist)) | |
44 | for i,h in enumerate(hist): |
|
44 | for i,h in enumerate(hist): | |
45 |
|
|
45 | self.assertEqual(hist[i], ip.history_manager.input_hist_raw[i]) | |
46 | finally: |
|
46 | finally: | |
47 | # Restore history manager |
|
47 | # Restore history manager | |
48 | ip.history_manager = hist_manager_ori |
|
48 | ip.history_manager = hist_manager_ori | |
49 |
|
49 | |||
50 | if __name__ == "__main__": |
|
50 | if __name__ == "__main__": | |
51 | unittest.main() |
|
51 | unittest.main() |
General Comments 0
You need to be logged in to leave comments.
Login now