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

Function expect_token

IPython/utils/tests/test_tokenutil.py:9–22  ·  view source on GitHub ↗
(expected, cell, cursor_pos)

Source from the content-addressed store, hash-verified

7from IPython.utils.tokenutil import token_at_cursor, line_at_cursor
8
9def expect_token(expected, cell, cursor_pos):
10 token = token_at_cursor(cell, cursor_pos)
11 offset = 0
12 for line in cell.splitlines():
13 if offset + len(line) >= cursor_pos:
14 break
15 else:
16 offset += len(line)+1
17 column = cursor_pos - offset
18 line_with_cursor = '%s|%s' % (line[:column], line[column:])
19 nt.assert_equal(token, expected,
20 "Expected %r, got %r in: %r (pos %i)" % (
21 expected, token, line_with_cursor, cursor_pos)
22 )
23
24def test_simple():
25 cell = "foo"

Callers 7

test_simpleFunction · 0.85
test_functionFunction · 0.85
test_multilineFunction · 0.85
test_multiline_tokenFunction · 0.85
test_nested_callFunction · 0.85
test_attrsFunction · 0.85
test_multiline_statementFunction · 0.85

Calls 1

token_at_cursorFunction · 0.90

Tested by

no test coverage detected