forked from palantir/python-language-server
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_pyflakes_lint.py
More file actions
62 lines (42 loc) · 1.53 KB
/
Copy pathtest_pyflakes_lint.py
File metadata and controls
62 lines (42 loc) · 1.53 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
# Copyright 2017 Palantir Technologies, Inc.
from pyls import lsp, uris
from pyls.workspace import Document
from pyls.plugins import pyflakes_lint
DOC_URI = uris.from_fs_path(__file__)
DOC = """import sys
def hello():
\tpass
import json
"""
DOC_SYNTAX_ERR = """def hello()
pass
"""
DOC_UNDEFINED_NAME_ERR = "a = b"
DOC_ENCODING = u"""# encoding=utf-8
import sys
"""
def test_pyflakes():
doc = Document(DOC_URI, DOC)
diags = pyflakes_lint.pyls_lint(doc)
# One we're expecting is:
msg = '\'sys\' imported but unused'
unused_import = [d for d in diags if d['message'] == msg][0]
assert unused_import['range']['start'] == {'line': 0, 'character': 0}
assert unused_import['severity'] == lsp.DiagnosticSeverity.Warning
def test_syntax_error_pyflakes():
doc = Document(DOC_URI, DOC_SYNTAX_ERR)
diag = pyflakes_lint.pyls_lint(doc)[0]
assert diag['message'] == 'invalid syntax'
assert diag['range']['start'] == {'line': 0, 'character': 12}
assert diag['severity'] == lsp.DiagnosticSeverity.Error
def test_undefined_name_pyflakes():
doc = Document(DOC_URI, DOC_UNDEFINED_NAME_ERR)
diag = pyflakes_lint.pyls_lint(doc)[0]
assert diag['message'] == 'undefined name \'b\''
assert diag['range']['start'] == {'line': 0, 'character': 4}
assert diag['severity'] == lsp.DiagnosticSeverity.Error
def test_unicode_encoding():
doc = Document(DOC_URI, DOC_ENCODING)
diags = pyflakes_lint.pyls_lint(doc)
assert len(diags) == 1
assert diags[0]['message'] == '\'sys\' imported but unused'