forked from palantir/python-language-server
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_mccabe_lint.py
More file actions
37 lines (28 loc) · 1.1 KB
/
Copy pathtest_mccabe_lint.py
File metadata and controls
37 lines (28 loc) · 1.1 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
# Copyright 2017 Palantir Technologies, Inc.
from pyls import lsp, uris
from pyls.workspace import Document
from pyls.plugins import mccabe_lint
DOC_URI = uris.from_fs_path(__file__)
DOC = """def hello():
\tpass
"""
DOC_SYNTAX_ERR = """def hello()
\tpass"""
def test_mccabe(config):
old_settings = config.settings
try:
config.update({'plugins': {'mccabe': {'threshold': 1}}})
doc = Document(DOC_URI, DOC)
diags = mccabe_lint.pyls_lint(config, doc)
assert all([d['source'] == 'mccabe' for d in diags])
# One we're expecting is:
msg = 'Cyclomatic complexity too high: 1 (threshold 1)'
mod_import = [d for d in diags if d['message'] == msg][0]
assert mod_import['severity'] == lsp.DiagnosticSeverity.Warning
assert mod_import['range']['start'] == {'line': 1, 'character': 0}
assert mod_import['range']['end'] == {'line': 1, 'character': 6}
finally:
config._settings = old_settings
def test_mccabe_syntax_error(config):
doc = Document(DOC_URI, DOC_SYNTAX_ERR)
assert mccabe_lint.pyls_lint(config, doc) is None