|
| 1 | +from pyls import lsp, uris |
| 2 | +from pyls.workspace import Document |
| 3 | +from pyls.plugins import jedi_lint |
| 4 | + |
| 5 | +DOC_URI = uris.from_fs_path(__file__) |
| 6 | +DOC = """import sys |
| 7 | +
|
| 8 | +def hello(): |
| 9 | +\tpass |
| 10 | +
|
| 11 | +import json |
| 12 | +""" |
| 13 | + |
| 14 | +DOC_SYNTAX_ERR = """def hello() |
| 15 | + pass |
| 16 | +""" |
| 17 | + |
| 18 | +DOC_INDENT_ERR = """def hello(): |
| 19 | + x = 1 |
| 20 | + pass |
| 21 | +""" |
| 22 | + |
| 23 | +DOC_ENCODING = u"""# encoding=utf-8 |
| 24 | +import sys |
| 25 | +""" |
| 26 | + |
| 27 | + |
| 28 | +def test_jedi_lint(workspace): |
| 29 | + doc = Document(DOC_URI, workspace, DOC) |
| 30 | + diags = jedi_lint.pyls_lint(doc) |
| 31 | + |
| 32 | + assert len(diags) == 0 |
| 33 | + |
| 34 | + |
| 35 | +def test_syntax_error_jedi(workspace): |
| 36 | + doc = Document(DOC_URI, workspace, DOC_SYNTAX_ERR) |
| 37 | + diag = jedi_lint.pyls_lint(doc)[0] |
| 38 | + |
| 39 | + assert diag['message'] == 'SyntaxError: invalid syntax' |
| 40 | + assert diag['range']['start'] == {'line': 0, 'character': 11} |
| 41 | + assert diag['range']['end'] == {'line': 1, 'character': 0} |
| 42 | + assert diag['severity'] == lsp.DiagnosticSeverity.Error |
| 43 | + |
| 44 | + |
| 45 | +def test_indent_error_jedi(workspace): |
| 46 | + doc = Document(DOC_URI, workspace, DOC_INDENT_ERR) |
| 47 | + diag = jedi_lint.pyls_lint(doc)[0] |
| 48 | + |
| 49 | + assert diag['message'] == "IndentationError: unindent does not match \ |
| 50 | +any outer indentation level" |
| 51 | + assert diag['range']['start'] == {'line': 2, 'character': 0} |
| 52 | + assert diag['range']['end'] == {'line': 2, 'character': 2} |
| 53 | + assert diag['severity'] == lsp.DiagnosticSeverity.Error |
| 54 | + |
| 55 | + |
| 56 | +def test_encoding_jedi(workspace): |
| 57 | + doc = Document(DOC_URI, workspace, DOC_ENCODING) |
| 58 | + diags = jedi_lint.pyls_lint(doc) |
| 59 | + |
| 60 | + assert len(diags) == 0 |
0 commit comments