Show More
@@ -2224,52 +2224,6 b' class InteractiveShell(Configurable, Magic):' | |||
|
2224 | 2224 | |
|
2225 | 2225 | return False |
|
2226 | 2226 | |
|
2227 | ||
|
2228 | # PENDING REMOVAL: this method is slated for deletion, once our new | |
|
2229 | # input logic has been 100% moved to frontends and is stable. | |
|
2230 | def runlines(self, lines, clean=False): | |
|
2231 | """Run a string of one or more lines of source. | |
|
2232 | ||
|
2233 | This method is capable of running a string containing multiple source | |
|
2234 | lines, as if they had been entered at the IPython prompt. Since it | |
|
2235 | exposes IPython's processing machinery, the given strings can contain | |
|
2236 | magic calls (%magic), special shell access (!cmd), etc. | |
|
2237 | """ | |
|
2238 | ||
|
2239 | if not isinstance(lines, (list, tuple)): | |
|
2240 | lines = lines.splitlines() | |
|
2241 | ||
|
2242 | if clean: | |
|
2243 | lines = self._cleanup_ipy_script(lines) | |
|
2244 | ||
|
2245 | # We must start with a clean buffer, in case this is run from an | |
|
2246 | # interactive IPython session (via a magic, for example). | |
|
2247 | self.reset_buffer() | |
|
2248 | ||
|
2249 | # Since we will prefilter all lines, store the user's raw input too | |
|
2250 | # before we apply any transformations | |
|
2251 | self.buffer_raw[:] = [ l+'\n' for l in lines] | |
|
2252 | ||
|
2253 | more = False | |
|
2254 | prefilter_lines = self.prefilter_manager.prefilter_lines | |
|
2255 | with nested(self.builtin_trap, self.display_trap): | |
|
2256 | for line in lines: | |
|
2257 | # skip blank lines so we don't mess up the prompt counter, but | |
|
2258 | # do NOT skip even a blank line if we are in a code block (more | |
|
2259 | # is true) | |
|
2260 | ||
|
2261 | if line or more: | |
|
2262 | more = self.push_line(prefilter_lines(line, more)) | |
|
2263 | # IPython's run_source returns None if there was an error | |
|
2264 | # compiling the code. This allows us to stop processing | |
|
2265 | # right away, so the user gets the error message at the | |
|
2266 | # right place. | |
|
2267 | if more is None: | |
|
2268 | break | |
|
2269 | # final newline in case the input didn't have it, so that the code | |
|
2270 | # actually does get executed | |
|
2271 | if more: | |
|
2272 | self.push_line('\n') | |
|
2273 | 2227 | |
|
2274 | 2228 | def run_source(self, source, filename=None, symbol='single'): |
|
2275 | 2229 | """Compile and run some source in the interpreter. |
@@ -237,10 +237,10 b" SystemExit: (2, u'Mode = exit')" | |||
|
237 | 237 | """ |
|
238 | 238 | |
|
239 | 239 | |
|
240 |
def test_run |
|
|
240 | def test_run_cell(): | |
|
241 | 241 | import textwrap |
|
242 |
ip.run |
|
|
243 |
ip.run |
|
|
242 | ip.run_cell('a = 10\na+=1') | |
|
243 | ip.run_cell('assert a == 11\nassert 1') | |
|
244 | 244 | |
|
245 | 245 | nt.assert_equals(ip.user_ns['a'], 11) |
|
246 | 246 | complex = textwrap.dedent(""" |
@@ -260,7 +260,7 b' def test_runlines():' | |||
|
260 | 260 | |
|
261 | 261 | """) |
|
262 | 262 | # Simply verifies that this kind of input is run |
|
263 |
ip.run |
|
|
263 | ip.run_cell(complex) | |
|
264 | 264 | |
|
265 | 265 | |
|
266 | 266 | def test_db(): |
@@ -151,7 +151,7 b' class TestMagicRunSimple(tt.TempFileMixin):' | |||
|
151 | 151 | "def f(): return foo()") |
|
152 | 152 | self.mktmp(src) |
|
153 | 153 | _ip.magic('run %s' % self.fname) |
|
154 |
_ip.run |
|
|
154 | _ip.run_cell('t = isinstance(f(), foo)') | |
|
155 | 155 | nt.assert_true(_ip.user_ns['t']) |
|
156 | 156 | |
|
157 | 157 | # We have to skip these in win32 because getoutputerr() crashes, |
@@ -188,7 +188,7 b' class TestMagicRunSimple(tt.TempFileMixin):' | |||
|
188 | 188 | " print i;break\n" % empty.fname) |
|
189 | 189 | self.mktmp(src) |
|
190 | 190 | _ip.magic('run %s' % self.fname) |
|
191 |
_ip.run |
|
|
191 | _ip.run_cell('ip == get_ipython()') | |
|
192 | 192 | tt.assert_equals(_ip.user_ns['i'], 5) |
|
193 | 193 | |
|
194 | 194 | @dec.skip_win32 |
@@ -241,7 +241,7 b' class Kernel(Configurable):' | |||
|
241 | 241 | except: |
|
242 | 242 | status = u'error' |
|
243 | 243 | # FIXME: this code right now isn't being used yet by default, |
|
244 |
# because the run |
|
|
244 | # because the run_cell() call above directly fires off exception | |
|
245 | 245 | # reporting. This code, therefore, is only active in the scenario |
|
246 | 246 | # where runlines itself has an unhandled exception. We need to |
|
247 | 247 | # uniformize this, for all exception construction to come from a |
General Comments 0
You need to be logged in to leave comments.
Login now