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