##// END OF EJS Templates
refactor to improve cell switching in edit mode...
refactor to improve cell switching in edit mode This code was repeated in both CodeCell and TextCell, both of which are extensions of Cell, so this just unifies the logic in Cell. TextCell had logic here to check if the cell was rendered or not, but I don't believe it is possible to end up triggering such a code path. (Should that be required, I can always just add back these methods to TextCell, performing the .rendered==True check, and calling the Cell prior to this, code mirror at_top would only return true on if the cursor was at the first character of the top line. Now, pressing up arrow on any character on the top line will take you to the cell above. The same applies for the bottom line. Pressing down arrow would only go to the next cell if the cursor was at a location *after* the last character (something that is only possible to achieve in vim mode if the last line is empty, for example). Now, down arrow on any character of the last line will go to the next cell.

File last commit:

r13620:9ac2cb23
r15754:d60e793e
Show More
test_magic_arguments.py
118 lines | 4.5 KiB | text/x-python | PythonLexer
/ IPython / core / tests / test_magic_arguments.py
Robert Kern
ENH: Add the argparse-based option parsing for magics.
r3229 #-----------------------------------------------------------------------------
Matthias BUSSONNIER
update copyright to 2011/20xx-2011...
r5390 # Copyright (C) 2010-2011, IPython Development Team.
Robert Kern
ENH: Add the argparse-based option parsing for magics.
r3229 #
# Distributed under the terms of the Modified BSD License.
#
# The full license is in the file COPYING.txt, distributed with this software.
#-----------------------------------------------------------------------------
Thomas Kluyver
Import argparse directly from stdlib
r12547 import argparse
Thomas Kluyver
Remove uses of @parametric decorator
r12374 from nose.tools import assert_equal
Robert Kern
ENH: Add the argparse-based option parsing for magics.
r3229
from IPython.core.magic_arguments import (argument, argument_group, kwds,
magic_arguments, parse_argstring, real_name)
@magic_arguments()
@argument('-f', '--foo', help="an argument")
def magic_foo1(self, args):
""" A docstring.
"""
return parse_argstring(magic_foo1, args)
Fernando Perez
Convert from nose-style to ours a parametric test....
r3432
Robert Kern
ENH: Add the argparse-based option parsing for magics.
r3229 @magic_arguments()
def magic_foo2(self, args):
""" A docstring.
"""
return parse_argstring(magic_foo2, args)
Fernando Perez
Convert from nose-style to ours a parametric test....
r3432
Robert Kern
ENH: Add the argparse-based option parsing for magics.
r3229 @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)
Fernando Perez
Convert from nose-style to ours a parametric test....
r3432
Robert Kern
ENH: Add the argparse-based option parsing for magics.
r3229 @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)
Fernando Perez
Convert from nose-style to ours a parametric test....
r3432
Robert Kern
ENH: Add the argparse-based option parsing for magics.
r3229 @magic_arguments('frobnicate')
@argument('-f', '--foo', help="an argument")
def magic_foo5(self, args):
""" A docstring.
"""
return parse_argstring(magic_foo5, args)
Fernando Perez
Convert from nose-style to ours a parametric test....
r3432
Robert Kern
ENH: Add the argparse-based option parsing for magics.
r3229 @magic_arguments()
@argument('-f', '--foo', help="an argument")
def magic_magic_foo(self, args):
""" A docstring.
"""
return parse_argstring(magic_magic_foo, args)
Fernando Perez
Convert from nose-style to ours a parametric test....
r3432
Robert Kern
ENH: Add the argparse-based option parsing for magics.
r3229 @magic_arguments()
@argument('-f', '--foo', help="an argument")
def foo(self, args):
""" A docstring.
"""
return parse_argstring(foo, args)
Fernando Perez
Convert from nose-style to ours a parametric test....
r3432
Robert Kern
ENH: Add the argparse-based option parsing for magics.
r3229 def test_magic_arguments():
Thomas Kluyver
Update tests for new magic_arguments docstrings
r13620 assert_equal(magic_foo1.__doc__, '::\n\n %foo1 [-f FOO]\n\n A docstring.\n\noptional arguments:\n -f FOO, --foo FOO an argument\n')
Thomas Kluyver
Remove uses of @parametric decorator
r12374 assert_equal(getattr(magic_foo1, 'argcmd_name', None), None)
assert_equal(real_name(magic_foo1), 'foo1')
assert_equal(magic_foo1(None, ''), argparse.Namespace(foo=None))
assert hasattr(magic_foo1, 'has_arguments')
Thomas Kluyver
Update tests for new magic_arguments docstrings
r13620 assert_equal(magic_foo2.__doc__, '::\n\n %foo2\n\n A docstring.\n')
Thomas Kluyver
Remove uses of @parametric decorator
r12374 assert_equal(getattr(magic_foo2, 'argcmd_name', None), None)
assert_equal(real_name(magic_foo2), 'foo2')
assert_equal(magic_foo2(None, ''), argparse.Namespace())
assert hasattr(magic_foo2, 'has_arguments')
Thomas Kluyver
Update tests for new magic_arguments docstrings
r13620 assert_equal(magic_foo3.__doc__, '::\n\n %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')
Thomas Kluyver
Remove uses of @parametric decorator
r12374 assert_equal(getattr(magic_foo3, 'argcmd_name', None), None)
assert_equal(real_name(magic_foo3), 'foo3')
assert_equal(magic_foo3(None, ''),
Fernando Perez
Convert from nose-style to ours a parametric test....
r3432 argparse.Namespace(bar=None, baz=None, foo=None))
Thomas Kluyver
Remove uses of @parametric decorator
r12374 assert hasattr(magic_foo3, 'has_arguments')
Thomas Kluyver
Update tests for new magic_arguments docstrings
r13620 assert_equal(magic_foo4.__doc__, '::\n\n %foo4 [-f FOO]\n\n A docstring.\n\noptional arguments:\n -f FOO, --foo FOO an argument\n')
Thomas Kluyver
Remove uses of @parametric decorator
r12374 assert_equal(getattr(magic_foo4, 'argcmd_name', None), None)
assert_equal(real_name(magic_foo4), 'foo4')
assert_equal(magic_foo4(None, ''), argparse.Namespace())
assert hasattr(magic_foo4, 'has_arguments')
Thomas Kluyver
Update tests for new magic_arguments docstrings
r13620 assert_equal(magic_foo5.__doc__, '::\n\n %frobnicate [-f FOO]\n\n A docstring.\n\noptional arguments:\n -f FOO, --foo FOO an argument\n')
Thomas Kluyver
Remove uses of @parametric decorator
r12374 assert_equal(getattr(magic_foo5, 'argcmd_name', None), 'frobnicate')
assert_equal(real_name(magic_foo5), 'frobnicate')
assert_equal(magic_foo5(None, ''), argparse.Namespace(foo=None))
assert hasattr(magic_foo5, 'has_arguments')
Thomas Kluyver
Update tests for new magic_arguments docstrings
r13620 assert_equal(magic_magic_foo.__doc__, '::\n\n %magic_foo [-f FOO]\n\n A docstring.\n\noptional arguments:\n -f FOO, --foo FOO an argument\n')
Thomas Kluyver
Remove uses of @parametric decorator
r12374 assert_equal(getattr(magic_magic_foo, 'argcmd_name', None), None)
assert_equal(real_name(magic_magic_foo), 'magic_foo')
assert_equal(magic_magic_foo(None, ''), argparse.Namespace(foo=None))
assert hasattr(magic_magic_foo, 'has_arguments')
Thomas Kluyver
Update tests for new magic_arguments docstrings
r13620 assert_equal(foo.__doc__, '::\n\n %foo [-f FOO]\n\n A docstring.\n\noptional arguments:\n -f FOO, --foo FOO an argument\n')
Thomas Kluyver
Remove uses of @parametric decorator
r12374 assert_equal(getattr(foo, 'argcmd_name', None), None)
assert_equal(real_name(foo), 'foo')
assert_equal(foo(None, ''), argparse.Namespace(foo=None))
assert hasattr(foo, 'has_arguments')