Show More
@@ -64,13 +64,18 b' class PrefilterFrontEnd(LineFrontEndBase):' | |||||
64 |
|
64 | |||
65 | debug = False |
|
65 | debug = False | |
66 |
|
66 | |||
67 | def __init__(self, ipython0=None, *args, **kwargs): |
|
67 | def __init__(self, ipython0=None, argv=None, *args, **kwargs): | |
68 | """ Parameters: |
|
68 | """ Parameters: | |
69 | ----------- |
|
69 | ----------- | |
70 |
|
70 | |||
71 | ipython0: an optional ipython0 instance to use for command |
|
71 | ipython0: an optional ipython0 instance to use for command | |
72 | prefiltering and completion. |
|
72 | prefiltering and completion. | |
|
73 | ||||
|
74 | argv : list, optional | |||
|
75 | Used as the instance's argv value. If not given, [] is used. | |||
73 | """ |
|
76 | """ | |
|
77 | if argv is None: | |||
|
78 | argv = [] | |||
74 | # This is a hack to avoid the IPython exception hook to trigger |
|
79 | # This is a hack to avoid the IPython exception hook to trigger | |
75 | # on exceptions (https://bugs.launchpad.net/bugs/337105) |
|
80 | # on exceptions (https://bugs.launchpad.net/bugs/337105) | |
76 | # XXX: This is horrible: module-leve monkey patching -> side |
|
81 | # XXX: This is horrible: module-leve monkey patching -> side | |
@@ -98,7 +103,7 b' class PrefilterFrontEnd(LineFrontEndBase):' | |||||
98 | old_rawinput = __builtin__.raw_input |
|
103 | old_rawinput = __builtin__.raw_input | |
99 | __builtin__.raw_input = my_rawinput |
|
104 | __builtin__.raw_input = my_rawinput | |
100 | # XXX: argv=[] is a bit bold. |
|
105 | # XXX: argv=[] is a bit bold. | |
101 |
ipython0 = make_IPython(argv= |
|
106 | ipython0 = make_IPython(argv=argv, | |
102 | user_ns=self.shell.user_ns, |
|
107 | user_ns=self.shell.user_ns, | |
103 | user_global_ns=self.shell.user_global_ns) |
|
108 | user_global_ns=self.shell.user_global_ns) | |
104 | __builtin__.raw_input = old_rawinput |
|
109 | __builtin__.raw_input = old_rawinput |
@@ -12,14 +12,16 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 copy import copy, deepcopy | |||
15 | from cStringIO import StringIO |
|
16 | from cStringIO import StringIO | |
16 | import string |
|
17 | import string | |
17 |
|
18 | |||
18 | from nose.tools import assert_equal |
|
19 | from nose.tools import assert_equal | |
19 |
|
20 | |||
20 | from IPython.ipapi import get as get_ipython0 |
|
|||
21 | from IPython.frontend.prefilterfrontend import PrefilterFrontEnd |
|
21 | from IPython.frontend.prefilterfrontend import PrefilterFrontEnd | |
22 | from copy import copy, deepcopy |
|
22 | from IPython.ipapi import get as get_ipython0 | |
|
23 | from IPython.testing.plugin.ipdoctest import default_argv | |||
|
24 | ||||
23 |
|
25 | |||
24 | def safe_deepcopy(d): |
|
26 | def safe_deepcopy(d): | |
25 | """ Deep copy every key of the given dict, when possible. Elsewhere |
|
27 | """ Deep copy every key of the given dict, when possible. Elsewhere | |
@@ -45,7 +47,7 b' class TestPrefilterFrontEnd(PrefilterFrontEnd):' | |||||
45 |
|
47 | |||
46 | def __init__(self): |
|
48 | def __init__(self): | |
47 | self.out = StringIO() |
|
49 | self.out = StringIO() | |
48 | PrefilterFrontEnd.__init__(self) |
|
50 | PrefilterFrontEnd.__init__(self,argv=default_argv()) | |
49 | # Some more code for isolation (yeah, crazy) |
|
51 | # Some more code for isolation (yeah, crazy) | |
50 | self._on_enter() |
|
52 | self._on_enter() | |
51 | self.out.flush() |
|
53 | self.out.flush() | |
@@ -64,7 +66,7 b' def isolate_ipython0(func):' | |||||
64 | """ Decorator to isolate execution that involves an iptyhon0. |
|
66 | """ Decorator to isolate execution that involves an iptyhon0. | |
65 |
|
67 | |||
66 | Notes |
|
68 | Notes | |
67 |
----- |
|
69 | ----- | |
68 |
|
70 | |||
69 | Apply only to functions with no arguments. Nose skips functions |
|
71 | Apply only to functions with no arguments. Nose skips functions | |
70 | with arguments. |
|
72 | with arguments. | |
@@ -153,6 +155,12 b' def test_magic():' | |||||
153 | This test is fairly fragile and will break when magics change. |
|
155 | This test is fairly fragile and will break when magics change. | |
154 | """ |
|
156 | """ | |
155 | f = TestPrefilterFrontEnd() |
|
157 | f = TestPrefilterFrontEnd() | |
|
158 | # Before checking the interactive namespace, make sure it's clear (it can | |||
|
159 | # otherwise pick up things stored in the user's local db) | |||
|
160 | f.input_buffer += '%reset -f' | |||
|
161 | f._on_enter() | |||
|
162 | f.complete_current_input() | |||
|
163 | # Now, run the %who magic and check output | |||
156 | f.input_buffer += '%who' |
|
164 | f.input_buffer += '%who' | |
157 | f._on_enter() |
|
165 | f._on_enter() | |
158 | out_value = f.out.getvalue() |
|
166 | out_value = f.out.getvalue() |
General Comments 0
You need to be logged in to leave comments.
Login now