diff --git a/.travis.yml b/.travis.yml index ca2307e..093cff8 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,6 +1,8 @@ language: python python: - "3.6" + - "3.7" + - "3.8" before_install: - pip install -r requirements.txt script: @@ -8,4 +10,4 @@ script: - pytest # - coverage run --source=. -m unittest discover # after_success: - # - coveralls \ No newline at end of file + # - coveralls diff --git a/pyls_mypy/__init__.py b/pyls_mypy/__init__.py index fbe5d98..25b27fb 100644 --- a/pyls_mypy/__init__.py +++ b/pyls_mypy/__init__.py @@ -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 diff --git a/pyls_mypy/plugin.py b/pyls_mypy/plugin.py index 530dea9..dd884ee 100644 --- a/pyls_mypy/plugin.py +++ b/pyls_mypy/plugin.py @@ -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__) @@ -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() diff --git a/requirements.txt b/requirements.txt index b6a814b..009ad66 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,5 +1,4 @@ -future;python_version < '3' flake8 configparser python-language-server -mypy;python_version >= '3.2' +mypy diff --git a/setup.py b/setup.py index d69ef61..32ff9bd 100755 --- a/setup.py +++ b/setup.py @@ -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', + ) diff --git a/test/test_plugin.py b/test/test_plugin.py index 6e13ae3..dc83cb3 100644 --- a/test/test_plugin.py +++ b/test/test_plugin.py @@ -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__ @@ -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] @@ -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]}