Skip to content
This repository
Browse code

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...
commit de4ba654e16782f96cab589c411fccdd9e5eb167 1 parent 827b268
Fernando Perez fperez authored
7 IPython/core/interactiveshell.py
@@ -2174,8 +2174,11 @@ def run_one_block(self, block):
2174 2174 if len(block.splitlines()) <= 1:
2175 2175 out = self.run_single_line(block)
2176 2176 else:
2177   - out = self.run_code(block)
2178   - #out = self.run_source(block)
  2177 + # Call run_source, which correctly compiles the input cell.
  2178 + # run_code must only be called when we know we have a code object,
  2179 + # as it does a naked exec and the compilation mode may not be what
  2180 + # we wanted.
  2181 + out = self.run_source(block)
2179 2182 return out
2180 2183
2181 2184 def run_single_line(self, line):
37 IPython/core/tests/test_interactiveshell.py
... ... @@ -0,0 +1,37 @@
  1 +"""Tests for the key interactiveshell module.
  2 +
  3 +Historically the main classes in interactiveshell have been under-tested. This
  4 +module should grow as many single-method tests as possible to trap many of the
  5 +recurring bugs we seem to encounter with high-level interaction.
  6 +
  7 +Authors
  8 +-------
  9 +* Fernando Perez
  10 +"""
  11 +#-----------------------------------------------------------------------------
  12 +# Copyright (C) 2011 The IPython Development Team
  13 +#
  14 +# Distributed under the terms of the BSD License. The full license is in
  15 +# the file COPYING, distributed as part of this software.
  16 +#-----------------------------------------------------------------------------
  17 +
  18 +#-----------------------------------------------------------------------------
  19 +# Imports
  20 +#-----------------------------------------------------------------------------
  21 +# stdlib
  22 +import unittest
  23 +
  24 +#-----------------------------------------------------------------------------
  25 +# Tests
  26 +#-----------------------------------------------------------------------------
  27 +
  28 +class InteractiveShellTestCase(unittest.TestCase):
  29 + def test_naked_string_cells(self):
  30 + """Test that cells with only naked strings are fully executed"""
  31 + ip = get_ipython()
  32 + # First, single-line inputs
  33 + ip.run_cell('"a"\n')
  34 + self.assertEquals(ip.user_ns['_'], 'a')
  35 + # And also multi-line cells
  36 + ip.run_cell('"""a\nb"""\n')
  37 + 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.