##// END OF EJS Templates
Backport PR #2384: Adapt inline backend to changes in matplotlib...
Backport PR #2384: Adapt inline backend to changes in matplotlib Matplotlib recently merged https://github.com/matplotlib/matplotlib/pull/1125 that makes it simpler to use objective oriented figure creation by automatically creating the right canvas for the backend. To solve that all backends must provide a backend_xxx.FigureCanvas. This is obviosly missing from the inline backend. The change is needed to make the inline backend work with mpl's 1.2.x branch which is due to released soon. Simply setting the default canvas equal to a Agg canvas appears to work for both svg and png figures but I'm not sure weather that is the right approach. Should the canvas depend on the figure format and provide a svg canvas for a svg figure? (Note that before this change to matplotlib the canvas from a plt.figure call seams to be a agg type in all cases) Edit: I made the pull request against 0.13.1 since it would be good to have this in the stable branch for when mpl is released. Just let me know and I can rebase it against master

File last commit:

r7502:38e47b0d
r8562:7d16877a
Show More
test_magic_arguments.py
121 lines | 4.9 KiB | text/x-python | PythonLexer
/ IPython / core / tests / test_magic_arguments.py
#-----------------------------------------------------------------------------
# Copyright (C) 2010-2011, IPython Development Team.
#
# Distributed under the terms of the Modified BSD License.
#
# The full license is in the file COPYING.txt, distributed with this software.
#-----------------------------------------------------------------------------
from nose.tools import assert_equal, assert_true
from IPython.external import argparse
from IPython.core.magic_arguments import (argument, argument_group, kwds,
magic_arguments, parse_argstring, real_name)
from IPython.testing.decorators import parametric
@magic_arguments()
@argument('-f', '--foo', help="an argument")
def magic_foo1(self, args):
""" A docstring.
"""
return parse_argstring(magic_foo1, args)
@magic_arguments()
def magic_foo2(self, args):
""" A docstring.
"""
return parse_argstring(magic_foo2, args)
@magic_arguments()
@argument('-f', '--foo', help="an argument")
@argument_group('Group')
@argument('-b', '--bar', help="a grouped argument")
@argument_group('Second Group')
@argument('-z', '--baz', help="another grouped argument")
def magic_foo3(self, args):
""" A docstring.
"""
return parse_argstring(magic_foo3, args)
@magic_arguments()
@kwds(argument_default=argparse.SUPPRESS)
@argument('-f', '--foo', help="an argument")
def magic_foo4(self, args):
""" A docstring.
"""
return parse_argstring(magic_foo4, args)
@magic_arguments('frobnicate')
@argument('-f', '--foo', help="an argument")
def magic_foo5(self, args):
""" A docstring.
"""
return parse_argstring(magic_foo5, args)
@magic_arguments()
@argument('-f', '--foo', help="an argument")
def magic_magic_foo(self, args):
""" A docstring.
"""
return parse_argstring(magic_magic_foo, args)
@magic_arguments()
@argument('-f', '--foo', help="an argument")
def foo(self, args):
""" A docstring.
"""
return parse_argstring(foo, args)
@parametric
def test_magic_arguments():
# Ideally, these would be doctests, but I could not get it to work.
yield assert_equal(magic_foo1.__doc__, '%foo1 [-f FOO]\n\n A docstring.\n\noptional arguments:\n -f FOO, --foo FOO an argument\n')
yield assert_equal(getattr(magic_foo1, 'argcmd_name', None), None)
yield assert_equal(real_name(magic_foo1), 'foo1')
yield assert_equal(magic_foo1(None, ''), argparse.Namespace(foo=None))
yield assert_true(hasattr(magic_foo1, 'has_arguments'))
yield assert_equal(magic_foo2.__doc__, '%foo2\n\n A docstring.\n')
yield assert_equal(getattr(magic_foo2, 'argcmd_name', None), None)
yield assert_equal(real_name(magic_foo2), 'foo2')
yield assert_equal(magic_foo2(None, ''), argparse.Namespace())
yield assert_true(hasattr(magic_foo2, 'has_arguments'))
yield assert_equal(magic_foo3.__doc__, '%foo3 [-f FOO] [-b BAR] [-z BAZ]\n\n A docstring.\n\noptional arguments:\n -f FOO, --foo FOO an argument\n\nGroup:\n -b BAR, --bar BAR a grouped argument\n\nSecond Group:\n -z BAZ, --baz BAZ another grouped argument\n')
yield assert_equal(getattr(magic_foo3, 'argcmd_name', None), None)
yield assert_equal(real_name(magic_foo3), 'foo3')
yield assert_equal(magic_foo3(None, ''),
argparse.Namespace(bar=None, baz=None, foo=None))
yield assert_true(hasattr(magic_foo3, 'has_arguments'))
yield assert_equal(magic_foo4.__doc__, '%foo4 [-f FOO]\n\n A docstring.\n\noptional arguments:\n -f FOO, --foo FOO an argument\n')
yield assert_equal(getattr(magic_foo4, 'argcmd_name', None), None)
yield assert_equal(real_name(magic_foo4), 'foo4')
yield assert_equal(magic_foo4(None, ''), argparse.Namespace())
yield assert_true(hasattr(magic_foo4, 'has_arguments'))
yield assert_equal(magic_foo5.__doc__, '%frobnicate [-f FOO]\n\n A docstring.\n\noptional arguments:\n -f FOO, --foo FOO an argument\n')
yield assert_equal(getattr(magic_foo5, 'argcmd_name', None), 'frobnicate')
yield assert_equal(real_name(magic_foo5), 'frobnicate')
yield assert_equal(magic_foo5(None, ''), argparse.Namespace(foo=None))
yield assert_true(hasattr(magic_foo5, 'has_arguments'))
yield assert_equal(magic_magic_foo.__doc__, '%magic_foo [-f FOO]\n\n A docstring.\n\noptional arguments:\n -f FOO, --foo FOO an argument\n')
yield assert_equal(getattr(magic_magic_foo, 'argcmd_name', None), None)
yield assert_equal(real_name(magic_magic_foo), 'magic_foo')
yield assert_equal(magic_magic_foo(None, ''), argparse.Namespace(foo=None))
yield assert_true(hasattr(magic_magic_foo, 'has_arguments'))
yield assert_equal(foo.__doc__, '%foo [-f FOO]\n\n A docstring.\n\noptional arguments:\n -f FOO, --foo FOO an argument\n')
yield assert_equal(getattr(foo, 'argcmd_name', None), None)
yield assert_equal(real_name(foo), 'foo')
yield assert_equal(foo(None, ''), argparse.Namespace(foo=None))
yield assert_true(hasattr(foo, 'has_arguments'))