From d8d941f98b0abca109251b1ec41bba89874f2ea7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9F=D1=80=D0=B5=D0=B4=D1=80=D0=B0=D0=B3=20=D0=9D=D0=B8?= =?UTF-8?q?=D0=BA=D0=BE=D0=BB=D0=B8=D1=9B?= Date: Thu, 21 Mar 2024 19:59:25 +0100 Subject: [PATCH] this file is needed --- tests/test_mocks.py | 82 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 82 insertions(+) create mode 100644 tests/test_mocks.py diff --git a/tests/test_mocks.py b/tests/test_mocks.py new file mode 100644 index 000000000..177c4f9a2 --- /dev/null +++ b/tests/test_mocks.py @@ -0,0 +1,82 @@ +from LSP.plugin.core.logging import debug +from LSP.plugin.core.protocol import Notification +from LSP.plugin.core.protocol import Request +from LSP.plugin.core.protocol import Response +from LSP.plugin.core.types import ClientConfig +from LSP.plugin.core.typing import List, Any, Callable + + +TEST_CONFIG = ClientConfig(name="test", command=[], selector="text.plain", tcp_port=None) +DISABLED_CONFIG = ClientConfig("test", command=[], selector="text.plain", tcp_port=None, enabled=False) + +basic_responses = { + 'initialize': { + 'capabilities': { + 'testing': True, + 'hoverProvider': True, + 'completionProvider': { + 'triggerCharacters': ['.'], + 'resolveProvider': True + }, + 'textDocumentSync': { + "openClose": True, + "change": 2, + "save": True + }, + 'definitionProvider': True, + 'typeDefinitionProvider': True, + 'declarationProvider': True, + 'implementationProvider': True, + 'documentFormattingProvider': True, + 'selectionRangeProvider': True, + 'renameProvider': True, + 'workspace': { + 'workspaceFolders': { + 'supported': True + } + } + } + } +} + + +class MockSession(object): + def __init__(self, async_response=None) -> None: + self.responses = basic_responses + self._notifications = [] # type: List[Notification] + self._async_response_callback = async_response + + def send_request(self, request: Request, on_success: Callable, on_error: Callable = None) -> None: + response = self.responses.get(request.method) + debug("TEST: responding to", request.method, "with", response) + if self._async_response_callback: + self._async_response_callback(lambda: on_success(response)) + else: + on_success(response) + + def execute_request(self, request: Request) -> Any: + return self.responses.get(request.method) + + def send_notification(self, notification: Notification) -> None: + self._notifications.append(notification) + + def on_notification(self, name, handler: Callable) -> None: + pass + + def on_request(self, name, handler: Callable) -> None: + pass + + def set_error_display_handler(self, handler: Callable) -> None: + pass + + def set_crash_handler(self, handler: Callable) -> None: + pass + + def set_log_payload_handler(self, handler: Callable) -> None: + pass + + def exit(self) -> None: + pass + + def send_response(self, response: Response) -> None: + pass