Show More
@@ -69,7 +69,8 b' class PrefilterFrontEnd(LineFrontEndBase):' | |||||
69 | if ipython0 is None: |
|
69 | if ipython0 is None: | |
70 | # Instanciate an IPython0 interpreter to be able to use the |
|
70 | # Instanciate an IPython0 interpreter to be able to use the | |
71 | # prefiltering. |
|
71 | # prefiltering. | |
72 | ipython0 = make_IPython() |
|
72 | # XXX: argv=[] is a bit bold. | |
|
73 | ipython0 = make_IPython(argv=[]) | |||
73 | self.ipython0 = ipython0 |
|
74 | self.ipython0 = ipython0 | |
74 | # Set the pager: |
|
75 | # Set the pager: | |
75 | self.ipython0.set_hook('show_in_pager', |
|
76 | self.ipython0.set_hook('show_in_pager', | |
@@ -85,7 +86,7 b' class PrefilterFrontEnd(LineFrontEndBase):' | |||||
85 | 'ls -CF') |
|
86 | 'ls -CF') | |
86 | # And now clean up the mess created by ipython0 |
|
87 | # And now clean up the mess created by ipython0 | |
87 | self.release_output() |
|
88 | self.release_output() | |
88 | if not 'banner' in kwargs: |
|
89 | if not 'banner' in kwargs and self.banner is None: | |
89 | kwargs['banner'] = self.ipython0.BANNER + """ |
|
90 | kwargs['banner'] = self.ipython0.BANNER + """ | |
90 | This is the wx frontend, by Gael Varoquaux. This is EXPERIMENTAL code.""" |
|
91 | This is the wx frontend, by Gael Varoquaux. This is EXPERIMENTAL code.""" | |
91 |
|
92 |
@@ -12,23 +12,36 b' __docformat__ = "restructuredtext en"' | |||||
12 | # in the file COPYING, distributed as part of this software. |
|
12 | # in the file COPYING, distributed as part of this software. | |
13 | #------------------------------------------------------------------------------- |
|
13 | #------------------------------------------------------------------------------- | |
14 |
|
14 | |||
15 | from IPython.frontend.prefilterfrontend import PrefilterFrontEnd |
|
|||
16 | from cStringIO import StringIO |
|
15 | from cStringIO import StringIO | |
17 | import string |
|
16 | import string | |
18 | import sys |
|
17 | ||
19 | from IPython.ipapi import get as get_ipython0 |
|
18 | from IPython.ipapi import get as get_ipython0 | |
|
19 | from IPython.frontend.prefilterfrontend import PrefilterFrontEnd | |||
20 |
|
20 | |||
21 | class TestPrefilterFrontEnd(PrefilterFrontEnd): |
|
21 | class TestPrefilterFrontEnd(PrefilterFrontEnd): | |
22 |
|
22 | |||
23 | input_prompt_template = string.Template('') |
|
23 | input_prompt_template = string.Template('') | |
24 | output_prompt_template = string.Template('') |
|
24 | output_prompt_template = string.Template('') | |
|
25 | banner = '' | |||
25 |
|
26 | |||
26 | def __init__(self): |
|
27 | def __init__(self): | |
27 |
ipython0 = get_ipython0() |
|
28 | ipython0 = get_ipython0().IP | |
28 | self.out = StringIO() |
|
29 | self.out = StringIO() | |
29 | PrefilterFrontEnd.__init__(self, ipython0=ipython0) |
|
30 | PrefilterFrontEnd.__init__(self, ipython0=ipython0) | |
30 |
|
31 | # Clean up the namespace for isolation between tests | ||
31 | def write(self, string): |
|
32 | user_ns = self.ipython0.user_ns | |
|
33 | # We need to keep references to things so that they don't | |||
|
34 | # get garbage collected (this stinks). | |||
|
35 | self.shadow_ns = dict() | |||
|
36 | for i in self.ipython0.magic_who_ls(): | |||
|
37 | self.shadow_ns[i] = user_ns.pop(i) | |||
|
38 | # Some more code for isolation (yeah, crazy) | |||
|
39 | self._on_enter() | |||
|
40 | self.out.flush() | |||
|
41 | self.out.reset() | |||
|
42 | self.out.truncate() | |||
|
43 | ||||
|
44 | def write(self, string, *args, **kwargs): | |||
32 | self.out.write(string) |
|
45 | self.out.write(string) | |
33 |
|
46 | |||
34 | def _on_enter(self): |
|
47 | def _on_enter(self): | |
@@ -40,9 +53,10 b' def test_execution():' | |||||
40 | """ Test execution of a command. |
|
53 | """ Test execution of a command. | |
41 | """ |
|
54 | """ | |
42 | f = TestPrefilterFrontEnd() |
|
55 | f = TestPrefilterFrontEnd() | |
43 |
f.input_buffer = 'print 1 |
|
56 | f.input_buffer = 'print 1' | |
44 | f._on_enter() |
|
57 | f._on_enter() | |
45 |
|
|
58 | out_value = f.out.getvalue() | |
|
59 | assert out_value == '1\n' | |||
46 |
|
60 | |||
47 |
|
61 | |||
48 | def test_multiline(): |
|
62 | def test_multiline(): | |
@@ -53,17 +67,21 b' def test_multiline():' | |||||
53 | f._on_enter() |
|
67 | f._on_enter() | |
54 | f.input_buffer += 'print 1' |
|
68 | f.input_buffer += 'print 1' | |
55 | f._on_enter() |
|
69 | f._on_enter() | |
56 |
|
|
70 | out_value = f.out.getvalue() | |
|
71 | assert out_value == '' | |||
57 | f._on_enter() |
|
72 | f._on_enter() | |
58 |
|
|
73 | out_value = f.out.getvalue() | |
|
74 | assert out_value == '1\n' | |||
59 | f = TestPrefilterFrontEnd() |
|
75 | f = TestPrefilterFrontEnd() | |
60 | f.input_buffer='(1 +' |
|
76 | f.input_buffer='(1 +' | |
61 | f._on_enter() |
|
77 | f._on_enter() | |
62 | f.input_buffer += '0)' |
|
78 | f.input_buffer += '0)' | |
63 | f._on_enter() |
|
79 | f._on_enter() | |
64 |
|
|
80 | out_value = f.out.getvalue() | |
|
81 | assert out_value == '' | |||
65 | f._on_enter() |
|
82 | f._on_enter() | |
66 |
|
|
83 | out_value = f.out.getvalue() | |
|
84 | assert out_value == '1\n' | |||
67 |
|
85 | |||
68 |
|
86 | |||
69 | def test_capture(): |
|
87 | def test_capture(): | |
@@ -74,12 +92,14 b' def test_capture():' | |||||
74 | f.input_buffer = \ |
|
92 | f.input_buffer = \ | |
75 | 'import os; out=os.fdopen(1, "w"); out.write("1") ; out.flush()' |
|
93 | 'import os; out=os.fdopen(1, "w"); out.write("1") ; out.flush()' | |
76 | f._on_enter() |
|
94 | f._on_enter() | |
77 |
|
|
95 | out_value = f.out.getvalue() | |
|
96 | assert out_value == '1' | |||
78 | f = TestPrefilterFrontEnd() |
|
97 | f = TestPrefilterFrontEnd() | |
79 | f.input_buffer = \ |
|
98 | f.input_buffer = \ | |
80 | 'import os; out=os.fdopen(2, "w"); out.write("1") ; out.flush()' |
|
99 | 'import os; out=os.fdopen(2, "w"); out.write("1") ; out.flush()' | |
81 | f._on_enter() |
|
100 | f._on_enter() | |
82 |
|
|
101 | out_value = f.out.getvalue() | |
|
102 | assert out_value == '1' | |||
83 |
|
103 | |||
84 |
|
104 | |||
85 | def test_magic(): |
|
105 | def test_magic(): | |
@@ -88,9 +108,10 b' def test_magic():' | |||||
88 | This test is fairly fragile and will break when magics change. |
|
108 | This test is fairly fragile and will break when magics change. | |
89 | """ |
|
109 | """ | |
90 | f = TestPrefilterFrontEnd() |
|
110 | f = TestPrefilterFrontEnd() | |
91 |
f.input_buffer += '%who |
|
111 | f.input_buffer += '%who' | |
92 | f._on_enter() |
|
112 | f._on_enter() | |
93 | assert f.out.getvalue() == 'Interactive namespace is empty.\n' |
|
113 | out_value = f.out.getvalue() | |
|
114 | assert out_value == 'Interactive namespace is empty.\n' | |||
94 |
|
115 | |||
95 |
|
116 | |||
96 | def test_help(): |
|
117 | def test_help(): | |
@@ -106,7 +127,10 b' def test_help():' | |||||
106 | f._on_enter() |
|
127 | f._on_enter() | |
107 | f.input_buffer += "f?" |
|
128 | f.input_buffer += "f?" | |
108 | f._on_enter() |
|
129 | f._on_enter() | |
109 | assert f.out.getvalue().split()[-1] == 'foobar' |
|
130 | assert 'traceback' not in f.last_result | |
|
131 | ## XXX: ipython doctest magic breaks this. I have no clue why | |||
|
132 | #out_value = f.out.getvalue() | |||
|
133 | #assert out_value.split()[-1] == 'foobar' | |||
110 |
|
134 | |||
111 |
|
135 | |||
112 | def test_completion(): |
|
136 | def test_completion(): | |
@@ -119,7 +143,8 b' def test_completion():' | |||||
119 | f._on_enter() |
|
143 | f._on_enter() | |
120 | f.input_buffer = 'zz' |
|
144 | f.input_buffer = 'zz' | |
121 | f.complete_current_input() |
|
145 | f.complete_current_input() | |
122 | assert f.out.getvalue() == '\nzzza zzzb ' |
|
146 | out_value = f.out.getvalue() | |
|
147 | assert out_value == '\nzzza zzzb ' | |||
123 | assert f.input_buffer == 'zzz' |
|
148 | assert f.input_buffer == 'zzz' | |
124 |
|
149 | |||
125 |
|
150 |
@@ -131,3 +131,5 b' def skip(func):' | |||||
131 | func.__name__) |
|
131 | func.__name__) | |
132 |
|
132 | |||
133 | return apply_wrapper(wrapper,func) |
|
133 | return apply_wrapper(wrapper,func) | |
|
134 | ||||
|
135 |
@@ -2,8 +2,8 b'' | |||||
2 | PREFIX=~/usr/local |
|
2 | PREFIX=~/usr/local | |
3 | PREFIX=~/tmp/local |
|
3 | PREFIX=~/tmp/local | |
4 |
|
4 | |||
5 | NOSE0=nosetests -vs --with-doctest --doctest-tests |
|
5 | NOSE0=nosetests -vs --with-doctest --doctest-tests --detailed-errors | |
6 | NOSE=nosetests -vvs --with-ipdoctest --doctest-tests --doctest-extension=txt |
|
6 | NOSE=nosetests -vvs --with-ipdoctest --doctest-tests --doctest-extension=txt --detailed-errors | |
7 |
|
7 | |||
8 | #--with-color |
|
8 | #--with-color | |
9 |
|
9 |
General Comments 0
You need to be logged in to leave comments.
Login now