Skip to content

Fix pylint message in tests #258

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Aug 27, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 0 additions & 4 deletions test/__init__.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,9 @@
# Copyright 2017-2020 Palantir Technologies, Inc.
# Copyright 2021- Python Language Server Contributors.

import sys
import pytest
from pylsp import IS_WIN

IS_PY3 = sys.version_info.major == 3

unix_only = pytest.mark.skipif(IS_WIN, reason="Unix only")
windows_only = pytest.mark.skipif(not IS_WIN, reason="Windows only")
py3_only = pytest.mark.skipif(not IS_PY3, reason="Python3 only")
py2_only = pytest.mark.skipif(IS_PY3, reason="Python2 only")
45 changes: 14 additions & 31 deletions test/plugins/test_pylint_lint.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,8 @@

import contextlib
import os
import sys
import tempfile

from test import py2_only, py3_only, IS_PY3
from pylsp import lsp, uris
from pylsp.workspace import Document
from pylsp.plugins import pylint_lint
Expand Down Expand Up @@ -53,30 +51,26 @@ def test_pylint(config, workspace):
assert unused_import['severity'] == lsp.DiagnosticSeverity.Warning
assert unused_import['tags'] == [lsp.DiagnosticTag.Unnecessary]

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

msg = 'Unused import sys (unused-import)'
unused_import = [d for d in diags if d['message'] == msg][0]
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
assert unused_import['range']['start'] == {
'line': 0,
'character': 0,
}
assert unused_import['severity'] == lsp.DiagnosticSeverity.Warning


@py3_only
def test_syntax_error_pylint_py3(config, workspace):
def test_syntax_error_pylint(config, workspace):
with temp_document(DOC_SYNTAX_ERR, workspace) as doc:
diag = pylint_lint.pylsp_lint(config, doc, True)[0]

if sys.version_info[:2] >= (3, 10):
assert diag['message'].count("[syntax-error] expected ':'")
else:
assert diag['message'].startswith('[syntax-error] invalid syntax')
assert diag['message'].startswith("[syntax-error]")
assert diag['message'].count("expected ':'") or diag['message'].count('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
Expand All @@ -86,23 +80,12 @@ def test_syntax_error_pylint_py3(config, workspace):
config.plugin_settings('pylint')['executable'] = 'pylint'
diag = pylint_lint.pylsp_lint(config, doc, True)[0]

assert diag['message'].count("expected ':'") or diag['message'].startswith('invalid syntax')
assert diag['message'].count("expected ':'") or diag['message'].count('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


@py2_only
def test_syntax_error_pylint_py2(config, workspace):
with temp_document(DOC_SYNTAX_ERR, workspace) as doc:
diag = pylint_lint.pylsp_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


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
Expand Down