forked from python-lsp/python-lsp-server
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_configuration.py
67 lines (55 loc) · 2.03 KB
/
test_configuration.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
# Copyright 2021- Python Language Server Contributors.
import os
from unittest.mock import patch
from test.fixtures import CALL_TIMEOUT_IN_SECONDS
from test.test_notebook_document import wait_for_condition
import pytest
from pylsp import IS_WIN
INITIALIZATION_OPTIONS = {
"pylsp": {
"plugins": {
"flake8": {"enabled": True},
"pycodestyle": {"enabled": False},
"pyflakes": {"enabled": False},
},
}
}
@pytest.mark.skipif(IS_WIN, reason="Flaky on Windows")
def test_set_flake8_using_init_opts(client_server_pair):
client, server = client_server_pair
client._endpoint.request(
"initialize",
{
"processId": 1234,
"rootPath": os.path.dirname(__file__),
"initializationOptions": INITIALIZATION_OPTIONS,
},
).result(timeout=CALL_TIMEOUT_IN_SECONDS)
for key, value in INITIALIZATION_OPTIONS["pylsp"]["plugins"].items():
assert server.workspace._config.settings().get("plugins").get(key).get(
"enabled"
) == value.get("enabled")
@pytest.mark.skipif(IS_WIN, reason="Flaky on Windows")
def test_set_flake8_using_workspace_did_change_configuration(client_server_pair):
client, server = client_server_pair
client._endpoint.request(
"initialize",
{
"processId": 1234,
"rootPath": os.path.dirname(__file__),
},
).result(timeout=CALL_TIMEOUT_IN_SECONDS)
assert (
server.workspace._config.settings().get("plugins").get("flake8").get("enabled")
is False
)
with patch.object(server, "_hook") as mock_hook:
client._endpoint.notify(
"workspace/didChangeConfiguration",
{"settings": INITIALIZATION_OPTIONS},
)
wait_for_condition(lambda: mock_hook.call_count >= 1)
for key, value in INITIALIZATION_OPTIONS["pylsp"]["plugins"].items():
assert server.workspace._config.settings().get("plugins").get(key).get(
"enabled"
) == value.get("enabled")