From dda97ea16fcecb56af542268031d6c02afb1d17a 2023-01-09 01:03:26 From: krassowski <5832902+krassowski@users.noreply.github.com> Date: 2023-01-09 01:03:26 Subject: [PATCH] Add two final tests to increase coverage --- diff --git a/IPython/terminal/tests/test_shortcuts.py b/IPython/terminal/tests/test_shortcuts.py index 21434b7..9f15843 100644 --- a/IPython/terminal/tests/test_shortcuts.py +++ b/IPython/terminal/tests/test_shortcuts.py @@ -1,5 +1,6 @@ import pytest from IPython.terminal.shortcuts.auto_suggest import ( + accept, accept_in_vi_insert_mode, accept_token, accept_character, @@ -12,6 +13,7 @@ from IPython.terminal.shortcuts.auto_suggest import ( from prompt_toolkit.history import InMemoryHistory from prompt_toolkit.buffer import Buffer +from prompt_toolkit.auto_suggest import AutoSuggestFromHistory from unittest.mock import patch, Mock @@ -31,6 +33,22 @@ def make_event(text, cursor, suggestion): @pytest.mark.parametrize( + "text, suggestion, expected", + [ + ("", "def out(tag: str, n=50):", "def out(tag: str, n=50):"), + ("def ", "out(tag: str, n=50):", "out(tag: str, n=50):"), + ], +) +def test_accept(text, suggestion, expected): + event = make_event(text, len(text), suggestion) + buffer = event.current_buffer + buffer.insert_text = Mock() + accept(event) + assert buffer.insert_text.called + assert buffer.insert_text.call_args[0] == (expected,) + + +@pytest.mark.parametrize( "text, cursor, suggestion, called", [ ("123456", 6, "123456789", True), @@ -156,6 +174,17 @@ def test_autosuggest_token_empty(): assert forward_word.called +def test_other_providers(): + """Ensure that swapping autosuggestions does not break with other providers""" + provider = AutoSuggestFromHistory() + up = swap_autosuggestion_up(provider) + down = swap_autosuggestion_down(provider) + event = Mock() + event.current_buffer = Buffer() + assert up(event) is None + assert down(event) is None + + async def test_navigable_provider(): provider = NavigableAutoSuggestFromHistory() history = InMemoryHistory(history_strings=["very_a", "very", "very_b", "very_c"])