Skip to content

Commit 13df4ad

Browse files
committed
hoist config sections to constant, use in test
1 parent 370cf1b commit 13df4ad

File tree

5 files changed

+36
-2
lines changed

5 files changed

+36
-2
lines changed

python_packages/jupyter_lsp/jupyter_lsp/constants.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,6 @@
88
EP_LISTENER_ALL_V1 = "jupyter_lsp_listener_all_v1"
99
EP_LISTENER_CLIENT_V1 = "jupyter_lsp_listener_client_v1"
1010
EP_LISTENER_SERVER_V1 = "jupyter_lsp_listener_server_v1"
11+
12+
# jupyter*config.d where language_servers can be defined
13+
APP_CONFIG_D_SECTIONS = ["_", "_notebook_", "_server_"]

python_packages/jupyter_lsp/jupyter_lsp/manager.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
from traitlets import Unicode, default
1616

1717
from .constants import (
18+
APP_CONFIG_D_SECTIONS,
1819
EP_LISTENER_ALL_V1,
1920
EP_LISTENER_CLIENT_V1,
2021
EP_LISTENER_SERVER_V1,
@@ -85,7 +86,7 @@ def _default_conf_d_language_servers(self):
8586

8687
manager = ConfigManager(read_config_path=jupyter_config_path())
8788

88-
for app in ["_", "_notebook_", "_server_"]:
89+
for app in APP_CONFIG_D_SECTIONS:
8990
language_servers.update(
9091
**manager.get(f"jupyter{app}config")
9192
.get(self.__class__.__name__, {})

python_packages/jupyter_lsp/jupyter_lsp/tests/conftest.py

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,10 @@
1111

1212
# local imports
1313
from jupyter_lsp import LanguageServerManager
14+
from jupyter_lsp.constants import APP_CONFIG_D_SECTIONS
1415
from jupyter_lsp.handlers import LanguageServersHandler, LanguageServerWebSocketHandler
1516

16-
# these should always be available in a test environment ()
17+
# these should always be available in a test environment
1718
KNOWN_SERVERS = [
1819
"bash-language-server",
1920
"dockerfile-language-server-nodejs",
@@ -46,6 +47,28 @@ def manager() -> LanguageServerManager:
4647
return LanguageServerManager()
4748

4849

50+
@fixture
51+
def echo_spec():
52+
return {"argv": ["echo", "no server here"], "languages": ["klingon"], "version": 2}
53+
54+
55+
@fixture
56+
def echo_conf_json(echo_spec) -> str:
57+
return json.dumps(
58+
{"LanguageServerManager": {"language_servers": {"_echo_": echo_spec}}},
59+
indent=2,
60+
sort_keys=True,
61+
)
62+
63+
64+
@fixture(params=sorted(APP_CONFIG_D_SECTIONS))
65+
def app_config_d(request, tmp_path, monkeypatch) -> pathlib.Path:
66+
conf_d = tmp_path / f"jupyter{request.param}config.d"
67+
conf_d.mkdir()
68+
monkeypatch.setenv("JUPYTER_CONFIG_PATH", f"{tmp_path}")
69+
return conf_d
70+
71+
4972
@fixture(params=sorted(KNOWN_SERVERS))
5073
def known_server(request):
5174
return request.param
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
def test_conf_d_language_servers(echo_conf_json, handlers, app_config_d):
2+
(app_config_d / "echo.json").write_text(echo_conf_json)
3+
handler, ws_handler = handlers
4+
manager = handler.manager
5+
manager.initialize()
6+
assert "_echo_" in [*manager.language_servers]

scripts/utest.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ def run_tests():
2626
"jupyter_lsp",
2727
"--cov-report",
2828
"term-missing:skip-covered",
29+
"--no-cov-on-fail",
2930
"-p",
3031
"no:warnings",
3132
"--flake8",

0 commit comments

Comments
 (0)