Skip to content

Commit b018cfa

Browse files
authored
Add basic test to ensure LSP can start and stop (#275)
1 parent dfa7fea commit b018cfa

File tree

2 files changed

+33
-0
lines changed

2 files changed

+33
-0
lines changed

ufmt/tests/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,5 @@
44
from .cli import CliTest
55
from .config import ConfigTest
66
from .core import CoreTest
7+
from .lsp import LspTest
78
from .util import UtilTest

ufmt/tests/lsp.py

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
# Copyright Amethyst Reese
2+
# Licensed under the MIT license
3+
4+
from io import StringIO
5+
from pathlib import Path
6+
from tempfile import TemporaryDirectory
7+
from threading import Timer
8+
from unittest import TestCase
9+
10+
from ufmt.lsp import ufmt_lsp
11+
12+
13+
class LspTest(TestCase):
14+
def setUp(self) -> None:
15+
self.td = TemporaryDirectory()
16+
self.tdp = Path(self.td.name).resolve()
17+
self.addCleanup(self.td.cleanup)
18+
19+
def test_startup_shutdown(self) -> None:
20+
stdin = StringIO()
21+
stdout = StringIO()
22+
23+
server = ufmt_lsp(root=self.tdp)
24+
25+
def times_up() -> None:
26+
server.shutdown() # type:ignore[no-untyped-call]
27+
raise RuntimeError("had to forcefully shutdown lsp")
28+
29+
timer = Timer(5, times_up)
30+
timer.start()
31+
server.start_io(stdin, stdout)
32+
timer.cancel()

0 commit comments

Comments
 (0)