From cc0d5b3606dd828c148acd1c8252a3513bb9c174 2012-05-26 03:20:00 From: Fernando Perez Date: 2012-05-26 03:20:00 Subject: [PATCH] Fix various test failures from then new magics API. --- diff --git a/IPython/core/history.py b/IPython/core/history.py index bafcd73..24b7b1f 100644 --- a/IPython/core/history.py +++ b/IPython/core/history.py @@ -884,6 +884,13 @@ class HistoryMagics(Magics): if close_at_end: outfile.close() + # For a long time we've had %hist as well as %history + @line_magic + def hist(self, arg): + return self.history(arg) + + hist.__doc__ = history.__doc__ + @line_magic def rep(self, arg): r"""Repeat a command, or get command to input line for editing. diff --git a/IPython/core/magic.py b/IPython/core/magic.py index c0ca043..b90eb5a 100644 --- a/IPython/core/magic.py +++ b/IPython/core/magic.py @@ -199,9 +199,7 @@ class MagicsManager(Configurable): validate_type(magic_type) magic_name = func.func_name if magic_name is None else magic_name setattr(self.user_magics, magic_name, func) - newm, name = self.user_magics.new_magic(func, magic_type, magic_name) - _record_magic(self.magics, magic_type, name, newm) - + _record_magic(self.magics, magic_type, magic_name, func) def _define_magic(self, name, func): """Support for deprecated API. diff --git a/IPython/core/magic_functions.py b/IPython/core/magic_functions.py index 1d9bb38..2530c0b 100644 --- a/IPython/core/magic_functions.py +++ b/IPython/core/magic_functions.py @@ -320,8 +320,8 @@ Defaulting color scheme to 'NoColor'""" @line_magic def quickref(self,arg): """ Show a quick reference sheet """ - import IPython.core.usage - qr = IPython.core.usage.quick_reference + self.magic_magic('-brief') + from IPython.core.usage import quick_reference + qr = quick_reference + self.magic('-brief') page.page(qr) @line_magic @@ -522,7 +522,7 @@ Defaulting color scheme to 'NoColor'""" "foo.ipynb" to "foo.json" do "%notebook -f json foo.ipynb". Possible formats include (json/ipynb, py). """ - args = magic_arguments.parse_argstring(self.magic_notebook, s) + args = magic_arguments.parse_argstring(self.notebook, s) from IPython.nbformat import current args.filename = unquote_filename(args.filename) @@ -1408,7 +1408,7 @@ class NamespaceMagics(Magics): beta """ - varlist = self.magic_who_ls(parameter_s) + varlist = self.who_ls(parameter_s) if not varlist: if parameter_s: print 'No variables match your requested type.' @@ -1459,7 +1459,7 @@ class NamespaceMagics(Magics): beta str test """ - varnames = self.magic_who_ls(parameter_s) + varnames = self.who_ls(parameter_s) if not varnames: if parameter_s: print 'No variables match your requested type.' diff --git a/IPython/core/tests/test_magic.py b/IPython/core/tests/test_magic.py index 0466474..8e9a1bd 100644 --- a/IPython/core/tests/test_magic.py +++ b/IPython/core/tests/test_magic.py @@ -16,6 +16,8 @@ from StringIO import StringIO import nose.tools as nt +from IPython.core import magic +from IPython.core import magic_functions as mf from IPython.nbformat.v3.tests.nbexamples import nb0 from IPython.nbformat import current from IPython.testing import decorators as dec @@ -51,7 +53,8 @@ def test_magic_parse_options(): """Test that we don't mangle paths when parsing magic options.""" ip = get_ipython() path = 'c:\\x' - opts = ip._magic.parse_options('-f %s' % path,'f:')[0] + m = magic.Magics(ip) + opts = m.parse_options('-f %s' % path,'f:')[0] # argv splitting is os-dependent if os.name == 'posix': expected = 'c:x' @@ -284,8 +287,9 @@ def test_parse_options(): """Tests for basic options parsing in magics.""" # These are only the most minimal of tests, more should be added later. At # the very least we check that basic text/unicode calls work OK. - nt.assert_equal(_ip._magic.parse_options('foo', '')[1], 'foo') - nt.assert_equal(_ip._magic.parse_options(u'foo', '')[1], u'foo') + m = magic.Magics(ip) + nt.assert_equal(m.parse_options('foo', '')[1], 'foo') + nt.assert_equal(m.parse_options(u'foo', '')[1], u'foo') def test_dirops(): @@ -422,7 +426,8 @@ def test_timeit_arguments(): "Test valid timeit arguments, should not cause SyntaxError (GH #1269)" _ip.magic("timeit ('#')") -@dec.skipif(_ip._magic.magic_prun == _ip._magic.profile_missing_notice) + +@dec.skipif(mf.profile is None) def test_prun_quotes(): "Test that prun does not clobber string escapes (GH #1302)" _ip.magic("prun -q x = '\t'") diff --git a/IPython/core/tests/test_prefilter.py b/IPython/core/tests/test_prefilter.py index d14aba1..8b26231 100644 --- a/IPython/core/tests/test_prefilter.py +++ b/IPython/core/tests/test_prefilter.py @@ -79,7 +79,7 @@ def test_issue_114(): msp = ip.prefilter_manager.multi_line_specials ip.prefilter_manager.multi_line_specials = False try: - for mgk in ip._magic.lsmagic(): + for mgk in ip.magics_manager.lsmagic()['line']: raw = template % mgk yield nt.assert_equals(ip.prefilter(raw), raw) finally: