Show More
@@ -1,123 +1,105 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') |
|
35 | 35 | |
|
36 | 36 | @skipif(not get_ipython().has_readline, 'no readline') |
|
37 | 37 | def test_replace_multiline_hist_disabled(self): |
|
38 | 38 | """Test that multiline replace does nothing if disabled""" |
|
39 | 39 | ip = get_ipython() |
|
40 | 40 | ip.multiline_history = False |
|
41 | 41 | |
|
42 | 42 | ghist = [u'line1', u'line2'] |
|
43 | 43 | for h in ghist: |
|
44 | 44 | ip.readline.add_history(h) |
|
45 | 45 | ip.hlen_before_cell = ip.readline.get_current_history_length() |
|
46 | 46 | ip._replace_rlhist_multiline(u'sourc€\nsource2') |
|
47 | 47 | |
|
48 | 48 | self.assertEquals(ip.readline.get_current_history_length(), |
|
49 | 49 | ip.hlen_before_cell) |
|
50 | 50 | hist = self.rl_hist_entries(ip.readline, 2) |
|
51 | 51 | self.assertEquals(hist, ghist) |
|
52 | 52 | |
|
53 | 53 | @skipif(not get_ipython().has_readline, 'no readline') |
|
54 | 54 | def test_replace_multiline_hist_adds(self): |
|
55 | 55 | """Test that multiline replace function adds history""" |
|
56 | 56 | ip = get_ipython() |
|
57 | 57 | |
|
58 | 58 | ip.hlen_before_cell = ip.readline.get_current_history_length() |
|
59 | 59 | ip._replace_rlhist_multiline(u'sourc€') |
|
60 | 60 | |
|
61 | 61 | self.assertEquals(ip.hlen_before_cell, |
|
62 | 62 | ip.readline.get_current_history_length()) |
|
63 | 63 | |
|
64 | 64 | @skipif(not get_ipython().has_readline, 'no readline') |
|
65 | 65 | def test_replace_multiline_hist_keeps_history(self): |
|
66 | 66 | """Test that multiline replace does not delete history""" |
|
67 | 67 | ip = get_ipython() |
|
68 | 68 | ip.multiline_history = True |
|
69 | 69 | |
|
70 | 70 | ghist = [u'line1', u'line2'] |
|
71 | 71 | for h in ghist: |
|
72 | 72 | ip.readline.add_history(h) |
|
73 | 73 | |
|
74 | 74 | #start cell |
|
75 | 75 | ip.hlen_before_cell = ip.readline.get_current_history_length() |
|
76 | 76 | ip._replace_rlhist_multiline(u'sourc€\nsource2') |
|
77 | 77 | |
|
78 | 78 | self.assertEquals(ip.readline.get_current_history_length(), |
|
79 | 79 | ip.hlen_before_cell) |
|
80 | 80 | hist = self.rl_hist_entries(ip.readline, 3) |
|
81 | 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 | 84 | @skipif(not get_ipython().has_readline, 'no readline') |
|
103 | 85 | def test_replace_multiline_hist_replaces_twice(self): |
|
104 | 86 | """Test that multiline entries are replaced twice""" |
|
105 | 87 | ip = get_ipython() |
|
106 | 88 | ip.multiline_history = True |
|
107 | 89 | |
|
108 | 90 | ip.readline.add_history(u'line0') |
|
109 | 91 | #start cell |
|
110 | 92 | ip.hlen_before_cell = ip.readline.get_current_history_length() |
|
111 | 93 | ip.readline.add_history('l€ne1') |
|
112 | 94 | ip.readline.add_history('line2') |
|
113 | 95 | #replace cell with single line |
|
114 | 96 | ip._replace_rlhist_multiline(u'l€ne1\nline2') |
|
115 | 97 | ip.readline.add_history('l€ne3') |
|
116 | 98 | ip.readline.add_history('line4') |
|
117 | 99 | #replace cell with single line |
|
118 | 100 | ip._replace_rlhist_multiline(u'l€ne3\nline4') |
|
119 | 101 | |
|
120 | 102 | self.assertEquals(ip.readline.get_current_history_length(), |
|
121 | 103 | ip.hlen_before_cell) |
|
122 | 104 | hist = self.rl_hist_entries(ip.readline, 3) |
|
123 | 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