Skip to content

Commit

Permalink
created test for reset_search_buffer (#14135)
Browse files Browse the repository at this point in the history
Referring to issue #13969

reset_search_buffer is not covered by tests
  • Loading branch information
Carreau committed Aug 28, 2023
2 parents a38512c + 183c3d6 commit 78d1f17
Showing 1 changed file with 18 additions and 1 deletion.
19 changes: 18 additions & 1 deletion IPython/terminal/tests/test_shortcuts.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,13 @@
swap_autosuggestion_down,
)
from IPython.terminal.shortcuts.auto_match import skip_over
from IPython.terminal.shortcuts import create_ipython_shortcuts
from IPython.terminal.shortcuts import create_ipython_shortcuts, reset_search_buffer

from prompt_toolkit.history import InMemoryHistory
from prompt_toolkit.buffer import Buffer
from prompt_toolkit.document import Document
from prompt_toolkit.auto_suggest import AutoSuggestFromHistory
from prompt_toolkit.enums import DEFAULT_BUFFER

from unittest.mock import patch, Mock

Expand Down Expand Up @@ -198,6 +199,22 @@ def test_autosuggest_token_empty():
assert forward_word.called


def test_reset_search_buffer():
event_with_text = Mock()
event_with_text.current_buffer.document.text = "some text"
event_with_text.current_buffer.reset = Mock()

event_empty = Mock()
event_empty.current_buffer.document.text = ""
event_empty.app.layout.focus = Mock()

reset_search_buffer(event_with_text)
event_with_text.current_buffer.reset.assert_called_once()

reset_search_buffer(event_empty)
event_empty.app.layout.focus.assert_called_once_with(DEFAULT_BUFFER)


def test_other_providers():
"""Ensure that swapping autosuggestions does not break with other providers"""
provider = AutoSuggestFromHistory()
Expand Down

0 comments on commit 78d1f17

Please sign in to comment.