-
-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathtest_server.py
More file actions
69 lines (55 loc) · 1.99 KB
/
Copy pathtest_server.py
File metadata and controls
69 lines (55 loc) · 1.99 KB
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
68
69
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License.
"""
Test for linting over LSP.
"""
from threading import Event
from hamcrest import assert_that, is_
from .lsp_test_client import constants, defaults, session, utils
TEST_FILE_PATH = constants.TEST_DATA / "sample1" / "sample.py"
TEST_FILE_URI = utils.as_uri(str(TEST_FILE_PATH))
SERVER_INFO = utils.get_server_info_defaults()
TIMEOUT = 10 # 10 seconds
def test_linting_example():
"""Test to linting on file open."""
contents = TEST_FILE_PATH.read_text()
actual = []
with session.LspSession() as ls_session:
ls_session.initialize(defaults.VSCODE_DEFAULT_INITIALIZE)
done = Event()
def _handler(params):
nonlocal actual
actual = params
done.set()
ls_session.set_notification_callback(session.PUBLISH_DIAGNOSTICS, _handler)
ls_session.notify_did_open(
{
"textDocument": {
"uri": TEST_FILE_URI,
"languageId": "python",
"version": 1,
"text": contents,
}
}
)
# wait for some time to receive all notifications
done.wait(TIMEOUT)
expected = {
"uri": TEST_FILE_URI,
"diagnostics": [
{
"range": {
"start": {"line": 2, "character": 0},
"end": {"line": 2, "character": 18},
},
"message": "Use of weak MD5 hash for security. Consider usedforsecurity=False",
"severity": 1,
"code": "B324:hashlib",
"codeDescription": {
"href": "https://bandit.readthedocs.io/en/1.9.3/plugins/b324_hashlib.html"
},
"source": SERVER_INFO["name"],
},
],
}
assert_that(actual, is_(expected))