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