MCPcopy Index your code
hub / github.com/ipython/ipython / expect_token

Function expect_token

tests/test_tokenutil.py:12–39  ·  view source on GitHub ↗

If cursor_pos is `None`, look for `|` as the cursor position. Assert that the token at the cursor position is `expected`.

(expected: str, cell: str, cursor_pos: int | None = None)

Source from the content-addressed store, hash-verified

10
11
12def expect_token(expected: str, cell: str, cursor_pos: int | None = None) -> None:
13 """
14 If cursor_pos is `None`, look for `|` as the cursor position.
15 Assert that the token at the cursor position is `expected`.
16 """
17 if cursor_pos is None:
18 assert (
19 cursor_count := cell.count("|")
20 ) == 1, (
21 f"Cursor position not specified and found {cursor_count} instance(s) of '|'"
22 )
23 cursor_pos = cell.index("|")
24 cell = cell.replace("|", "")
25 token = token_at_cursor(cell, cursor_pos)
26 offset = 0
27 for line in cell.splitlines():
28 if offset + len(line) >= cursor_pos:
29 break
30 else:
31 offset += len(line) + 1
32 column = cursor_pos - offset
33 line_with_cursor = "%s|%s" % (line[:column], line[column:])
34 assert token == expected, "Expected %r, got %r in: %r (pos %i)" % (
35 expected,
36 token,
37 line_with_cursor,
38 cursor_pos,
39 )
40
41
42def test_simple():

Callers 8

test_simpleFunction · 0.85
test_functionFunction · 0.85
test_multilineFunction · 0.85
test_nested_call_kwargsFunction · 0.85
test_nested_call_argsFunction · 0.85
test_outer_nameFunction · 0.85
test_attrsFunction · 0.85
test_multiline_statementFunction · 0.85

Calls 3

token_at_cursorFunction · 0.90
indexMethod · 0.80
replaceMethod · 0.80

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…