Skip to content

Commit 196058b

Browse files
authored
Fix pylint message in tests (#258)
1 parent 58249bb commit 196058b

File tree

2 files changed

+14
-35
lines changed

2 files changed

+14
-35
lines changed

test/__init__.py

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,9 @@
11
# Copyright 2017-2020 Palantir Technologies, Inc.
22
# Copyright 2021- Python Language Server Contributors.
33

4-
import sys
54
import pytest
65
from pylsp import IS_WIN
76

8-
IS_PY3 = sys.version_info.major == 3
97

108
unix_only = pytest.mark.skipif(IS_WIN, reason="Unix only")
119
windows_only = pytest.mark.skipif(not IS_WIN, reason="Windows only")
12-
py3_only = pytest.mark.skipif(not IS_PY3, reason="Python3 only")
13-
py2_only = pytest.mark.skipif(IS_PY3, reason="Python2 only")

test/plugins/test_pylint_lint.py

Lines changed: 14 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,8 @@
44

55
import contextlib
66
import os
7-
import sys
87
import tempfile
98

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

56-
if IS_PY3:
57-
# test running pylint in stdin
58-
config.plugin_settings('pylint')['executable'] = 'pylint'
59-
diags = pylint_lint.pylsp_lint(config, doc, True)
54+
# test running pylint in stdin
55+
config.plugin_settings('pylint')['executable'] = 'pylint'
56+
diags = pylint_lint.pylsp_lint(config, doc, True)
6057

61-
msg = 'Unused import sys (unused-import)'
62-
unused_import = [d for d in diags if d['message'] == msg][0]
58+
msg = 'Unused import sys (unused-import)'
59+
unused_import = [d for d in diags if d['message'] == msg][0]
6360

64-
assert unused_import['range']['start'] == {
65-
'line': 0,
66-
'character': 0,
67-
}
68-
assert unused_import['severity'] == lsp.DiagnosticSeverity.Warning
61+
assert unused_import['range']['start'] == {
62+
'line': 0,
63+
'character': 0,
64+
}
65+
assert unused_import['severity'] == lsp.DiagnosticSeverity.Warning
6966

7067

71-
@py3_only
72-
def test_syntax_error_pylint_py3(config, workspace):
68+
def test_syntax_error_pylint(config, workspace):
7369
with temp_document(DOC_SYNTAX_ERR, workspace) as doc:
7470
diag = pylint_lint.pylsp_lint(config, doc, True)[0]
7571

76-
if sys.version_info[:2] >= (3, 10):
77-
assert diag['message'].count("[syntax-error] expected ':'")
78-
else:
79-
assert diag['message'].startswith('[syntax-error] invalid syntax')
72+
assert diag['message'].startswith("[syntax-error]")
73+
assert diag['message'].count("expected ':'") or diag['message'].count('invalid syntax')
8074
# Pylint doesn't give column numbers for invalid syntax.
8175
assert diag['range']['start'] == {'line': 0, 'character': 12}
8276
assert diag['severity'] == lsp.DiagnosticSeverity.Error
@@ -86,23 +80,12 @@ def test_syntax_error_pylint_py3(config, workspace):
8680
config.plugin_settings('pylint')['executable'] = 'pylint'
8781
diag = pylint_lint.pylsp_lint(config, doc, True)[0]
8882

89-
assert diag['message'].count("expected ':'") or diag['message'].startswith('invalid syntax')
83+
assert diag['message'].count("expected ':'") or diag['message'].count('invalid syntax')
9084
# Pylint doesn't give column numbers for invalid syntax.
9185
assert diag['range']['start'] == {'line': 0, 'character': 12}
9286
assert diag['severity'] == lsp.DiagnosticSeverity.Error
9387

9488

95-
@py2_only
96-
def test_syntax_error_pylint_py2(config, workspace):
97-
with temp_document(DOC_SYNTAX_ERR, workspace) as doc:
98-
diag = pylint_lint.pylsp_lint(config, doc, True)[0]
99-
100-
assert diag['message'].startswith('[syntax-error] invalid syntax')
101-
# Pylint doesn't give column numbers for invalid syntax.
102-
assert diag['range']['start'] == {'line': 0, 'character': 0}
103-
assert diag['severity'] == lsp.DiagnosticSeverity.Error
104-
105-
10689
def test_lint_free_pylint(config, workspace):
10790
# Can't use temp_document because it might give us a file that doesn't
10891
# match pylint's naming requirements. We should be keeping this file clean

0 commit comments

Comments
 (0)