mirror of
https://github.com/PyCQA/flake8.git
synced 2026-04-07 05:26:53 +00:00
rework plugin loading
This commit is contained in:
parent
38c5eceda9
commit
50d69150c1
36 changed files with 1277 additions and 1505 deletions
|
|
@ -1,56 +1,47 @@
|
|||
"""Tests for our debugging module."""
|
||||
from unittest import mock
|
||||
|
||||
import pytest
|
||||
|
||||
from flake8._compat import importlib_metadata
|
||||
from flake8.main import debug
|
||||
from flake8.plugins import finder
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
("versions", "expected"),
|
||||
(
|
||||
([], []),
|
||||
(
|
||||
[("p1", "1"), ("p2", "2"), ("p1", "1")],
|
||||
[
|
||||
{"plugin": "p1", "version": "1"},
|
||||
{"plugin": "p2", "version": "2"},
|
||||
def test_debug_information():
|
||||
def _plugin(pkg, version, ep_name):
|
||||
return finder.LoadedPlugin(
|
||||
finder.Plugin(
|
||||
pkg,
|
||||
version,
|
||||
importlib_metadata.EntryPoint(
|
||||
ep_name, "dne:dne", "flake8.extension"
|
||||
),
|
||||
),
|
||||
None,
|
||||
{},
|
||||
)
|
||||
|
||||
plugins = finder.Plugins(
|
||||
checkers=finder.Checkers(
|
||||
tree=[
|
||||
_plugin("pkg1", "1.2.3", "X1"),
|
||||
_plugin("pkg1", "1.2.3", "X2"),
|
||||
_plugin("pkg2", "4.5.6", "X3"),
|
||||
],
|
||||
logical_line=[],
|
||||
physical_line=[],
|
||||
),
|
||||
),
|
||||
)
|
||||
def test_plugins_from(versions, expected):
|
||||
"""Test that we format plugins appropriately."""
|
||||
option_manager = mock.Mock(**{"manager.versions.return_value": versions})
|
||||
assert expected == debug.plugins_from(option_manager)
|
||||
reporters={},
|
||||
)
|
||||
|
||||
|
||||
@mock.patch("platform.python_implementation", return_value="CPython")
|
||||
@mock.patch("platform.python_version", return_value="3.5.3")
|
||||
@mock.patch("platform.system", return_value="Linux")
|
||||
def test_information(system, pyversion, pyimpl):
|
||||
"""Verify that we return all the information we care about."""
|
||||
expected = {
|
||||
"version": "3.1.0",
|
||||
info = debug.information("9001", plugins)
|
||||
assert info == {
|
||||
"version": "9001",
|
||||
"plugins": [
|
||||
{"plugin": "mccabe", "version": "0.5.9"},
|
||||
{"plugin": "pycodestyle", "version": "2.0.0"},
|
||||
{"plugin": "pkg1", "version": "1.2.3"},
|
||||
{"plugin": "pkg2", "version": "4.5.6"},
|
||||
],
|
||||
"platform": {
|
||||
"python_implementation": "CPython",
|
||||
"python_version": "3.5.3",
|
||||
"system": "Linux",
|
||||
"python_implementation": mock.ANY,
|
||||
"python_version": mock.ANY,
|
||||
"system": mock.ANY,
|
||||
},
|
||||
}
|
||||
plugins = mock.Mock(
|
||||
**{
|
||||
"manager.versions.return_value": [
|
||||
("pycodestyle", "2.0.0"),
|
||||
("mccabe", "0.5.9"),
|
||||
]
|
||||
}
|
||||
)
|
||||
assert expected == debug.information("3.1.0", plugins)
|
||||
pyimpl.assert_called_once_with()
|
||||
pyversion.assert_called_once_with()
|
||||
system.assert_called_once_with()
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue