Skip to content
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

Drop python 2 compatibility layer & other maintenance goodies #46

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
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: 3 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
language: python
python:
- "3.6"
- "3.7"
- "3.8"
before_install:
- pip install -r requirements.txt
script:
- flake8 --exclude=./versioneer.py
- pytest
# - coverage run --source=. -m unittest discover
# after_success:
# - coveralls
# - coveralls
5 changes: 0 additions & 5 deletions pyls_mypy/__init__.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,4 @@
from ._version import get_versions
import sys

if sys.version_info[0] < 3:
from future.standard_library import install_aliases
install_aliases()

__version__ = get_versions()['version']
del get_versions
4 changes: 2 additions & 2 deletions pyls_mypy/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from mypy import api as mypy_api
from pyls import hookimpl

line_pattern = r"([^:]+):(?:(\d+):)?(?:(\d+):)? (\w+): (.*)"
line_matcher = re.compile(r"([^:]+):(?:(\d+):)?(?:(\d+):)? (\w+): (.*)").match

log = logging.getLogger(__name__)

Expand All @@ -13,7 +13,7 @@ def parse_line(line, document=None):
Return a language-server diagnostic from a line of the Mypy error report;
optionally, use the whole document to provide more context on it.
'''
result = re.match(line_pattern, line)
result = line_matcher(line)
if result:
file_path, lineno, offset, severity, msg = result.groups()

Expand Down
3 changes: 1 addition & 2 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
future;python_version < '3'
flake8
configparser
python-language-server
mypy;python_version >= '3.2'
mypy
13 changes: 12 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,16 @@
from setuptools import setup
import versioneer


if __name__ == "__main__":
setup(version=versioneer.get_version(), cmdclass=versioneer.get_cmdclass())
setup(
version=versioneer.get_version(),
cmdclass=versioneer.get_cmdclass(),
classifiers=[
"Programming Language :: Python :: 3",
"Programming Language :: Python :: 3.6",
"Programming Language :: Python :: 3.7",
"Programming Language :: Python :: 3.8",
],
python_requires='>=3.6',
)
40 changes: 24 additions & 16 deletions test/test_plugin.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import pytest
from unittest.mock import Mock

from pyls.workspace import Document
from pyls import uris
from pyls.workspace import Document, Workspace
from pyls_mypy import plugin

DOC_URI = __file__
Expand All @@ -15,16 +17,26 @@
'error: "Request" has no attribute "id"')


@pytest.fixture
def workspace(tmpdir):
"""Return a workspace."""
return Workspace(uris.from_fs_path(str(tmpdir)), Mock())


@pytest.fixture
def document(workspace):
return Document(DOC_URI, workspace, DOC_TYPE_ERR)


class FakeConfig(object):
def plugin_settings(self, plugin, document_path=None):
return {}


def test_plugin():
def test_plugin(document):
config = FakeConfig()
doc = Document(DOC_URI, DOC_TYPE_ERR)
workspace = None
diags = plugin.pyls_lint(config, workspace, doc, is_saved=False)
diags = plugin.pyls_lint(config, workspace, document, is_saved=False)

assert len(diags) == 1
diag = diags[0]
Expand All @@ -33,35 +45,31 @@ def test_plugin():
assert diag['range']['end'] == {'line': 0, 'character': 1}


def test_parse_full_line():
doc = Document(DOC_URI, DOC_TYPE_ERR)
diag = plugin.parse_line(TEST_LINE, doc)
def test_parse_full_line(document):
diag = plugin.parse_line(TEST_LINE, document)
assert diag['message'] == '"Request" has no attribute "id"'
assert diag['range']['start'] == {'line': 278, 'character': 7}
assert diag['range']['end'] == {'line': 278, 'character': 8}


def test_parse_line_without_col():
doc = Document(DOC_URI, DOC_TYPE_ERR)
diag = plugin.parse_line(TEST_LINE_WITHOUT_COL, doc)
def test_parse_line_without_col(document):
diag = plugin.parse_line(TEST_LINE_WITHOUT_COL, document)
assert diag['message'] == '"Request" has no attribute "id"'
assert diag['range']['start'] == {'line': 278, 'character': 0}
assert diag['range']['end'] == {'line': 278, 'character': 1}


def test_parse_line_without_line():
doc = Document(DOC_URI, DOC_TYPE_ERR)
diag = plugin.parse_line(TEST_LINE_WITHOUT_LINE, doc)
def test_parse_line_without_line(document):
diag = plugin.parse_line(TEST_LINE_WITHOUT_LINE, document)
assert diag['message'] == '"Request" has no attribute "id"'
assert diag['range']['start'] == {'line': 0, 'character': 0}
assert diag['range']['end'] == {'line': 0, 'character': 1}


@pytest.mark.parametrize('word,bounds', [('', (7, 8)), ('my_var', (7, 13))])
def test_parse_line_with_context(monkeypatch, word, bounds):
doc = Document(DOC_URI, 'DOC_TYPE_ERR')
def test_parse_line_with_context(monkeypatch, word, bounds, document):
monkeypatch.setattr(Document, 'word_at_position', lambda *args: word)
diag = plugin.parse_line(TEST_LINE, doc)
diag = plugin.parse_line(TEST_LINE, document)
assert diag['message'] == '"Request" has no attribute "id"'
assert diag['range']['start'] == {'line': 278, 'character': bounds[0]}
assert diag['range']['end'] == {'line': 278, 'character': bounds[1]}