From 59d4731c57afdb27fbe5cd23155e362a5081607b 2013-08-13 18:13:31 From: Thomas Kluyver Date: 2013-08-13 18:13:31 Subject: [PATCH] Merge pull request #4008 from jasongrout/prun-transform Transform code before %prun/%%prun runs --- diff --git a/IPython/core/magics/execution.py b/IPython/core/magics/execution.py index 0e22375..4e6d9ae 100644 --- a/IPython/core/magics/execution.py +++ b/IPython/core/magics/execution.py @@ -181,6 +181,7 @@ python-profiler package from non-free.""") list_all=True, posix=False) if cell is not None: arg_str += '\n' + cell + arg_str = self.shell.input_splitter.transform_cell(arg_str) return self._run_with_profiler(arg_str, opts, self.shell.user_ns) def _run_with_profiler(self, code, opts, namespace): diff --git a/IPython/core/tests/test_magic.py b/IPython/core/tests/test_magic.py index 983a393..7740524 100644 --- a/IPython/core/tests/test_magic.py +++ b/IPython/core/tests/test_magic.py @@ -490,6 +490,21 @@ def test_timeit_special_syntax(): @dec.skipif(execution.profile is None) +def test_prun_special_syntax(): + "Test %%prun with IPython special syntax" + @register_line_magic + def lmagic(line): + ip = get_ipython() + ip.user_ns['lmagic_out'] = line + + # line mode test + _ip.run_line_magic('prun', '-q %lmagic my line') + nt.assert_equal(_ip.user_ns['lmagic_out'], 'my line') + # cell mode test + _ip.run_cell_magic('prun', '-q', '%lmagic my line2') + nt.assert_equal(_ip.user_ns['lmagic_out'], 'my line2') + +@dec.skipif(execution.profile is None) def test_prun_quotes(): "Test that prun does not clobber string escapes (GH #1302)" _ip.magic(r"prun -q x = '\t'")