##// END OF EJS Templates
skip multiline history tests on windows...
Julian Taylor -
Show More
@@ -1,150 +1,161 b''
1 1 # -*- coding: utf-8 -*-
2 2 """Tests for the key interactiveshell module.
3 3
4 4 Authors
5 5 -------
6 6 * Julian Taylor
7 7 """
8 8 #-----------------------------------------------------------------------------
9 9 # Copyright (C) 2011 The IPython Development Team
10 10 #
11 11 # Distributed under the terms of the BSD License. The full license is in
12 12 # the file COPYING, distributed as part of this software.
13 13 #-----------------------------------------------------------------------------
14 14
15 15 #-----------------------------------------------------------------------------
16 16 # Imports
17 17 #-----------------------------------------------------------------------------
18 18 # stdlib
19 19 import unittest
20 20
21 21 from IPython.testing.decorators import skipif
22 22
23 23 class InteractiveShellTestCase(unittest.TestCase):
24 24 def rl_hist_entries(self, rl, n):
25 25 """Get last n readline history entries as a list"""
26 26 return [rl.get_history_item(rl.get_current_history_length() - x)
27 27 for x in range(n - 1, -1, -1)]
28 28
29 29 def test_runs_without_rl(self):
30 30 """Test that function does not throw without readline"""
31 31 ip = get_ipython()
32 32 ip.has_readline = False
33 33 ip.readline = None
34 34 ip._replace_rlhist_multiline(u'source', 0)
35 35
36 36 @skipif(not get_ipython().has_readline, 'no readline')
37 37 def test_runs_without_remove_history_item(self):
38 38 """Test that function does not throw on windows without
39 39 remove_history_item"""
40 40 ip = get_ipython()
41 if hasattr(ip.readline, 'remove_history_item'):
41 42 del ip.readline.remove_history_item
42 43 ip._replace_rlhist_multiline(u'source', 0)
43 44
44 45 @skipif(not get_ipython().has_readline, 'no readline')
46 @skipif(not hasattr(get_ipython().readline, 'remove_history_item'),
47 'no remove_history_item')
45 48 def test_replace_multiline_hist_disabled(self):
46 49 """Test that multiline replace does nothing if disabled"""
47 50 ip = get_ipython()
48 51 ip.multiline_history = False
49 52
50 53 ghist = [u'line1', u'line2']
51 54 for h in ghist:
52 55 ip.readline.add_history(h)
53 56 hlen_b4_cell = ip.readline.get_current_history_length()
54 57 hlen_b4_cell = ip._replace_rlhist_multiline(u'sourc€\nsource2',
55 58 hlen_b4_cell)
56 59
57 60 self.assertEquals(ip.readline.get_current_history_length(),
58 61 hlen_b4_cell)
59 62 hist = self.rl_hist_entries(ip.readline, 2)
60 63 self.assertEquals(hist, ghist)
61 64
62 65 @skipif(not get_ipython().has_readline, 'no readline')
66 @skipif(not hasattr(get_ipython().readline, 'remove_history_item'),
67 'no remove_history_item')
63 68 def test_replace_multiline_hist_adds(self):
64 69 """Test that multiline replace function adds history"""
65 70 ip = get_ipython()
66 71
67 72 hlen_b4_cell = ip.readline.get_current_history_length()
68 73 hlen_b4_cell = ip._replace_rlhist_multiline(u'sourc€', hlen_b4_cell)
69 74
70 75 self.assertEquals(hlen_b4_cell,
71 76 ip.readline.get_current_history_length())
72 77
73 78 @skipif(not get_ipython().has_readline, 'no readline')
79 @skipif(not hasattr(get_ipython().readline, 'remove_history_item'),
80 'no remove_history_item')
74 81 def test_replace_multiline_hist_keeps_history(self):
75 82 """Test that multiline replace does not delete history"""
76 83 ip = get_ipython()
77 84 ip.multiline_history = True
78 85
79 86 ghist = [u'line1', u'line2']
80 87 for h in ghist:
81 88 ip.readline.add_history(h)
82 89
83 90 #start cell
84 91 hlen_b4_cell = ip.readline.get_current_history_length()
85 92 # nothing added to rl history, should do nothing
86 93 hlen_b4_cell = ip._replace_rlhist_multiline(u'sourc€\nsource2',
87 94 hlen_b4_cell)
88 95
89 96 self.assertEquals(ip.readline.get_current_history_length(),
90 97 hlen_b4_cell)
91 98 hist = self.rl_hist_entries(ip.readline, 2)
92 99 self.assertEquals(hist, ghist)
93 100
94 101
95 102 @skipif(not get_ipython().has_readline, 'no readline')
103 @skipif(not hasattr(get_ipython().readline, 'remove_history_item'),
104 'no remove_history_item')
96 105 def test_replace_multiline_hist_replaces_twice(self):
97 106 """Test that multiline entries are replaced twice"""
98 107 ip = get_ipython()
99 108 ip.multiline_history = True
100 109
101 110 ip.readline.add_history(u'line0')
102 111 #start cell
103 112 hlen_b4_cell = ip.readline.get_current_history_length()
104 113 ip.readline.add_history('l€ne1')
105 114 ip.readline.add_history('line2')
106 115 #replace cell with single line
107 116 hlen_b4_cell = ip._replace_rlhist_multiline(u'l€ne1\nline2',
108 117 hlen_b4_cell)
109 118 ip.readline.add_history('l€ne3')
110 119 ip.readline.add_history('line4')
111 120 #replace cell with single line
112 121 hlen_b4_cell = ip._replace_rlhist_multiline(u'l€ne3\nline4',
113 122 hlen_b4_cell)
114 123
115 124 self.assertEquals(ip.readline.get_current_history_length(),
116 125 hlen_b4_cell)
117 126 hist = self.rl_hist_entries(ip.readline, 3)
118 127 self.assertEquals(hist, ['line0', 'l€ne1\nline2', 'l€ne3\nline4'])
119 128
120 129
121 130 @skipif(not get_ipython().has_readline, 'no readline')
131 @skipif(not hasattr(get_ipython().readline, 'remove_history_item'),
132 'no remove_history_item')
122 133 def test_replace_multiline_hist_replaces_empty_line(self):
123 134 """Test that multiline history skips empty line cells"""
124 135 ip = get_ipython()
125 136 ip.multiline_history = True
126 137
127 138 ip.readline.add_history(u'line0')
128 139 #start cell
129 140 hlen_b4_cell = ip.readline.get_current_history_length()
130 141 ip.readline.add_history('l€ne1')
131 142 ip.readline.add_history('line2')
132 143 hlen_b4_cell = ip._replace_rlhist_multiline(u'l€ne1\nline2',
133 144 hlen_b4_cell)
134 145 ip.readline.add_history('')
135 146 hlen_b4_cell = ip._replace_rlhist_multiline(u'', hlen_b4_cell)
136 147 ip.readline.add_history('l€ne3')
137 148 hlen_b4_cell = ip._replace_rlhist_multiline(u'l€ne3', hlen_b4_cell)
138 149 ip.readline.add_history(' ')
139 150 hlen_b4_cell = ip._replace_rlhist_multiline(' ', hlen_b4_cell)
140 151 ip.readline.add_history('\t')
141 152 ip.readline.add_history('\t ')
142 153 hlen_b4_cell = ip._replace_rlhist_multiline('\t', hlen_b4_cell)
143 154 ip.readline.add_history('line4')
144 155 hlen_b4_cell = ip._replace_rlhist_multiline(u'line4', hlen_b4_cell)
145 156
146 157 self.assertEquals(ip.readline.get_current_history_length(),
147 158 hlen_b4_cell)
148 159 hist = self.rl_hist_entries(ip.readline, 4)
149 160 # expect no empty cells in history
150 161 self.assertEquals(hist, ['line0', 'l€ne1\nline2', 'l€ne3', 'line4'])
General Comments 0
You need to be logged in to leave comments. Login now