From 460353e67e34a145f65512513a8fd98acd01a707 2010-01-09 06:29:06 From: Fernando Perez Date: 2010-01-09 06:29:06 Subject: [PATCH] Fix broken %time magic. Fixes https://bugs.launchpad.net/ipython/+bug/497187 --- diff --git a/IPython/core/iplib.py b/IPython/core/iplib.py index 5965b19..b4fa3b7 100644 --- a/IPython/core/iplib.py +++ b/IPython/core/iplib.py @@ -2378,6 +2378,10 @@ class InteractiveShell(Component, Magic): def init_prefilter(self): self.prefilter_manager = PrefilterManager(self, config=self.config) + # Ultimately this will be refactored in the new interpreter code, but + # for now, we should expose the main prefilter method (there's legacy + # code out there that may rely on this). + self.prefilter = self.prefilter_manager.prefilter_lines #------------------------------------------------------------------------- # Utilities diff --git a/IPython/core/tests/test_magic.py b/IPython/core/tests/test_magic.py index 6a463f0..2cd7b6c 100644 --- a/IPython/core/tests/test_magic.py +++ b/IPython/core/tests/test_magic.py @@ -11,7 +11,6 @@ from cStringIO import StringIO import nose.tools as nt -#from IPython.core.iplib import get_ipython from IPython.utils.platutils import find_cmd, get_long_path_name from IPython.testing import decorators as dec from IPython.testing import tools as tt @@ -270,6 +269,7 @@ class TestMagicRun(object): pass # Multiple tests for clipboard pasting +@dec.parametric def test_paste(): _ip = get_ipython() def paste(txt, flags='-q'): @@ -291,11 +291,11 @@ def test_paste(): # Run tests with fake clipboard function user_ns.pop('x', None) paste('x=1') - yield (nt.assert_equal, user_ns['x'], 1) + yield nt.assert_equal(user_ns['x'], 1) user_ns.pop('x', None) paste('>>> x=2') - yield (nt.assert_equal, user_ns['x'], 2) + yield nt.assert_equal(user_ns['x'], 2) paste(""" >>> x = [1,2,3] @@ -304,14 +304,14 @@ def test_paste(): ... y.append(i**2) ... """) - yield (nt.assert_equal, user_ns['x'], [1,2,3]) - yield (nt.assert_equal, user_ns['y'], [1,4,9]) + yield nt.assert_equal(user_ns['x'], [1,2,3]) + yield nt.assert_equal(user_ns['y'], [1,4,9]) # Now, test that paste -r works user_ns.pop('x', None) - yield (nt.assert_false, 'x' in user_ns) + yield nt.assert_false('x' in user_ns) _ip.magic('paste -r') - yield (nt.assert_equal, user_ns['x'], [1,2,3]) + yield nt.assert_equal(user_ns['x'], [1,2,3]) # Also test paste echoing, by temporarily faking the writer w = StringIO() @@ -325,12 +325,23 @@ def test_paste(): out = w.getvalue() finally: _ip.write = writer - yield (nt.assert_equal, user_ns['a'], 100) - yield (nt.assert_equal, user_ns['b'], 200) - yield (nt.assert_equal, out, code+"\n## -- End pasted text --\n") + yield nt.assert_equal(user_ns['a'], 100) + yield nt.assert_equal(user_ns['b'], 200) + yield nt.assert_equal(out, code+"\n## -- End pasted text --\n") finally: # This should be in a finally clause, instead of the bare except above. # Restore original hook hooks.clipboard_get = original_clip + +def test_time(): + _ip.magic('time None') + + +def doctest_time(): + """ + In [10]: %time None + CPU times: user 0.00 s, sys: 0.00 s, total: 0.00 s + Wall time: 0.00 s + """