Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Cell tweaks #354

Merged
merged 6 commits into from

2 participants

@takluyver
Owner

This fixes and adds tests for a couple of bugs my ast refactor had introduced:

  1. Pressing return in a blank cell shouldn't increment the execution_count.
  2. We shouldn't do transformations inside multi-line strings, so entering:
"""
%lsmagic
"""

should get you the same string back.

IPython/lib/tests/test_irunner.py
@@ -33,6 +33,9 @@ class RunnerTestCase(unittest.TestCase):
out_l = [l for l in out.splitlines() if l and not l.isspace()]
mismatch = 0
if len(output_l) != len(out_l):
+ print "\n".join(output_l)
@fperez Owner
fperez added a note

why is this a separate print statement rather than encoded in the failure message?

@takluyver Owner

Primarily just because it was a frustrated "Gah, that's not helpful!" moment. You're right, I'll redo it.

@fperez Owner
fperez added a note
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
@fperez
Owner

other than the small line comment, this looks good for merge. Thanks!

@takluyver takluyver merged commit 2d96c57 into ipython:master
@damianavila damianavila referenced this pull request from a commit
Commit has since been removed from the repository and is no longer available.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
This page is out of date. Refresh to see the latest.
View
15 IPython/core/interactiveshell.py
@@ -2106,21 +2106,28 @@ def safe_execfile_ipy(self, fname):
self.showtraceback()
warn('Unknown failure executing file: <%s>' % fname)
- def run_cell(self, cell, store_history=True):
+ def run_cell(self, raw_cell, store_history=True):
"""Run a complete IPython cell.
Parameters
----------
- cell : str
+ raw_cell : str
The code (including IPython code such as %magic functions) to run.
store_history : bool
If True, the raw and translated cell will be stored in IPython's
history. For user code calling back into IPython's machinery, this
should be set to False.
"""
- raw_cell = cell
+ if (not raw_cell) or raw_cell.isspace():
+ return
+
+ for line in raw_cell.splitlines():
+ self.input_splitter.push(line)
+ cell = self.input_splitter.source_reset()
+
with self.builtin_trap:
- cell = self.prefilter_manager.prefilter_lines(cell)
+ if len(cell.splitlines()) == 1:
+ cell = self.prefilter_manager.prefilter_lines(cell)
# Store raw and processed history
if store_history:
View
7 IPython/core/tests/test_interactiveshell.py
@@ -41,7 +41,9 @@ def test_run_empty_cell(self):
"""Just make sure we don't get a horrible error with a blank
cell of input. Yes, I did overlook that."""
ip = get_ipython()
+ old_xc = ip.execution_count
ip.run_cell('')
+ self.assertEquals(ip.execution_count, old_xc)
def test_run_cell_multiline(self):
"""Multi-block, multi-line cells must execute correctly.
@@ -84,3 +86,8 @@ def test_In_variable(self):
newlen = len(ip.user_ns['In'])
self.assertEquals(oldlen+1, newlen)
self.assertEquals(ip.user_ns['In'][-1],'1;')
+
+ def test_magic_names_in_string(self):
+ ip = get_ipython()
+ ip.run_cell('a = """\n%exit\n"""')
+ self.assertEquals(ip.user_ns['a'], '\n%exit\n')
View
10 IPython/lib/tests/test_irunner.py
@@ -33,7 +33,15 @@ def _test_runner(self,runner,source,output):
out_l = [l for l in out.splitlines() if l and not l.isspace()]
mismatch = 0
if len(output_l) != len(out_l):
- self.fail('mismatch in number of lines')
+ message = ("Mismatch in number of lines\n\n"
+ "Expected:\n"
+ "~~~~~~~~~\n"
+ "%s\n\n"
+ "Got:\n"
+ "~~~~~~~~~\n"
+ "%s"
+ ) % ("\n".join(output_l), "\n".join(out_l))
+ self.fail(message)
for n in range(len(output_l)):
# Do a line-by-line comparison
ol1 = output_l[n].strip()
Something went wrong with that request. Please try again.