From 18ae28c465b4525d6121edec7446ec2fe8ce50dd 2009-03-30 04:19:34
From: Gael Varoquaux <gael.varoquaux@normalesup.org>
Date: 2009-03-30 04:19:34
Subject: [PATCH] BUG: Fix wrong command splitting in Interpreter
---

diff --git a/IPython/kernel/core/interpreter.py b/IPython/kernel/core/interpreter.py
index bca170b..88e02c3 100644
--- a/IPython/kernel/core/interpreter.py
+++ b/IPython/kernel/core/interpreter.py
@@ -708,6 +708,12 @@ class Interpreter(object):
         # the end even though we don't have a line number for it. Fortunately,
         # None does the job nicely.
         linenos.append(None)
+
+        # Same problem at the other end: sometimes the ast tree has its
+        # first complete statement not starting on line 0. In this case
+        # we might miss part of it
+        linenos[0] = 0
+
         lines = python.splitlines()
 
         # Create a list of atomic commands.
diff --git a/IPython/kernel/core/tests/test_interpreter.py b/IPython/kernel/core/tests/test_interpreter.py
index 3efc4f2..f92e298 100644
--- a/IPython/kernel/core/tests/test_interpreter.py
+++ b/IPython/kernel/core/tests/test_interpreter.py
@@ -5,17 +5,22 @@
 __docformat__ = "restructuredtext en"
 
 #-----------------------------------------------------------------------------
-#  Copyright (C) 2008  The IPython Development Team                           
+#  Copyright (C) 2008-2009  The IPython Development Team                           
 #                                                                             
 #  Distributed under the terms of the BSD License.  The full license is in    
 #  the file COPYING, distributed as part of this software.                    
 #-----------------------------------------------------------------------------
-                                                                              
+
 #-----------------------------------------------------------------------------
 # Imports                                                                     
 #-----------------------------------------------------------------------------
 
 from IPython.kernel.core.interpreter import Interpreter
+import nose
+
+#-----------------------------------------------------------------------------
+# Tests 
+#-----------------------------------------------------------------------------
 
 def test_unicode():
     """ Test unicode handling with the interpreter.
@@ -24,3 +29,29 @@ def test_unicode():
     i.execute_python(u'print "ù"')
     i.execute_python('print "ù"')
 
+
+def test_split_commands():
+    """ Test that commands are indeed individually split.
+    """
+    i = Interpreter()
+    test_atoms = [('(1\n + 1)', ),
+                  ('1', '1', ),
+                  ]
+    for atoms in test_atoms:
+        atoms = [atom.rstrip() + '\n' for atom in atoms]
+        yield nose.tools.assert_equals, i.split_commands(''.join(atoms)), \
+                                atoms
+
+
+def test_long_lines():
+    """ Test for spurious syntax error created by the interpreter.
+    """
+    test_strings = [u'( 1 +\n 1\n )\n\n',
+                    u'(1 \n + 1\n )\n\n',
+                   ]
+    i = Interpreter()
+    for s in test_strings:
+        yield i.execute, s
+
+
+