From 94fa0ab89d850a4eb4a83260a88d6e7756b3fb67 2011-03-25 17:47:25 From: Fernando Perez Date: 2011-03-25 17:47:25 Subject: [PATCH] BUG: multi-line, multi-block cells were broken. Test added. Closes gh-314. --- diff --git a/IPython/core/interactiveshell.py b/IPython/core/interactiveshell.py index ab67de2..14d503d 100644 --- a/IPython/core/interactiveshell.py +++ b/IPython/core/interactiveshell.py @@ -2094,7 +2094,6 @@ class InteractiveShell(Configurable, Magic): # Store the untransformed code raw_cell = cell - # Code transformation and execution must take place with our # modifications to builtins. with self.builtin_trap: @@ -2121,14 +2120,13 @@ class InteractiveShell(Configurable, Magic): # Store raw and processed history if store_history: self.history_manager.store_inputs(self.execution_count, - cell, raw_cell) + cell, raw_cell) self.logger.log(cell, raw_cell) # All user code execution should take place with our # modified displayhook. with self.display_trap: - # Single-block input should behave like an interactive prompt if len(blocks) == 1: out = self.run_source(blocks[0]) @@ -2164,7 +2162,7 @@ class InteractiveShell(Configurable, Magic): else: # Run the whole cell as one entity, storing both raw and # processed input in history - self.run_source(ipy_cell, symbol='exec') + self.run_source(cell, symbol='exec') # Write output to the database. Does nothing unless # history output logging is enabled. diff --git a/IPython/core/tests/test_interactiveshell.py b/IPython/core/tests/test_interactiveshell.py index c0f96e5..41419b9 100644 --- a/IPython/core/tests/test_interactiveshell.py +++ b/IPython/core/tests/test_interactiveshell.py @@ -41,3 +41,17 @@ class InteractiveShellTestCase(unittest.TestCase): cell of input. Yes, I did overlook that.""" ip = get_ipython() ip.run_cell('') + + def test_run_cell_multilne(self): + """Multi-block, multi-line cells must execute correctly. + """ + ip = get_ipython() + src = '\n'.join(["x=1", + "y=2", + "if 1:", + " x += 1", + " y += 1",]) + ip.run_cell(src) + self.assertEquals(ip.user_ns['x'], 2) + self.assertEquals(ip.user_ns['y'], 3) +