Distinguish check types via plugin type manager

Flake8 and pep8 has historically supported three types of checks:

- Plugins that accept the physical line
- Plugins that accept the logical line
- Plugins that accept the AST tree

The logical place to make this distinction is on the Checkers plugin
type manager class. This adds the foundation for finding plugins that
fall into each class.
This commit is contained in:
Ian Cordasco 2016-02-23 23:20:34 -06:00
parent 1cd5fea730
commit 24d2689a05
3 changed files with 80 additions and 0 deletions

View file

@ -4,6 +4,7 @@ import mock
import pytest
from flake8.plugins import manager as plugin_manager
from flake8 import utils
@ -86,3 +87,24 @@ def test_filenames_from_a_single_file():
assert len(filenames) == 1
assert ['flake8/__init__.py'] == filenames
def test_parameters_for_class_plugin():
"""Verify that we can retrieve the parameters for a class plugin."""
class FakeCheck(object):
def __init__(self, tree):
pass
plugin = plugin_manager.Plugin('plugin-name', object())
plugin._plugin = FakeCheck
assert utils.parameters_for(plugin) == ['tree']
def test_parameters_for_function_plugin():
"""Verify that we retrieve the parameters for a function plugin."""
def fake_plugin(physical_line, self, tree):
pass
plugin = plugin_manager.Plugin('plugin-name', object())
plugin._plugin = fake_plugin
assert utils.parameters_for(plugin) == ['physical_line', 'self', 'tree']