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