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

Compatibility with mypy 0.730 #349

Merged
merged 5 commits into from
Nov 18, 2019
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
1 change: 1 addition & 0 deletions CONTRIBUTORS.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
Contributors
===

* Abdullah Hilson ([@abumalick](https://github.com/abumalick))
* Amir Rachum ([@Nurdok](https://github.com/Nurdok))
* Anthony Ricaud ([@rik](https://github.com/rik))
* Bram ([@Psycojoker](https://github.com/Psycojoker))
Expand Down
2 changes: 1 addition & 1 deletion docs/usage.rst
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ were run in the metadata section of the report.

If Prospector does not correctly detect your project's dependencies, you can specify them manually from the commandline::

prospector --uses django celery flask
prospector --uses django --uses celery --uses flask


Additionally, if Prospector is automatically detecting a library that you do not in fact use, you can turn off autodetection completely::
Expand Down
8 changes: 5 additions & 3 deletions prospector/tools/mypy/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,9 @@ def configure(self, prospector_config, _):
def run(self, found_files):
paths = [path for path in found_files.iter_module_paths()]
paths.extend(self.options)
result = self.checker.run(paths)
report, _ = result[0], result[1:] # noqa
report, _ = self.checker.run(paths)
messages = report.splitlines()
if messages and messages[-1].startswith(('Found', 'Success')):
del messages[-1]

return [format_message(message) for message in report.splitlines()]
return [format_message(message) for message in messages]
53 changes: 52 additions & 1 deletion tests/tools/mypy/test_mypy_tool.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,17 @@
# -*- coding: utf-8 -*-
import sys
from unittest import SkipTest, TestCase

from prospector.message import Location, Message

if sys.version_info >= (3, 0):
from unittest import mock
else:
import mock


try:
from prospector.tools.mypy import format_message
from prospector.tools.mypy import MypyTool, format_message
except ImportError:
raise SkipTest

Expand Down Expand Up @@ -40,3 +47,47 @@ def test_format_message_without_character(self):
source="mypy", code="error", location=location, message="Important error"
)
self.assertEqual(format_message("file.py:17: error: Important error"), expected)

def test_pre730_format(self):
tool = MypyTool()
found_files = mock.MagicMock()
output = ['file.py:17: error: Important error', 'file.py:17:2: error: Important error']

with mock.patch('mypy.api.run') as mock_mypy:
mock_mypy.return_value = ('\n'.join(output), "unused")
messages = tool.run(found_files)

self.assertEqual(len(messages), len(output))

def test_pre730_format_empty(self):
tool = MypyTool()
found_files = mock.MagicMock()
output = []

with mock.patch('mypy.api.run') as mock_mypy:
mock_mypy.return_value = ('\n'.join(output), "unused")
messages = tool.run(found_files)

self.assertEqual(len(messages), len(output))

def test_post730_format(self):
tool = MypyTool()
found_files = mock.MagicMock()
output = ['file.py:17: error: Important error', 'file.py:17:2: error: Important error', 'Found 2 errors in 1 file (checked 63 source files)']

with mock.patch('mypy.api.run') as mock_mypy:
mock_mypy.return_value = ('\n'.join(output), "unused")
messages = tool.run(found_files)

self.assertEqual(len(messages), len(output) - 1)

def test_post730_format_empty(self):
tool = MypyTool()
found_files = mock.MagicMock()
output = ['Success: no issues found in 9 source files']

with mock.patch('mypy.api.run') as mock_mypy:
mock_mypy.return_value = ('\n'.join(output), "unused")
messages = tool.run(found_files)

self.assertEqual(len(messages), len(output) - 1)