##// END OF EJS Templates
Fixing minor resize bug on the Mac.
Fixing minor resize bug on the Mac.

File last commit:

r3530:6a9f4e52
r4396:27379eb8
Show More
test_handlers.py
172 lines | 6.4 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
from IPython.testing import decorators as dec
from IPython.testing.globalipapp import get_ipython
#-----------------------------------------------------------------------------
# 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)"""
for pre, post in tests:
global num_tests
num_tests += 1
Thomas Kluyver
Fix core and lib tests so that all tests pass.
r3530 actual = ip.prefilter_manager.prefilter_lines(pre)
dan.milstein
Changing input filtering to require whitespace separation between the initial command (alias, magic, autocall) and rest of line. ...
r707 if actual != None:
actual = actual.rstrip('\n')
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 if actual != post:
failures.append('Expected %r to become %r, found %r' % (
pre, post, actual))
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 # alias expansion
Fernando Perez
Fix prefilter bug and move old test_handlers file into proper test suite....
r2659
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 # We're using 'true' as our syscall of choice because it doesn't
# write anything to stdout.
# Turn off actual execution of aliases, because it's noisy
dan.milstein
Changing input filtering to require whitespace separation between the initial command (alias, magic, autocall) and rest of line. ...
r707 old_system_cmd = ip.system
ip.system = lambda cmd: None
Fernando Perez
Fix prefilter bug and move old test_handlers file into proper test suite....
r2659
ip.alias_manager.alias_table['an_alias'] = (0, 'true')
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 # These are useful for checking a particular recursive alias issue
Fernando Perez
Fix prefilter bug and move old test_handlers file into proper test suite....
r2659 ip.alias_manager.alias_table['top'] = (0, 'd:/cygwin/top')
ip.alias_manager.alias_table['d'] = (0, 'true')
Thomas Kluyver
Modify tests to expect unicode. Now all tests pass again.
r3471 run([("an_alias", 'get_ipython().system(u"true ")'), # alias
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 # Below: recursive aliases should expand whitespace-surrounded
# chars, *not* initial chars which happen to be aliases:
Thomas Kluyver
Modify tests to expect unicode. Now all tests pass again.
r3471 ("top", 'get_ipython().system(u"d:/cygwin/top ")'),
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 ])
dan.milstein
Changing input filtering to require whitespace separation between the initial command (alias, magic, autocall) and rest of line. ...
r707 ip.system = old_system_cmd
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.
run([('"no change"', '"no change"'), # normal
Thomas Kluyver
Modify tests to expect unicode. Now all tests pass again.
r3471 ("!true", 'get_ipython().system(u"true")'), # shell_escapes
("!! true", 'get_ipython().magic(u"sx true")'), # shell_escapes + magic
("!!true", 'get_ipython().magic(u"sx true")'), # shell_escapes + magic
("%lsmagic", 'get_ipython().magic(u"lsmagic ")'), # magic
("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
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
# post-esc-char whitespace goes inside
Thomas Kluyver
Modify tests to expect unicode. Now all tests pass again.
r3471 ("! true", 'get_ipython().system(u" true")'),
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
# handle_help
# These are weak tests -- just looking at what the help handlers
# logs, which is not how it really does its work. But it still
# lets us check the key paths through the handler.
Fernando Perez
Fix prefilter bug and move old test_handlers file into proper test suite....
r2659
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 ("x=1 # what?", "x=1 # what?"), # no help if valid python
])
# multi_line_specials
Fernando Perez
Fix prefilter bug and move old test_handlers file into proper test suite....
r2659 ip.prefilter_manager.multi_line_specials = False
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 # W/ multi_line_specials off, leading ws kills esc chars/autoexpansion
run([
('if 1:\n !true', 'if 1:\n !true'),
('if 1:\n lsmagic', 'if 1:\n lsmagic'),
('if 1:\n an_alias', 'if 1:\n an_alias'),
])
Fernando Perez
Fix prefilter bug and move old test_handlers file into proper test suite....
r2659 ip.prefilter_manager.multi_line_specials = True
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 # initial indents must be preserved.
run([
Thomas Kluyver
Modify tests to expect unicode. Now all tests pass again.
r3471 ('if 1:\n !true', 'if 1:\n get_ipython().system(u"true")'),
('if 2:\n lsmagic', 'if 2:\n get_ipython().magic(u"lsmagic ")'),
('if 1:\n an_alias', 'if 1:\n get_ipython().system(u"true ")'),
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 # Weird one
Thomas Kluyver
Modify tests to expect unicode. Now all tests pass again.
r3471 ('if 1:\n !!true', 'if 1:\n get_ipython().magic(u"sx true")'),
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 # Even with m_l_s on, autocall is off even with special chars
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 ('if 1:\n /fun 1 2', 'if 1:\n /fun 1 2'),
('if 1:\n ;fun 1 2', 'if 1:\n ;fun 1 2'),
('if 1:\n ,fun 1 2', 'if 1:\n ,fun 1 2'),
('if 1:\n ?fun 1 2', 'if 1:\n ?fun 1 2'),
# What about !!
])
# 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
# 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([
('len "abc"', 'len "abc"'),
('autocallable', 'autocallable()'),
(",list 1 2 3", 'list("1", "2", "3")'),
(";list 1 2 3", 'list("1 2 3")'),
("/len range(1,4)", 'len(range(1,4))'),
])
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([
(",list 1 2 3", 'list("1", "2", "3")'),
(";list 1 2 3", 'list("1 2 3")'),
("/len range(1,4)", 'len(range(1,4))'),
('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)'),
('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 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([
(",list 1 2 3", 'list("1", "2", "3")'),
(";list 1 2 3", 'list("1 2 3")'),
("/len range(1,4)", 'len(range(1,4))'),
('len "abc"', 'len("abc")'),
('len "abc";', 'len("abc");'),
('len [1,2]', 'len([1,2])'),
('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
Fernando Perez
Fix prefilter bug and move old test_handlers file into proper test suite....
r2659 nt.assert_equals(failures, [])