mirror of
https://github.com/PyCQA/flake8.git
synced 2026-04-14 08:24:46 +00:00
rework plugin loading
This commit is contained in:
parent
38c5eceda9
commit
50d69150c1
36 changed files with 1277 additions and 1505 deletions
|
|
@ -1,26 +1,33 @@
|
|||
"""Unit tests for the FileChecker class."""
|
||||
import argparse
|
||||
from unittest import mock
|
||||
|
||||
import pytest
|
||||
|
||||
import flake8
|
||||
from flake8 import checker
|
||||
from flake8._compat import importlib_metadata
|
||||
from flake8.plugins import finder
|
||||
|
||||
|
||||
@mock.patch("flake8.checker.FileChecker._make_processor", return_value=None)
|
||||
def test_repr(*args):
|
||||
"""Verify we generate a correct repr."""
|
||||
file_checker = checker.FileChecker(
|
||||
"example.py",
|
||||
checks={},
|
||||
options=object(),
|
||||
filename="example.py",
|
||||
plugins=finder.Checkers([], [], []),
|
||||
options=argparse.Namespace(),
|
||||
)
|
||||
assert repr(file_checker) == "FileChecker for example.py"
|
||||
|
||||
|
||||
def test_nonexistent_file():
|
||||
"""Verify that checking non-existent file results in an error."""
|
||||
c = checker.FileChecker("foobar.py", checks={}, options=object())
|
||||
c = checker.FileChecker(
|
||||
filename="example.py",
|
||||
plugins=finder.Checkers([], [], []),
|
||||
options=argparse.Namespace(),
|
||||
)
|
||||
|
||||
assert c.processor is None
|
||||
assert not c.should_process
|
||||
|
|
@ -31,17 +38,21 @@ def test_nonexistent_file():
|
|||
|
||||
def test_raises_exception_on_failed_plugin(tmp_path, default_options):
|
||||
"""Checks that a failing plugin results in PluginExecutionFailed."""
|
||||
foobar = tmp_path / "foobar.py"
|
||||
foobar.write_text("I exist!") # Create temp file
|
||||
plugin = {
|
||||
"name": "failure",
|
||||
"plugin_name": "failure", # Both are necessary
|
||||
"parameters": dict(),
|
||||
"plugin": mock.MagicMock(side_effect=ValueError),
|
||||
}
|
||||
"""Verify a failing plugin results in an plugin error"""
|
||||
fname = tmp_path.joinpath("t.py")
|
||||
fname.touch()
|
||||
plugin = finder.LoadedPlugin(
|
||||
finder.Plugin(
|
||||
"plugin-name",
|
||||
"1.2.3",
|
||||
importlib_metadata.EntryPoint("X", "dne:dne", "flake8.extension"),
|
||||
),
|
||||
mock.Mock(side_effect=ValueError),
|
||||
{},
|
||||
)
|
||||
fchecker = checker.FileChecker(
|
||||
str(foobar), checks=[], options=default_options
|
||||
filename=str(fname),
|
||||
plugins=finder.Checkers([], [], []),
|
||||
options=default_options,
|
||||
)
|
||||
with pytest.raises(flake8.exceptions.PluginExecutionFailed):
|
||||
fchecker.run_check(plugin)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue