diff --git a/tests/setup.py b/tests/setup.py index 25a32b8ed..d37b07043 100644 --- a/tests/setup.py +++ b/tests/setup.py @@ -18,16 +18,11 @@ CI = any(key in environ for key in ("TRAVIS", "CI", "GITHUB_ACTIONS")) TIMEOUT_TIME = 10000 if CI else 2000 -text_config = ClientConfig( - name="textls", - selector="text.plain", - command=[], - tcp_port=None) +text_config = ClientConfig(name="textls", selector="text.plain", command=[], tcp_port=None) class YieldPromise: - - __slots__ = ('__done', '__result') + __slots__ = ("__done", "__result") def __init__(self) -> None: self.__done = False @@ -49,7 +44,8 @@ def make_stdio_test_config() -> ClientConfig: name="TEST", command=["python3", join("$packages", "LSP", "tests", "server.py")], selector="text.plain", - enabled=True) + enabled=True, + ) def make_tcp_test_config() -> ClientConfig: @@ -58,7 +54,8 @@ def make_tcp_test_config() -> ClientConfig: command=["python3", join("$packages", "LSP", "tests", "server.py"), "--tcp-port", "$port"], selector="text.plain", tcp_port=0, # select a free one for me - enabled=True) + enabled=True, + ) def add_config(config): @@ -81,7 +78,6 @@ def expand(s: str, w: sublime.Window) -> str: class TextDocumentTestCase(DeferrableTestCase): - @classmethod def get_stdio_test_config(cls) -> ClientConfig: return make_stdio_test_config() @@ -102,9 +98,7 @@ def setUpClass(cls) -> Generator: cls.view = window.open_file(filename) yield {"condition": lambda: not cls.view.is_loading(), "timeout": TIMEOUT_TIME} yield cls.ensure_document_listener_created - yield { - "condition": lambda: cls.wm.get_session(cls.config.name, filename) is not None, - "timeout": TIMEOUT_TIME} + yield {"condition": lambda: cls.wm.get_session(cls.config.name, filename) is not None, "timeout": TIMEOUT_TIME} cls.session = cls.wm.get_session(cls.config.name, filename) yield {"condition": lambda: cls.session.state == ClientStates.READY, "timeout": TIMEOUT_TIME} cls.initialize_params = yield from cls.await_message("initialize") @@ -122,7 +116,7 @@ def setUp(self) -> Generator: self.init_view_settings() yield self.ensure_document_listener_created params = yield from self.await_message("textDocument/didOpen") - self.assertEqual(params['textDocument']['version'], 0) + self.assertEqual(params["textDocument"]["version"], 0) @classmethod def get_test_name(cls) -> str: @@ -211,8 +205,10 @@ def await_promise(cls, promise: YieldPromise | Promise) -> Generator: def await_run_code_action(self, code_action: dict[str, Any]) -> Generator: promise = YieldPromise() sublime.set_timeout_async( - lambda: self.session.run_code_action_async(code_action, progress=False, view=self.view) - .then(promise.fulfill)) + lambda: self.session.run_code_action_async(code_action, progress=False, view=self.view).then( + promise.fulfill + ) + ) yield from self.await_promise(promise) def set_response(self, method: str, response: Any) -> None: @@ -251,7 +247,7 @@ def error_handler(params: Any) -> None: yield from self.await_promise(promise) def await_clear_view_and_save(self) -> Generator: - assert self.view # type: Optional[sublime.View] + assert isinstance(self.view, sublime.View) self.view.run_command("select_all") self.view.run_command("left_delete") self.view.run_command("save") @@ -259,7 +255,7 @@ def await_clear_view_and_save(self) -> Generator: yield from self.await_message("textDocument/didSave") def await_view_change(self, expected_change_count: int) -> Generator: - assert self.view # type: Optional[sublime.View] + assert isinstance(self.view, sublime.View) def condition() -> bool: nonlocal self