summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorAnthony Sottile <asottile@umich.edu>2019-05-19 17:01:14 -0700
committerAnthony Sottile <asottile@umich.edu>2019-05-19 17:31:04 -0700
commitfb7e9338cd06760a2f9096f976f0e246fc36a09e (patch)
treec2a2a2a907d7540eef0dbd633d6cb52cc50da14a /tests
parentb6ba6d4d03109965d3cf5174d5c2e6868d7d92bb (diff)
downloadflake8-fb7e9338cd06760a2f9096f976f0e246fc36a09e.tar.gz
mypy now passes
Diffstat (limited to 'tests')
-rw-r--r--tests/__init__.py1
-rw-r--r--tests/integration/test_checker.py10
-rw-r--r--tests/unit/test_base_formatter.py5
-rw-r--r--tests/unit/test_debug.py3
-rw-r--r--tests/unit/test_decision_engine.py3
-rw-r--r--tests/unit/test_option.py2
-rw-r--r--tests/unit/test_plugin_type_manager.py14
-rw-r--r--tests/unit/test_statistics.py2
-rw-r--r--tests/unit/test_utils.py6
9 files changed, 16 insertions, 30 deletions
diff --git a/tests/__init__.py b/tests/__init__.py
new file mode 100644
index 0000000..f7ac891
--- /dev/null
+++ b/tests/__init__.py
@@ -0,0 +1 @@
+"""This is here because mypy doesn't understand PEP 420."""
diff --git a/tests/integration/test_checker.py b/tests/integration/test_checker.py
index 0a3703c..a17e5cd 100644
--- a/tests/integration/test_checker.py
+++ b/tests/integration/test_checker.py
@@ -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)
diff --git a/tests/unit/test_base_formatter.py b/tests/unit/test_base_formatter.py
index f28ab80..ec051a8 100644
--- a/tests/unit/test_base_formatter.py
+++ b/tests/unit/test_base_formatter.py
@@ -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)
diff --git a/tests/unit/test_debug.py b/tests/unit/test_debug.py
index 0d1f903..2b7995d 100644
--- a/tests/unit/test_debug.py
+++ b/tests/unit/test_debug.py
@@ -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
diff --git a/tests/unit/test_decision_engine.py b/tests/unit/test_decision_engine.py
index fd87a45..635c9d8 100644
--- a/tests/unit/test_decision_engine.py
+++ b/tests/unit/test_decision_engine.py
@@ -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'],
),
)
diff --git a/tests/unit/test_option.py b/tests/unit/test_option.py
index eb4f95d..e931d13 100644
--- a/tests/unit/test_option.py
+++ b/tests/unit/test_option.py
@@ -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
diff --git a/tests/unit/test_plugin_type_manager.py b/tests/unit/test_plugin_type_manager.py
index e1392a4..4174c58 100644
--- a/tests/unit/test_plugin_type_manager.py
+++ b/tests/unit/test_plugin_type_manager.py
@@ -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')
diff --git a/tests/unit/test_statistics.py b/tests/unit/test_statistics.py
index 31d6276..16896f0 100644
--- a/tests/unit/test_statistics.py
+++ b/tests/unit/test_statistics.py
@@ -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():
diff --git a/tests/unit/test_utils.py b/tests/unit/test_utils.py
index dcbf8b8..9f6925e 100644
--- a/tests/unit/test_utils.py
+++ b/tests/unit/test_utils.py
@@ -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/'))