Example #1
0
def test_per_file_caching():
    # Ensure that diagnostics are cached per-file.
    with temp_document(DOC) as doc:
        assert pylint_lint.pyls_lint(doc, True)

    assert not pylint_lint.pyls_lint(Document(uris.from_fs_path(__file__)),
                                     False)
Example #2
0
def test_per_file_caching(config, workspace):
    # Ensure that diagnostics are cached per-file.
    with temp_document(DOC, workspace) as doc:
        assert pylint_lint.pyls_lint(config, doc, True)

    assert not pylint_lint.pyls_lint(
        config, Document(uris.from_fs_path(__file__), workspace), False)
Example #3
0
def test_syntax_error_pylint_py2(config, workspace):
    with temp_document(DOC_SYNTAX_ERR, workspace) as doc:
        diag = pylint_lint.pyls_lint(config, doc, True)[0]

        assert diag['message'].startswith('[syntax-error] invalid syntax')
        # Pylint doesn't give column numbers for invalid syntax.
        assert diag['range']['start'] == {'line': 0, 'character': 0}
        assert diag['severity'] == lsp.DiagnosticSeverity.Error
Example #4
0
def test_syntax_error_pylint_py3(config, workspace):
    with temp_document(DOC_SYNTAX_ERR, workspace) as doc:
        diag = pylint_lint.pyls_lint(config, doc, True)[0]

        assert diag['message'].startswith('[syntax-error] invalid syntax')
        # Pylint doesn't give column numbers for invalid syntax.
        assert diag['range']['start'] == {'line': 0, 'character': 12}
        assert diag['severity'] == lsp.DiagnosticSeverity.Error

        # test running pylint in stdin
        config.plugin_settings('pylint')['executable'] = 'pylint'
        diag = pylint_lint.pyls_lint(config, doc, True)[0]

        assert diag['message'].startswith('invalid syntax')
        # Pylint doesn't give column numbers for invalid syntax.
        assert diag['range']['start'] == {'line': 0, 'character': 12}
        assert diag['severity'] == lsp.DiagnosticSeverity.Error
Example #5
0
def test_undefined_name_pylint(config, make_document):  # pylint: disable=redefined-outer-name
    doc = make_document(DOC_UNDEFINED_NAME_ERR)
    diag = pylint_lint.pyls_lint(config, doc, on_change=False)[0]

    assert diag['message'] == 'Undefined variable \'b\''
    assert diag['range']['start'] == {'line': 0, 'character': 4}
    assert diag['severity'] == lsp.DiagnosticSeverity.Error
    assert diag['code'] == 'undefined-variable'
def test_pylint(config, workspace):
    with temp_document(DOC, workspace) as doc:
        diags = pylint_lint.pyls_lint(config, doc, True)

        msg = '[unused-import] Unused import sys'
        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
Example #7
0
def test_syntax_error_pylint(config, make_document):  # pylint: disable=redefined-outer-name
    doc = make_document(DOC_SYNTAX_ERR)
    diag = pylint_lint.pyls_lint(config, doc, on_change=False)[0]

    assert diag['message'] == 'invalid syntax (<string>, line 1)'
    # sadly, pylint, always outputs column to 0 for these errors...
    assert diag['range']['start'] == {'line': 0, 'character': 0}
    assert diag['severity'] == lsp.DiagnosticSeverity.Error
    assert diag['code'] == 'syntax-error'
Example #8
0
def test_pylint(config, make_document):  # pylint: disable=redefined-outer-name
    doc = make_document(DOC)
    diags = pylint_lint.pyls_lint(config, doc, on_change=False)

    # One we're expecting is:
    msg = 'Unused import sys'
    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
    assert unused_import['code'] == 'unused-import'
Example #9
0
def test_pylint(config, workspace):
    with temp_document(DOC, workspace) as doc:
        diags = pylint_lint.pyls_lint(config, doc, True)

        msg = '[unused-import] Unused import sys'
        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

        if IS_PY3:
            # test running pylint in stdin
            config.plugin_settings('pylint')['executable'] = 'pylint'
            diags = pylint_lint.pyls_lint(config, doc, True)

            msg = 'Unused import sys (unused-import)'
            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
Example #10
0
def test_lint_free_pylint(config, workspace):
    # Can't use temp_document because it might give us a file that doesn't
    # match pylint's naming requirements. We should be keeping this file clean
    # though, so it works for a test of an empty lint.
    assert not pylint_lint.pyls_lint(
        config, Document(uris.from_fs_path(__file__), workspace), True)
Example #11
0
def test_pylint_onchange(config, make_document):  # pylint: disable=redefined-outer-name
    doc = make_document(DOC)
    diags = pylint_lint.pyls_lint(config, doc, on_change=True)

    assert diags == []