##// END OF EJS Templates
Don't try to document notebook & Qt console config options...
Don't try to document notebook & Qt console config options Some of this code should be reused in their respective repos to describe their config options.

File last commit:

r12600:cfd92dce
r21278:2c298f38
Show More
test_handlers.py
97 lines | 3.2 KiB | text/x-python | PythonLexer
Fernando Perez
Fix prefilter bug and move old test_handlers file into proper test suite....
r2659 """Tests for input handlers.
"""
#-----------------------------------------------------------------------------
# Module imports
#-----------------------------------------------------------------------------
dan.milstein
Major refactoring of prefilter mechanism. Much of the transformation process has been moved out of the iplib.InteractiveShell class and into a separate module, IPython.prefilter. In addition, extensive tests have been added for prefiltering.
r657
Fernando Perez
Fix prefilter bug and move old test_handlers file into proper test suite....
r2659 # third party
import nose.tools as nt
# our own packages
from IPython.core import autocall
Thomas Kluyver
Improvements in the code that breaks up user input.
r4744 from IPython.testing import tools as tt
Fernando Perez
Fix prefilter bug and move old test_handlers file into proper test suite....
r2659 from IPython.testing.globalipapp import get_ipython
Thomas Kluyver
Fix almost all IPython.core tests for Python 3.
r4896 from IPython.utils import py3compat
Fernando Perez
Fix prefilter bug and move old test_handlers file into proper test suite....
r2659
#-----------------------------------------------------------------------------
# Globals
#-----------------------------------------------------------------------------
# Get the public instance of IPython
ip = get_ipython()
dan.milstein
Major refactoring of prefilter mechanism. Much of the transformation process has been moved out of the iplib.InteractiveShell class and into a separate module, IPython.prefilter. In addition, extensive tests have been added for prefiltering.
r657
failures = []
num_tests = 0
Fernando Perez
Fix prefilter bug and move old test_handlers file into proper test suite....
r2659 #-----------------------------------------------------------------------------
# Test functions
#-----------------------------------------------------------------------------
class CallableIndexable(object):
def __getitem__(self, idx): return True
def __call__(self, *args, **kws): return True
class Autocallable(autocall.IPyAutocall):
def __call__(self):
return "called"
dan.milstein
Major refactoring of prefilter mechanism. Much of the transformation process has been moved out of the iplib.InteractiveShell class and into a separate module, IPython.prefilter. In addition, extensive tests have been added for prefiltering.
r657 def run(tests):
"""Loop through a list of (pre, post) inputs, where pre is the string
handed to ipython, and post is how that string looks after it's been
transformed (i.e. ipython's notion of _i)"""
Thomas Kluyver
Improvements in the code that breaks up user input.
r4744 tt.check_pairs(ip.prefilter_manager.prefilter_lines, tests)
dan.milstein
Major refactoring of prefilter mechanism. Much of the transformation process has been moved out of the iplib.InteractiveShell class and into a separate module, IPython.prefilter. In addition, extensive tests have been added for prefiltering.
r657
Fernando Perez
Fix prefilter bug and move old test_handlers file into proper test suite....
r2659 def test_handlers():
dan.milstein
Major refactoring of prefilter mechanism. Much of the transformation process has been moved out of the iplib.InteractiveShell class and into a separate module, IPython.prefilter. In addition, extensive tests have been added for prefiltering.
r657 call_idx = CallableIndexable()
Fernando Perez
Fix prefilter bug and move old test_handlers file into proper test suite....
r2659 ip.user_ns['call_idx'] = call_idx
dan.milstein
Major refactoring of prefilter mechanism. Much of the transformation process has been moved out of the iplib.InteractiveShell class and into a separate module, IPython.prefilter. In addition, extensive tests have been added for prefiltering.
r657
# For many of the below, we're also checking that leading whitespace
# turns off the esc char, which it should unless there is a continuation
# line.
Thomas Kluyver
Fix various tests in IPython.core for Python 3.
r4895 run([(i,py3compat.u_format(o)) for i,o in \
[('"no change"', '"no change"'), # normal
Thomas Kluyver
Use standard repr() instead of our own make_quoted_expr().
r5350 (u"lsmagic", "get_ipython().magic({u}'lsmagic ')"), # magic
Fernando Perez
Fix prefilter bug and move old test_handlers file into proper test suite....
r2659 #("a = b # PYTHON-MODE", '_i'), # emacs -- avoids _in cache
Thomas Kluyver
Fix various tests in IPython.core for Python 3.
r4895 ]])
dan.milstein
Major refactoring of prefilter mechanism. Much of the transformation process has been moved out of the iplib.InteractiveShell class and into a separate module, IPython.prefilter. In addition, extensive tests have been added for prefiltering.
r657
# Objects which are instances of IPyAutocall are *always* autocalled
autocallable = Autocallable()
Fernando Perez
Fix prefilter bug and move old test_handlers file into proper test suite....
r2659 ip.user_ns['autocallable'] = autocallable
dan.milstein
Major refactoring of prefilter mechanism. Much of the transformation process has been moved out of the iplib.InteractiveShell class and into a separate module, IPython.prefilter. In addition, extensive tests have been added for prefiltering.
r657
Bernardo B. Marques
remove all trailling spaces
r4872 # auto
Fernando Perez
Fix prefilter bug and move old test_handlers file into proper test suite....
r2659 ip.magic('autocall 0')
dan.milstein
Major refactoring of prefilter mechanism. Much of the transformation process has been moved out of the iplib.InteractiveShell class and into a separate module, IPython.prefilter. In addition, extensive tests have been added for prefiltering.
r657 # Only explicit escapes or instances of IPyAutocallable should get
# expanded
run([
Bernardo B. Marques
remove all trailling spaces
r4872 ('len "abc"', 'len "abc"'),
('autocallable', 'autocallable()'),
Thomas Kluyver
Add test for gh-1117
r5651 # Don't add extra brackets (gh-1117)
Bradley Froehle
Simplify logic for deciding when to rewrite expressions for autocall.
r5654 ('autocallable()', 'autocallable()'),
dan.milstein
Major refactoring of prefilter mechanism. Much of the transformation process has been moved out of the iplib.InteractiveShell class and into a separate module, IPython.prefilter. In addition, extensive tests have been added for prefiltering.
r657 ])
Fernando Perez
Fix prefilter bug and move old test_handlers file into proper test suite....
r2659 ip.magic('autocall 1')
dan.milstein
Major refactoring of prefilter mechanism. Much of the transformation process has been moved out of the iplib.InteractiveShell class and into a separate module, IPython.prefilter. In addition, extensive tests have been added for prefiltering.
r657 run([
('len "abc"', 'len("abc")'),
('len "abc";', 'len("abc");'), # ; is special -- moves out of parens
# Autocall is turned off if first arg is [] and the object
# is both callable and indexable. Like so:
('len [1,2]', 'len([1,2])'), # len doesn't support __getitem__...
('call_idx [1]', 'call_idx [1]'), # call_idx *does*..
('call_idx 1', 'call_idx(1)'),
Bradley Froehle
Simplify logic for deciding when to rewrite expressions for autocall.
r5654 ('len', 'len'), # only at 2 does it auto-call on single args
dan.milstein
Major refactoring of prefilter mechanism. Much of the transformation process has been moved out of the iplib.InteractiveShell class and into a separate module, IPython.prefilter. In addition, extensive tests have been added for prefiltering.
r657 ])
Fernando Perez
Fix prefilter bug and move old test_handlers file into proper test suite....
r2659 ip.magic('autocall 2')
dan.milstein
Major refactoring of prefilter mechanism. Much of the transformation process has been moved out of the iplib.InteractiveShell class and into a separate module, IPython.prefilter. In addition, extensive tests have been added for prefiltering.
r657 run([
('len "abc"', 'len("abc")'),
('len "abc";', 'len("abc");'),
Bernardo B. Marques
remove all trailling spaces
r4872 ('len [1,2]', 'len([1,2])'),
dan.milstein
Major refactoring of prefilter mechanism. Much of the transformation process has been moved out of the iplib.InteractiveShell class and into a separate module, IPython.prefilter. In addition, extensive tests have been added for prefiltering.
r657 ('call_idx [1]', 'call_idx [1]'),
('call_idx 1', 'call_idx(1)'),
# This is what's different:
('len', 'len()'), # only at 2 does it auto-call on single args
])
Fernando Perez
Fix prefilter bug and move old test_handlers file into proper test suite....
r2659 ip.magic('autocall 1')
dan.milstein
Major refactoring of prefilter mechanism. Much of the transformation process has been moved out of the iplib.InteractiveShell class and into a separate module, IPython.prefilter. In addition, extensive tests have been added for prefiltering.
r657
Bradley M. Froehle
s/nt.assert_equals/nt.assert_equal/
r7875 nt.assert_equal(failures, [])