From c97747aab90214f1c9b682aebe3f384a136caee0 2023-01-09 00:43:53 From: krassowski <5832902+krassowski@users.noreply.github.com> Date: 2023-01-09 00:43:53 Subject: [PATCH] Mock session to avoid Windows issues on CI. Instantiating a real session on Windows CI leads to exception: ``` prompt_toolkit.output.win32.NoConsoleScreenBufferError: No Windows console found. Are you running cmd.exe? ``` with the following traceback: ``` IPython\terminal\tests\test_shortcuts.py:214: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ C:\hostedtoolcache\windows\PyPy\3.8.15\x86\lib\site-packages\prompt_toolkit\shortcuts\prompt.py:476: in __init__ self.app = self._create_application(editing_mode, erase_when_done) C:\hostedtoolcache\windows\PyPy\3.8.15\x86\lib\site-packages\prompt_toolkit\shortcuts\prompt.py:765: in _create_application output=self._output, C:\hostedtoolcache\windows\PyPy\3.8.15\x86\lib\site-packages\prompt_toolkit\application\application.py:282: in __init__ self.output = output or session.output C:\hostedtoolcache\windows\PyPy\3.8.15\x86\lib\site-packages\prompt_toolkit\application\current.py:71: in output self._output = create_output() C:\hostedtoolcache\windows\PyPy\3.8.15\x86\lib\site-packages\prompt_toolkit\output\defaults.py:85: in create_output return Win32Output(stdout, default_color_depth=color_depth_from_env) C:\hostedtoolcache\windows\PyPy\3.8.15\x86\lib\site-packages\prompt_toolkit\output\win32.py:114: in __init__ info = self.get_win32_screen_buffer_info() ``` --- diff --git a/IPython/terminal/tests/test_shortcuts.py b/IPython/terminal/tests/test_shortcuts.py index da8e841..21434b7 100644 --- a/IPython/terminal/tests/test_shortcuts.py +++ b/IPython/terminal/tests/test_shortcuts.py @@ -11,7 +11,6 @@ from IPython.terminal.shortcuts.auto_suggest import ( ) from prompt_toolkit.history import InMemoryHistory -from prompt_toolkit.shortcuts import PromptSession from prompt_toolkit.buffer import Buffer from unittest.mock import patch, Mock @@ -207,18 +206,24 @@ async def test_navigable_provider(): assert get_suggestion().text == "_a" +def create_session_mock(): + session = Mock() + session.default_buffer = Buffer() + return session + + def test_navigable_provider_connection(): provider = NavigableAutoSuggestFromHistory() provider.skip_lines = 1 - session_1 = PromptSession() + session_1 = create_session_mock() provider.connect(session_1) assert provider.skip_lines == 1 session_1.default_buffer.on_text_insert.fire() assert provider.skip_lines == 0 - session_2 = PromptSession() + session_2 = create_session_mock() provider.connect(session_2) provider.skip_lines = 2