Skip to content

Commit

Permalink
Compatibility with mypy 0.730
Browse files Browse the repository at this point in the history
Mypy now returns a summary as the last line of the output. This patch filters them out.

fix #345
  • Loading branch information
rik committed Oct 10, 2019
1 parent 7c47117 commit 1434e63
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 4 deletions.
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)

0 comments on commit 1434e63

Please sign in to comment.