##// END OF EJS Templates
Merge pull request #6512 from Carreau/fix-6417...
Merge pull request #6512 from Carreau/fix-6417 Fix font-awesome icons in examples notebook

File last commit:

r16580:de473a1c
r17924:e5cf2e60 merge
Show More
test_tokenutil.py
63 lines | 1.7 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,
"Excpected %r, got %r in: %s" % (
expected, token, line_with_cursor)
)
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'
for i in (6,7,8,10,11,12):
expect_token("foo", cell, i)
def test_multiline():
cell = '\n'.join([
'a = 5',
'b = hello("string", there)'
])
expected = 'hello'
MinRK
update completion_ and objection_info_request...
r16580 start = cell.index(expected)
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
update completion_ and objection_info_request...
r16580 start = cell.index(expected)
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'
idx = cell.find('obj')
for i in range(idx, idx + 3):
expect_token(expected, cell, i)
idx = idx + 4
expected = 'obj.attr'
for i in range(idx, idx + 4):
expect_token(expected, cell, i)
idx = idx + 5
expected = 'obj.attr.subattr'
for i in range(idx, len(cell)):
expect_token(expected, cell, i)