##// END OF EJS Templates
actually send only one kernel_info request...
actually send only one kernel_info request store the Future for the initial request, allowing subsequent requests to wait on the same pending reply. Previously, any incoming requests that arrived while waiting for the first reply would send their own request.

File last commit:

r18453:c04db182
r18563:0b2c2392
Show More
test_tokenutil.py
70 lines | 2.0 KiB | text/x-python | PythonLexer
MinRK
add utils.tokenutil for getting the token at a cursor offset
r16578 """Tests for tokenutil"""
# Copyright (c) IPython Development Team.
# Distributed under the terms of the Modified BSD License.
import nose.tools as nt
from IPython.utils.tokenutil import token_at_cursor
MinRK
update completion_ and objection_info_request...
r16580 def expect_token(expected, cell, cursor_pos):
token = token_at_cursor(cell, cursor_pos)
offset = 0
for line in cell.splitlines():
if offset + len(line) >= cursor_pos:
break
else:
offset += len(line)
column = cursor_pos - offset
line_with_cursor = '%s|%s' % (line[:column], line[column:])
MinRK
add utils.tokenutil for getting the token at a cursor offset
r16578 line
nt.assert_equal(token, expected,
MinRK
don't pick up tokens right of cursor...
r18453 "Expected %r, got %r in: %r (pos %i)" % (
expected, token, line_with_cursor, cursor_pos)
MinRK
add utils.tokenutil for getting the token at a cursor offset
r16578 )
def test_simple():
cell = "foo"
for i in range(len(cell)):
expect_token("foo", cell, i)
def test_function():
cell = "foo(a=5, b='10')"
expected = 'foo'
MinRK
don't pick up tokens right of cursor...
r18453 # up to `foo(|a=`
for i in range(cell.find('a=') + 1):
expect_token("foo", cell, i)
# find foo after `=`
for i in [cell.find('=') + 1, cell.rfind('=') + 1]:
expect_token("foo", cell, i)
# in between `5,|` and `|b=`
for i in range(cell.find(','), cell.find('b=')):
MinRK
add utils.tokenutil for getting the token at a cursor offset
r16578 expect_token("foo", cell, i)
def test_multiline():
cell = '\n'.join([
'a = 5',
'b = hello("string", there)'
])
expected = 'hello'
MinRK
don't pick up tokens right of cursor...
r18453 start = cell.index(expected) + 1
MinRK
update completion_ and objection_info_request...
r16580 for i in range(start, start + len(expected)):
expect_token(expected, cell, i)
MinRK
add utils.tokenutil for getting the token at a cursor offset
r16578 expected = 'there'
MinRK
don't pick up tokens right of cursor...
r18453 start = cell.index(expected) + 1
MinRK
update completion_ and objection_info_request...
r16580 for i in range(start, start + len(expected)):
expect_token(expected, cell, i)
MinRK
add utils.tokenutil for getting the token at a cursor offset
r16578
def test_attrs():
cell = "foo(a=obj.attr.subattr)"
expected = 'obj'
MinRK
don't pick up tokens right of cursor...
r18453 idx = cell.find('obj') + 1
MinRK
add utils.tokenutil for getting the token at a cursor offset
r16578 for i in range(idx, idx + 3):
expect_token(expected, cell, i)
MinRK
don't pick up tokens right of cursor...
r18453 idx = cell.find('.attr') + 2
MinRK
add utils.tokenutil for getting the token at a cursor offset
r16578 expected = 'obj.attr'
for i in range(idx, idx + 4):
expect_token(expected, cell, i)
MinRK
don't pick up tokens right of cursor...
r18453 idx = cell.find('.subattr') + 2
MinRK
add utils.tokenutil for getting the token at a cursor offset
r16578 expected = 'obj.attr.subattr'
for i in range(idx, len(cell)):
expect_token(expected, cell, i)