From 4144b8cc299676e4db9d5ec20dc592240487ac3c 2023-08-12 22:04:56 From: Abdullah Habib Date: 2023-08-12 22:04:56 Subject: [PATCH] created test for reset_search_buffer --- diff --git a/IPython/terminal/tests/test_shortcuts.py b/IPython/terminal/tests/test_shortcuts.py index 45bb327..263b5c6 100644 --- a/IPython/terminal/tests/test_shortcuts.py +++ b/IPython/terminal/tests/test_shortcuts.py @@ -12,7 +12,7 @@ from IPython.terminal.shortcuts.auto_suggest import ( 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 @@ -20,6 +20,7 @@ from prompt_toolkit.document import Document from prompt_toolkit.auto_suggest import AutoSuggestFromHistory from unittest.mock import patch, Mock +from prompt_toolkit.enums import DEFAULT_BUFFER def test_deprected(): @@ -198,6 +199,24 @@ 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()