Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Refine regexp checks for end of blocks logic.

  • Loading branch information...
commit a7d2e2738f8bc8f957d1c92f96c01c5903072f73 1 parent b89562b
@fperez authored
View
6 IPython/core/inputsplitter.py
@@ -156,7 +156,8 @@ def last_blank(src):
return src == '\n' or bool(last_blank_re.match(src))
-last_two_blanks_re = re.compile(r'^.*\n\s*\n\s*$', re.MULTILINE)
+last_two_blanks_re = re.compile(r'^\n\s*\n\s*$', re.MULTILINE)
+last_two_blanks_re2 = re.compile(r'^.+\n\s*\n\s+$', re.MULTILINE)
def last_two_blanks(src):
"""Determine if the input source ends in two blanks.
@@ -168,7 +169,8 @@ def last_two_blanks(src):
src : string
A single or multiline string.
"""
- return bool(last_two_blanks_re.match(src))
+ return (bool(last_two_blanks_re.match(src)) or
+ bool(last_two_blanks_re2.match(src)) )
def remove_comments(src):
View
37 IPython/core/tests/test_inputsplitter.py
@@ -616,17 +616,20 @@ def test_last_two_blanks():
nt.assert_false(isp.last_two_blanks('abc'))
nt.assert_false(isp.last_two_blanks('abc\n'))
nt.assert_false(isp.last_two_blanks('abc\n\na'))
+ nt.assert_false(isp.last_two_blanks('abc\n \n'))
+ nt.assert_false(isp.last_two_blanks('abc\n\n'))
nt.assert_true(isp.last_two_blanks('\n\n'))
nt.assert_true(isp.last_two_blanks('\n\n '))
nt.assert_true(isp.last_two_blanks('\n \n'))
- nt.assert_true(isp.last_two_blanks('abc\n \n'))
nt.assert_true(isp.last_two_blanks('abc\n\n '))
- nt.assert_true(isp.last_two_blanks('abc\n\n'))
+ nt.assert_true(isp.last_two_blanks('abc\n\n\n'))
+ nt.assert_true(isp.last_two_blanks('abc\n\n \n'))
+ nt.assert_true(isp.last_two_blanks('abc\n\n \n '))
+ nt.assert_true(isp.last_two_blanks('abc\n\n \n \n'))
-def test_cell_magics():
- from IPython.core import magic
+def test_cell_magics_line_mode():
cell = """\
%%cellm line
@@ -649,6 +652,32 @@ def test_cell_magics():
nt.assert_false(sp.push_accepts_more()) #3
+def test_cell_magics_cell_mode():
+
+ cell = """\
+%%cellm line
+body
+"""
+ sp = isp.IPythonInputSplitter(input_mode='cell')
+ sp.push(cell)
+ nt.assert_equal(sp.cell_magic_parts, ['body\n'])
+ out = sp.source
+ ref = u"get_ipython()._cell_magic(u'cellm', u'line')\n"
+ nt.assert_equal(out, ref)
+
+ sp.reset()
+
+ src = '%%cellm line2\n'
+ sp.push(src)
+ nt.assert_true(sp.push_accepts_more()) #1
+ src += '\n'
+ sp.push(src)
+ nt.assert_true(sp.push_accepts_more()) #2
+ src += '\n'
+ sp.push(src)
+ nt.assert_false(sp.push_accepts_more()) #3
+
+
class IPythonInputTestCase(InputSplitterTestCase):
"""By just creating a new class whose .isp is a different instance, we
re-run the same test battery on the new input splitter.
Please sign in to comment.
Something went wrong with that request. Please try again.