Show More
@@ -72,7 +72,7 b' class ipnsdict(dict):' | |||||
72 | def clear(self): |
|
72 | def clear(self): | |
73 | dict.clear(self) |
|
73 | dict.clear(self) | |
74 | self.update(self._savedict) |
|
74 | self.update(self._savedict) | |
75 |
|
75 | |||
76 | def _checkpoint(self): |
|
76 | def _checkpoint(self): | |
77 | self._savedict.clear() |
|
77 | self._savedict.clear() | |
78 | self._savedict.update(self) |
|
78 | self._savedict.update(self) | |
@@ -127,17 +127,30 b' def start_ipython():' | |||||
127 | _excepthook = sys.excepthook |
|
127 | _excepthook = sys.excepthook | |
128 | _main = sys.modules.get('__main__') |
|
128 | _main = sys.modules.get('__main__') | |
129 |
|
129 | |||
|
130 | # Create custom argv and namespaces for our IPython to be test-friendly | |||
130 | argv = tools.default_argv() |
|
131 | argv = tools.default_argv() | |
|
132 | user_ns, global_ns = iplib.make_user_namespaces(ipnsdict(), {}) | |||
131 |
|
133 | |||
132 | # Start IPython instance. We customize it to start with minimal frills. |
|
134 | # Create and initialize our test-friendly IPython instance. | |
133 | user_ns,global_ns = iplib.make_user_namespaces(ipnsdict(),{}) |
|
|||
134 | ip = ipapp.IPythonApp(argv, user_ns=user_ns, user_global_ns=global_ns) |
|
135 | ip = ipapp.IPythonApp(argv, user_ns=user_ns, user_global_ns=global_ns) | |
135 | ip.initialize() |
|
136 | ip.initialize() | |
|
137 | ||||
|
138 | # A few more tweaks needed for playing nicely with doctests... | |||
|
139 | ||||
|
140 | # These traps are normally only active for interactive use, set them | |||
|
141 | # permanently since we'll be mocking interactive sessions. | |||
136 | ip.shell.builtin_trap.set() |
|
142 | ip.shell.builtin_trap.set() | |
137 |
|
143 | |||
138 | # Set error printing to stdout so nose can doctest exceptions |
|
144 | # Set error printing to stdout so nose can doctest exceptions | |
139 | ip.shell.InteractiveTB.out_stream = 'stdout' |
|
145 | ip.shell.InteractiveTB.out_stream = 'stdout' | |
140 |
|
146 | |||
|
147 | # Modify the IPython system call with one that uses getoutput, so that we | |||
|
148 | # can capture subcommands and print them to Python's stdout, otherwise the | |||
|
149 | # doctest machinery would miss them. | |||
|
150 | ip.shell.system = xsys | |||
|
151 | ||||
|
152 | # IPython is ready, now clean up some global state... | |||
|
153 | ||||
141 | # Deactivate the various python system hooks added by ipython for |
|
154 | # Deactivate the various python system hooks added by ipython for | |
142 | # interactive convenience so we don't confuse the doctest system |
|
155 | # interactive convenience so we don't confuse the doctest system | |
143 | sys.modules['__main__'] = _main |
|
156 | sys.modules['__main__'] = _main | |
@@ -146,15 +159,10 b' def start_ipython():' | |||||
146 |
|
159 | |||
147 | # So that ipython magics and aliases can be doctested (they work by making |
|
160 | # So that ipython magics and aliases can be doctested (they work by making | |
148 | # a call into a global _ip object). Also make the top-level get_ipython |
|
161 | # a call into a global _ip object). Also make the top-level get_ipython | |
149 | # now return this without calling here again |
|
162 | # now return this without recursively calling here again. | |
150 | _ip = ip.shell |
|
163 | _ip = ip.shell | |
151 | get_ipython = _ip.get_ipython |
|
164 | get_ipython = _ip.get_ipython | |
152 | __builtin__._ip = _ip |
|
165 | __builtin__._ip = _ip | |
153 | __builtin__.get_ipython = get_ipython |
|
166 | __builtin__.get_ipython = get_ipython | |
154 |
|
167 | |||
155 | # Modify the IPython system call with one that uses getoutput, so that we |
|
|||
156 | # can capture subcommands and print them to Python's stdout, otherwise the |
|
|||
157 | # doctest machinery would miss them. |
|
|||
158 | ip.shell.system = xsys |
|
|||
159 |
|
||||
160 | return _ip |
|
168 | return _ip |
General Comments 0
You need to be logged in to leave comments.
Login now