MCPcopy Create free account
hub / github.com/ipython/ipython / test_handlers

Function test_handlers

IPython/core/tests/test_handlers.py:44–94  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

42
43
44def test_handlers():
45 call_idx = CallableIndexable()
46 ip.user_ns['call_idx'] = call_idx
47
48 # For many of the below, we're also checking that leading whitespace
49 # turns off the esc char, which it should unless there is a continuation
50 # line.
51 run(
52 [('"no change"', '"no change"'), # normal
53 (u"lsmagic", "get_ipython().run_line_magic('lsmagic', '')"), # magic
54 #("a = b # PYTHON-MODE", '_i'), # emacs -- avoids _in cache
55 ])
56
57 # Objects which are instances of IPyAutocall are *always* autocalled
58 autocallable = Autocallable()
59 ip.user_ns['autocallable'] = autocallable
60
61 # auto
62 ip.magic('autocall 0')
63 # Only explicit escapes or instances of IPyAutocallable should get
64 # expanded
65 run([
66 ('len "abc"', 'len "abc"'),
67 ('autocallable', 'autocallable()'),
68 # Don't add extra brackets (gh-1117)
69 ('autocallable()', 'autocallable()'),
70 ])
71 ip.magic('autocall 1')
72 run([
73 ('len "abc"', 'len("abc")'),
74 ('len "abc";', 'len("abc");'), # ; is special -- moves out of parens
75 # Autocall is turned off if first arg is [] and the object
76 # is both callable and indexable. Like so:
77 ('len [1,2]', 'len([1,2])'), # len doesn't support __getitem__...
78 ('call_idx [1]', 'call_idx [1]'), # call_idx *does*..
79 ('call_idx 1', 'call_idx(1)'),
80 ('len', 'len'), # only at 2 does it auto-call on single args
81 ])
82 ip.magic('autocall 2')
83 run([
84 ('len "abc"', 'len("abc")'),
85 ('len "abc";', 'len("abc");'),
86 ('len [1,2]', 'len([1,2])'),
87 ('call_idx [1]', 'call_idx [1]'),
88 ('call_idx 1', 'call_idx(1)'),
89 # This is what's different:
90 ('len', 'len()'), # only at 2 does it auto-call on single args
91 ])
92 ip.magic('autocall 1')
93
94 nt.assert_equal(failures, [])

Callers

nothing calls this directly

Calls 4

CallableIndexableClass · 0.85
runFunction · 0.85
AutocallableClass · 0.85
magicMethod · 0.45

Tested by

no test coverage detected