mirror of
https://github.com/PyCQA/flake8.git
synced 2026-04-05 04:36:52 +00:00
mypy now passes
This commit is contained in:
parent
b6ba6d4d03
commit
fb7e9338cd
32 changed files with 255 additions and 212 deletions
1
tests/__init__.py
Normal file
1
tests/__init__.py
Normal file
|
|
@ -0,0 +1 @@
|
|||
"""This is here because mypy doesn't understand PEP 420."""
|
||||
|
|
@ -216,9 +216,7 @@ def test_report_order(results, expected_order):
|
|||
|
||||
# _handle_results is the first place which gets the sorted result
|
||||
# Should something non-private be mocked instead?
|
||||
handler = mock.Mock()
|
||||
handler.side_effect = count_side_effect
|
||||
manager._handle_results = handler
|
||||
|
||||
assert manager.report() == (len(results), len(results))
|
||||
handler.assert_called_once_with('placeholder', expected_results)
|
||||
handler = mock.Mock(side_effect=count_side_effect)
|
||||
with mock.patch.object(manager, '_handle_results', handler):
|
||||
assert manager.report() == (len(results), len(results))
|
||||
handler.assert_called_once_with('placeholder', expected_results)
|
||||
|
|
|
|||
|
|
@ -44,7 +44,9 @@ def test_format_needs_to_be_implemented():
|
|||
"""Ensure BaseFormatter#format raises a NotImplementedError."""
|
||||
formatter = base.BaseFormatter(options())
|
||||
with pytest.raises(NotImplementedError):
|
||||
formatter.format('foo')
|
||||
formatter.format(
|
||||
style_guide.Violation('A000', 'file.py', 1, 1, 'error text', None)
|
||||
)
|
||||
|
||||
|
||||
def test_show_source_returns_nothing_when_not_showing_source():
|
||||
|
|
@ -73,6 +75,7 @@ def test_show_source_updates_physical_line_appropriately(line, column):
|
|||
formatter = base.BaseFormatter(options(show_source=True))
|
||||
error = style_guide.Violation('A000', 'file.py', 1, column, 'error', line)
|
||||
output = formatter.show_source(error)
|
||||
assert output
|
||||
_, pointer = output.rsplit('\n', 1)
|
||||
assert pointer.count(' ') == (column - 1)
|
||||
|
||||
|
|
|
|||
|
|
@ -72,8 +72,7 @@ def test_information(system, pyversion, pyimpl):
|
|||
@mock.patch('json.dumps', return_value='{}')
|
||||
def test_print_information_no_plugins(dumps, information, print_mock):
|
||||
"""Verify we print and exit only when we have plugins."""
|
||||
plugins = []
|
||||
option_manager = mock.Mock(registered_plugins=set(plugins))
|
||||
option_manager = mock.Mock(registered_plugins=set())
|
||||
assert debug.print_information(
|
||||
None, None, None, None, option_manager=option_manager,
|
||||
) is None
|
||||
|
|
|
|||
|
|
@ -74,11 +74,10 @@ def test_was_selected_selects_errors(select_list, enable_extensions,
|
|||
|
||||
def test_was_selected_implicitly_selects_errors():
|
||||
"""Verify we detect users implicitly selecting an error."""
|
||||
select_list = []
|
||||
error_code = 'E121'
|
||||
decider = style_guide.DecisionEngine(
|
||||
create_options(
|
||||
select=select_list,
|
||||
select=[],
|
||||
extended_default_select=['E'],
|
||||
),
|
||||
)
|
||||
|
|
|
|||
|
|
@ -75,4 +75,4 @@ def test_config_name_needs_long_option_name():
|
|||
def test_dest_is_not_overridden():
|
||||
"""Show that we do not override custom destinations."""
|
||||
opt = manager.Option('-s', '--short', dest='something_not_short')
|
||||
assert opt.dest == 'something_not_short'
|
||||
assert opt.dest == 'something_not_short' # type: ignore
|
||||
|
|
|
|||
|
|
@ -1,17 +1,10 @@
|
|||
"""Tests for flake8.plugins.manager.PluginTypeManager."""
|
||||
import sys
|
||||
|
||||
import mock
|
||||
import pytest
|
||||
|
||||
from flake8 import exceptions
|
||||
from flake8.plugins import manager
|
||||
|
||||
if sys.version_info >= (3, 3):
|
||||
import collections.abc as collections_abc
|
||||
else:
|
||||
import collections as collections_abc
|
||||
|
||||
TEST_NAMESPACE = "testing.plugin-type-manager"
|
||||
|
||||
|
||||
|
|
@ -91,7 +84,7 @@ def test_generate_call_function():
|
|||
'method_name', optmanager,
|
||||
)
|
||||
|
||||
assert isinstance(func, collections_abc.Callable)
|
||||
assert callable(func)
|
||||
assert func(plugin) is optmanager
|
||||
|
||||
|
||||
|
|
@ -168,15 +161,14 @@ def test_provide_options(PluginManager): # noqa: N803
|
|||
PluginManager.return_value = create_mapping_manager_mock(plugins)
|
||||
optmanager = object()
|
||||
options = object()
|
||||
extra_args = []
|
||||
|
||||
type_mgr = FakeTestType()
|
||||
type_mgr.provide_options(optmanager, options, extra_args)
|
||||
type_mgr.provide_options(optmanager, options, [])
|
||||
|
||||
for plugin in plugins:
|
||||
plugin.provide_options.assert_called_with(optmanager,
|
||||
options,
|
||||
extra_args)
|
||||
[])
|
||||
|
||||
|
||||
@mock.patch('flake8.plugins.manager.PluginManager')
|
||||
|
|
|
|||
|
|
@ -82,7 +82,7 @@ def test_recording_statistics():
|
|||
assert isinstance(key, stats.Key)
|
||||
assert isinstance(value, stats.Statistic)
|
||||
|
||||
assert storage[(DEFAULT_FILENAME, DEFAULT_ERROR_CODE)].count == 1
|
||||
assert storage[stats.Key(DEFAULT_FILENAME, DEFAULT_ERROR_CODE)].count == 1
|
||||
|
||||
|
||||
def test_statistics_for_single_record():
|
||||
|
|
|
|||
|
|
@ -163,12 +163,6 @@ def test_fnmatch(filename, patterns, expected):
|
|||
assert utils.fnmatch(filename, patterns) is expected
|
||||
|
||||
|
||||
def test_fnmatch_returns_the_default_with_empty_default():
|
||||
"""The default parameter should be returned when no patterns are given."""
|
||||
sentinel = object()
|
||||
assert utils.fnmatch('file.py', [], default=sentinel) is sentinel
|
||||
|
||||
|
||||
def test_filenames_from_a_directory():
|
||||
"""Verify that filenames_from walks a directory."""
|
||||
filenames = list(utils.filenames_from('src/flake8/'))
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue