Skip to content
Browse files

Fix bug with execution of naked multiline strings.

The actual bug fix was a trivial one-line change, made here.  The rest
of the commits in this series improve our testing machinery and clean
up related code.

The actual fix was just calling the run_source instead of the run_code
method, which should only be called with compiled code objects.
  • Loading branch information...
1 parent 827b268 commit de4ba654e16782f96cab589c411fccdd9e5eb167 @fperez committed Feb 3, 2011
Showing with 42 additions and 2 deletions.
  1. +5 −2 IPython/core/interactiveshell.py
  2. +37 −0 IPython/core/tests/test_interactiveshell.py
View
7 IPython/core/interactiveshell.py
@@ -2174,8 +2174,11 @@ def run_one_block(self, block):
if len(block.splitlines()) <= 1:
out = self.run_single_line(block)
else:
- out = self.run_code(block)
- #out = self.run_source(block)
+ # Call run_source, which correctly compiles the input cell.
+ # run_code must only be called when we know we have a code object,
+ # as it does a naked exec and the compilation mode may not be what
+ # we wanted.
+ out = self.run_source(block)
return out
def run_single_line(self, line):
View
37 IPython/core/tests/test_interactiveshell.py
@@ -0,0 +1,37 @@
+"""Tests for the key interactiveshell module.
+
+Historically the main classes in interactiveshell have been under-tested. This
+module should grow as many single-method tests as possible to trap many of the
+recurring bugs we seem to encounter with high-level interaction.
+
+Authors
+-------
+* Fernando Perez
+"""
+#-----------------------------------------------------------------------------
+# Copyright (C) 2011 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
+#-----------------------------------------------------------------------------
+# stdlib
+import unittest
+
+#-----------------------------------------------------------------------------
+# Tests
+#-----------------------------------------------------------------------------
+
+class InteractiveShellTestCase(unittest.TestCase):
+ def test_naked_string_cells(self):
+ """Test that cells with only naked strings are fully executed"""
+ ip = get_ipython()
+ # First, single-line inputs
+ ip.run_cell('"a"\n')
+ self.assertEquals(ip.user_ns['_'], 'a')
+ # And also multi-line cells
+ ip.run_cell('"""a\nb"""\n')
+ self.assertEquals(ip.user_ns['_'], 'a\nb')

0 comments on commit de4ba65

Please sign in to comment.
Something went wrong with that request. Please try again.