Skip to content

Commit

Permalink
fix: make flake8 happier
Browse files Browse the repository at this point in the history
Signed-off-by: Jack Cherng <[email protected]>
  • Loading branch information
jfcherng committed Apr 21, 2024
1 parent 33debcc commit 1d67b68
Showing 1 changed file with 14 additions and 18 deletions.
32 changes: 14 additions & 18 deletions tests/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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:
Expand All @@ -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):
Expand All @@ -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()
Expand All @@ -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")
Expand All @@ -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:
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -251,15 +247,15 @@ 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")
yield from self.await_message("textDocument/didChange")
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
Expand Down

0 comments on commit 1d67b68

Please sign in to comment.