Show More
@@ -1,5 +1,6 b'' | |||
|
1 | 1 | import pytest |
|
2 | 2 | from IPython.terminal.shortcuts.auto_suggest import ( |
|
3 | accept, | |
|
3 | 4 | accept_in_vi_insert_mode, |
|
4 | 5 | accept_token, |
|
5 | 6 | accept_character, |
@@ -12,6 +13,7 b' from IPython.terminal.shortcuts.auto_suggest import (' | |||
|
12 | 13 | |
|
13 | 14 | from prompt_toolkit.history import InMemoryHistory |
|
14 | 15 | from prompt_toolkit.buffer import Buffer |
|
16 | from prompt_toolkit.auto_suggest import AutoSuggestFromHistory | |
|
15 | 17 | |
|
16 | 18 | from unittest.mock import patch, Mock |
|
17 | 19 | |
@@ -31,6 +33,22 b' def make_event(text, cursor, suggestion):' | |||
|
31 | 33 | |
|
32 | 34 | |
|
33 | 35 | @pytest.mark.parametrize( |
|
36 | "text, suggestion, expected", | |
|
37 | [ | |
|
38 | ("", "def out(tag: str, n=50):", "def out(tag: str, n=50):"), | |
|
39 | ("def ", "out(tag: str, n=50):", "out(tag: str, n=50):"), | |
|
40 | ], | |
|
41 | ) | |
|
42 | def test_accept(text, suggestion, expected): | |
|
43 | event = make_event(text, len(text), suggestion) | |
|
44 | buffer = event.current_buffer | |
|
45 | buffer.insert_text = Mock() | |
|
46 | accept(event) | |
|
47 | assert buffer.insert_text.called | |
|
48 | assert buffer.insert_text.call_args[0] == (expected,) | |
|
49 | ||
|
50 | ||
|
51 | @pytest.mark.parametrize( | |
|
34 | 52 | "text, cursor, suggestion, called", |
|
35 | 53 | [ |
|
36 | 54 | ("123456", 6, "123456789", True), |
@@ -156,6 +174,17 b' def test_autosuggest_token_empty():' | |||
|
156 | 174 | assert forward_word.called |
|
157 | 175 | |
|
158 | 176 | |
|
177 | def test_other_providers(): | |
|
178 | """Ensure that swapping autosuggestions does not break with other providers""" | |
|
179 | provider = AutoSuggestFromHistory() | |
|
180 | up = swap_autosuggestion_up(provider) | |
|
181 | down = swap_autosuggestion_down(provider) | |
|
182 | event = Mock() | |
|
183 | event.current_buffer = Buffer() | |
|
184 | assert up(event) is None | |
|
185 | assert down(event) is None | |
|
186 | ||
|
187 | ||
|
159 | 188 | async def test_navigable_provider(): |
|
160 | 189 | provider = NavigableAutoSuggestFromHistory() |
|
161 | 190 | history = InMemoryHistory(history_strings=["very_a", "very", "very_b", "very_c"]) |
General Comments 0
You need to be logged in to leave comments.
Login now