mirror of
https://github.com/PyCQA/flake8.git
synced 2026-04-10 14:54:17 +00:00
Merge pull request #1307 from PyCQA/pre-commit-ci-update-config
[pre-commit.ci] pre-commit autoupdate
This commit is contained in:
commit
5899e7d720
9 changed files with 94 additions and 78 deletions
|
|
@ -1,7 +1,7 @@
|
||||||
exclude: ^tests/fixtures/example-code/
|
exclude: ^tests/fixtures/example-code/
|
||||||
repos:
|
repos:
|
||||||
- repo: https://github.com/pre-commit/pre-commit-hooks
|
- repo: https://github.com/pre-commit/pre-commit-hooks
|
||||||
rev: v2.3.0
|
rev: v3.4.0
|
||||||
hooks:
|
hooks:
|
||||||
- id: check-yaml
|
- id: check-yaml
|
||||||
- id: debug-statements
|
- id: debug-statements
|
||||||
|
|
@ -26,7 +26,7 @@ repos:
|
||||||
- id: pyupgrade
|
- id: pyupgrade
|
||||||
args: [--py36-plus]
|
args: [--py36-plus]
|
||||||
- repo: https://github.com/pre-commit/mirrors-mypy
|
- repo: https://github.com/pre-commit/mirrors-mypy
|
||||||
rev: v0.720
|
rev: v0.812
|
||||||
hooks:
|
hooks:
|
||||||
- id: mypy
|
- id: mypy
|
||||||
exclude: ^(docs/|example-plugin/|tests/fixtures)
|
exclude: ^(docs/|example-plugin/|tests/fixtures)
|
||||||
|
|
|
||||||
|
|
@ -40,11 +40,7 @@ SERIAL_RETRY_ERRNOS = {
|
||||||
|
|
||||||
def _multiprocessing_is_fork(): # type () -> bool
|
def _multiprocessing_is_fork(): # type () -> bool
|
||||||
"""Class state is only preserved when using the `fork` strategy."""
|
"""Class state is only preserved when using the `fork` strategy."""
|
||||||
return (
|
return multiprocessing and multiprocessing.get_start_method() == "fork"
|
||||||
multiprocessing
|
|
||||||
# https://github.com/python/typeshed/pull/3415
|
|
||||||
and multiprocessing.get_start_method() == "fork" # type: ignore
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
class Manager:
|
class Manager:
|
||||||
|
|
@ -396,7 +392,7 @@ class FileChecker:
|
||||||
|
|
||||||
# If we're recovering from a problem in _make_processor, we will not
|
# If we're recovering from a problem in _make_processor, we will not
|
||||||
# have this attribute.
|
# have this attribute.
|
||||||
if hasattr(self, "processor"):
|
if hasattr(self, "processor") and self.processor is not None:
|
||||||
line = self.processor.noqa_line_for(line_number)
|
line = self.processor.noqa_line_for(line_number)
|
||||||
else:
|
else:
|
||||||
line = None
|
line = None
|
||||||
|
|
@ -407,6 +403,7 @@ class FileChecker:
|
||||||
def run_check(self, plugin, **arguments):
|
def run_check(self, plugin, **arguments):
|
||||||
"""Run the check in a single plugin."""
|
"""Run the check in a single plugin."""
|
||||||
LOG.debug("Running %r with %r", plugin, arguments)
|
LOG.debug("Running %r with %r", plugin, arguments)
|
||||||
|
assert self.processor is not None
|
||||||
try:
|
try:
|
||||||
self.processor.keyword_arguments_for(
|
self.processor.keyword_arguments_for(
|
||||||
plugin["parameters"], arguments
|
plugin["parameters"], arguments
|
||||||
|
|
@ -467,6 +464,7 @@ class FileChecker:
|
||||||
|
|
||||||
def run_ast_checks(self) -> None:
|
def run_ast_checks(self) -> None:
|
||||||
"""Run all checks expecting an abstract syntax tree."""
|
"""Run all checks expecting an abstract syntax tree."""
|
||||||
|
assert self.processor is not None
|
||||||
try:
|
try:
|
||||||
ast = self.processor.build_ast()
|
ast = self.processor.build_ast()
|
||||||
except (ValueError, SyntaxError, TypeError) as e:
|
except (ValueError, SyntaxError, TypeError) as e:
|
||||||
|
|
@ -494,6 +492,7 @@ class FileChecker:
|
||||||
|
|
||||||
def run_logical_checks(self):
|
def run_logical_checks(self):
|
||||||
"""Run all checks expecting a logical line."""
|
"""Run all checks expecting a logical line."""
|
||||||
|
assert self.processor is not None
|
||||||
comments, logical_line, mapping = self.processor.build_logical_line()
|
comments, logical_line, mapping = self.processor.build_logical_line()
|
||||||
if not mapping:
|
if not mapping:
|
||||||
return
|
return
|
||||||
|
|
@ -522,6 +521,7 @@ class FileChecker:
|
||||||
|
|
||||||
A single physical check may return multiple errors.
|
A single physical check may return multiple errors.
|
||||||
"""
|
"""
|
||||||
|
assert self.processor is not None
|
||||||
for plugin in self.checks["physical_line_plugins"]:
|
for plugin in self.checks["physical_line_plugins"]:
|
||||||
self.processor.update_checker_state_for(plugin)
|
self.processor.update_checker_state_for(plugin)
|
||||||
result = self.run_check(plugin, physical_line=physical_line)
|
result = self.run_check(plugin, physical_line=physical_line)
|
||||||
|
|
@ -554,6 +554,7 @@ class FileChecker:
|
||||||
Instead of using this directly, you should use
|
Instead of using this directly, you should use
|
||||||
:meth:`flake8.checker.FileChecker.run_checks`.
|
:meth:`flake8.checker.FileChecker.run_checks`.
|
||||||
"""
|
"""
|
||||||
|
assert self.processor is not None
|
||||||
parens = 0
|
parens = 0
|
||||||
statistics = self.statistics
|
statistics = self.statistics
|
||||||
file_processor = self.processor
|
file_processor = self.processor
|
||||||
|
|
@ -577,6 +578,7 @@ class FileChecker:
|
||||||
|
|
||||||
def run_checks(self):
|
def run_checks(self):
|
||||||
"""Run checks against the file."""
|
"""Run checks against the file."""
|
||||||
|
assert self.processor is not None
|
||||||
try:
|
try:
|
||||||
self.process_tokens()
|
self.process_tokens()
|
||||||
self.run_ast_checks()
|
self.run_ast_checks()
|
||||||
|
|
@ -594,6 +596,7 @@ class FileChecker:
|
||||||
|
|
||||||
def handle_newline(self, token_type):
|
def handle_newline(self, token_type):
|
||||||
"""Handle the logic when encountering a newline token."""
|
"""Handle the logic when encountering a newline token."""
|
||||||
|
assert self.processor is not None
|
||||||
if token_type == tokenize.NEWLINE:
|
if token_type == tokenize.NEWLINE:
|
||||||
self.run_logical_checks()
|
self.run_logical_checks()
|
||||||
self.processor.reset_blank_before()
|
self.processor.reset_blank_before()
|
||||||
|
|
@ -608,6 +611,7 @@ class FileChecker:
|
||||||
self, token: processor._Token, prev_physical: str
|
self, token: processor._Token, prev_physical: str
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Run physical checks if and only if it is at the end of the line."""
|
"""Run physical checks if and only if it is at the end of the line."""
|
||||||
|
assert self.processor is not None
|
||||||
# a newline token ends a single physical line.
|
# a newline token ends a single physical line.
|
||||||
if processor.is_eol_token(token):
|
if processor.is_eol_token(token):
|
||||||
# if the file does not end with a newline, the NEWLINE
|
# if the file does not end with a newline, the NEWLINE
|
||||||
|
|
|
||||||
|
|
@ -44,7 +44,7 @@ class Application:
|
||||||
#: The timestamp when the Application instance was instantiated.
|
#: The timestamp when the Application instance was instantiated.
|
||||||
self.start_time = time.time()
|
self.start_time = time.time()
|
||||||
#: The timestamp when the Application finished reported errors.
|
#: The timestamp when the Application finished reported errors.
|
||||||
self.end_time: float = None
|
self.end_time: Optional[float] = None
|
||||||
#: The name of the program being run
|
#: The name of the program being run
|
||||||
self.program = program
|
self.program = program
|
||||||
#: The version of the program being run
|
#: The version of the program being run
|
||||||
|
|
@ -63,24 +63,26 @@ class Application:
|
||||||
options.register_default_options(self.option_manager)
|
options.register_default_options(self.option_manager)
|
||||||
|
|
||||||
#: The instance of :class:`flake8.plugins.manager.Checkers`
|
#: The instance of :class:`flake8.plugins.manager.Checkers`
|
||||||
self.check_plugins: plugin_manager.Checkers = None
|
self.check_plugins: Optional[plugin_manager.Checkers] = None
|
||||||
#: The instance of :class:`flake8.plugins.manager.ReportFormatters`
|
#: The instance of :class:`flake8.plugins.manager.ReportFormatters`
|
||||||
self.formatting_plugins: plugin_manager.ReportFormatters = None
|
self.formatting_plugins: Optional[
|
||||||
|
plugin_manager.ReportFormatters
|
||||||
|
] = None
|
||||||
#: The user-selected formatter from :attr:`formatting_plugins`
|
#: The user-selected formatter from :attr:`formatting_plugins`
|
||||||
self.formatter: BaseFormatter = None
|
self.formatter: Optional[BaseFormatter] = None
|
||||||
#: The :class:`flake8.style_guide.StyleGuideManager` built from the
|
#: The :class:`flake8.style_guide.StyleGuideManager` built from the
|
||||||
#: user's options
|
#: user's options
|
||||||
self.guide: style_guide.StyleGuideManager = None
|
self.guide: Optional[style_guide.StyleGuideManager] = None
|
||||||
#: The :class:`flake8.checker.Manager` that will handle running all of
|
#: The :class:`flake8.checker.Manager` that will handle running all of
|
||||||
#: the checks selected by the user.
|
#: the checks selected by the user.
|
||||||
self.file_checker_manager: checker.Manager = None
|
self.file_checker_manager: Optional[checker.Manager] = None
|
||||||
|
|
||||||
#: The user-supplied options parsed into an instance of
|
#: The user-supplied options parsed into an instance of
|
||||||
#: :class:`argparse.Namespace`
|
#: :class:`argparse.Namespace`
|
||||||
self.options: argparse.Namespace = None
|
self.options: Optional[argparse.Namespace] = None
|
||||||
#: The left over arguments that were not parsed by
|
#: The left over arguments that were not parsed by
|
||||||
#: :attr:`option_manager`
|
#: :attr:`option_manager`
|
||||||
self.args: List[str] = None
|
self.args: Optional[List[str]] = None
|
||||||
#: The number of errors, warnings, and other messages after running
|
#: The number of errors, warnings, and other messages after running
|
||||||
#: flake8 and taking into account ignored errors and lines.
|
#: flake8 and taking into account ignored errors and lines.
|
||||||
self.result_count = 0
|
self.result_count = 0
|
||||||
|
|
@ -128,6 +130,7 @@ class Application:
|
||||||
This should be the last thing called on the application instance. It
|
This should be the last thing called on the application instance. It
|
||||||
will check certain options and exit appropriately.
|
will check certain options and exit appropriately.
|
||||||
"""
|
"""
|
||||||
|
assert self.options is not None
|
||||||
if self.options.count:
|
if self.options.count:
|
||||||
print(self.result_count)
|
print(self.result_count)
|
||||||
|
|
||||||
|
|
@ -162,8 +165,10 @@ class Application:
|
||||||
|
|
||||||
def register_plugin_options(self) -> None:
|
def register_plugin_options(self) -> None:
|
||||||
"""Register options provided by plugins to our option manager."""
|
"""Register options provided by plugins to our option manager."""
|
||||||
|
assert self.check_plugins is not None
|
||||||
self.check_plugins.register_options(self.option_manager)
|
self.check_plugins.register_options(self.option_manager)
|
||||||
self.check_plugins.register_plugin_versions(self.option_manager)
|
self.check_plugins.register_plugin_versions(self.option_manager)
|
||||||
|
assert self.formatting_plugins is not None
|
||||||
self.formatting_plugins.register_options(self.option_manager)
|
self.formatting_plugins.register_options(self.option_manager)
|
||||||
|
|
||||||
def parse_configuration_and_cli(
|
def parse_configuration_and_cli(
|
||||||
|
|
@ -190,15 +195,18 @@ class Application:
|
||||||
if not self.parsed_diff:
|
if not self.parsed_diff:
|
||||||
self.exit()
|
self.exit()
|
||||||
|
|
||||||
|
assert self.check_plugins is not None
|
||||||
self.check_plugins.provide_options(
|
self.check_plugins.provide_options(
|
||||||
self.option_manager, self.options, self.args
|
self.option_manager, self.options, self.args
|
||||||
)
|
)
|
||||||
|
assert self.formatting_plugins is not None
|
||||||
self.formatting_plugins.provide_options(
|
self.formatting_plugins.provide_options(
|
||||||
self.option_manager, self.options, self.args
|
self.option_manager, self.options, self.args
|
||||||
)
|
)
|
||||||
|
|
||||||
def formatter_for(self, formatter_plugin_name):
|
def formatter_for(self, formatter_plugin_name):
|
||||||
"""Retrieve the formatter class by plugin name."""
|
"""Retrieve the formatter class by plugin name."""
|
||||||
|
assert self.formatting_plugins is not None
|
||||||
default_formatter = self.formatting_plugins["default"]
|
default_formatter = self.formatting_plugins["default"]
|
||||||
formatter_plugin = self.formatting_plugins.get(formatter_plugin_name)
|
formatter_plugin = self.formatting_plugins.get(formatter_plugin_name)
|
||||||
if formatter_plugin is None:
|
if formatter_plugin is None:
|
||||||
|
|
@ -214,6 +222,7 @@ class Application:
|
||||||
self, formatter_class: Optional[Type["BaseFormatter"]] = None
|
self, formatter_class: Optional[Type["BaseFormatter"]] = None
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Initialize a formatter based on the parsed options."""
|
"""Initialize a formatter based on the parsed options."""
|
||||||
|
assert self.options is not None
|
||||||
format_plugin = self.options.format
|
format_plugin = self.options.format
|
||||||
if 1 <= self.options.quiet < 2:
|
if 1 <= self.options.quiet < 2:
|
||||||
format_plugin = "quiet-filename"
|
format_plugin = "quiet-filename"
|
||||||
|
|
@ -227,6 +236,8 @@ class Application:
|
||||||
|
|
||||||
def make_guide(self) -> None:
|
def make_guide(self) -> None:
|
||||||
"""Initialize our StyleGuide."""
|
"""Initialize our StyleGuide."""
|
||||||
|
assert self.formatter is not None
|
||||||
|
assert self.options is not None
|
||||||
self.guide = style_guide.StyleGuideManager(
|
self.guide = style_guide.StyleGuideManager(
|
||||||
self.options, self.formatter
|
self.options, self.formatter
|
||||||
)
|
)
|
||||||
|
|
@ -252,6 +263,7 @@ class Application:
|
||||||
:param list files:
|
:param list files:
|
||||||
List of filenames to process
|
List of filenames to process
|
||||||
"""
|
"""
|
||||||
|
assert self.file_checker_manager is not None
|
||||||
if self.running_against_diff:
|
if self.running_against_diff:
|
||||||
files = sorted(self.parsed_diff)
|
files = sorted(self.parsed_diff)
|
||||||
self.file_checker_manager.start(files)
|
self.file_checker_manager.start(files)
|
||||||
|
|
@ -267,9 +279,12 @@ class Application:
|
||||||
|
|
||||||
def report_benchmarks(self):
|
def report_benchmarks(self):
|
||||||
"""Aggregate, calculate, and report benchmarks for this run."""
|
"""Aggregate, calculate, and report benchmarks for this run."""
|
||||||
|
assert self.options is not None
|
||||||
if not self.options.benchmark:
|
if not self.options.benchmark:
|
||||||
return
|
return
|
||||||
|
|
||||||
|
assert self.file_checker_manager is not None
|
||||||
|
assert self.end_time is not None
|
||||||
time_elapsed = self.end_time - self.start_time
|
time_elapsed = self.end_time - self.start_time
|
||||||
statistics = [("seconds elapsed", time_elapsed)]
|
statistics = [("seconds elapsed", time_elapsed)]
|
||||||
add_statistic = statistics.append
|
add_statistic = statistics.append
|
||||||
|
|
@ -280,6 +295,7 @@ class Application:
|
||||||
per_second_description = f"{statistic} processed per second"
|
per_second_description = f"{statistic} processed per second"
|
||||||
add_statistic((per_second_description, int(value / time_elapsed)))
|
add_statistic((per_second_description, int(value / time_elapsed)))
|
||||||
|
|
||||||
|
assert self.formatter is not None
|
||||||
self.formatter.show_benchmarks(statistics)
|
self.formatter.show_benchmarks(statistics)
|
||||||
|
|
||||||
def report_errors(self) -> None:
|
def report_errors(self) -> None:
|
||||||
|
|
@ -289,6 +305,7 @@ class Application:
|
||||||
number of errors, warnings, and other messages found.
|
number of errors, warnings, and other messages found.
|
||||||
"""
|
"""
|
||||||
LOG.info("Reporting errors")
|
LOG.info("Reporting errors")
|
||||||
|
assert self.file_checker_manager is not None
|
||||||
results = self.file_checker_manager.report()
|
results = self.file_checker_manager.report()
|
||||||
self.total_result_count, self.result_count = results
|
self.total_result_count, self.result_count = results
|
||||||
LOG.info(
|
LOG.info(
|
||||||
|
|
@ -299,9 +316,12 @@ class Application:
|
||||||
|
|
||||||
def report_statistics(self):
|
def report_statistics(self):
|
||||||
"""Aggregate and report statistics from this run."""
|
"""Aggregate and report statistics from this run."""
|
||||||
|
assert self.options is not None
|
||||||
if not self.options.statistics:
|
if not self.options.statistics:
|
||||||
return
|
return
|
||||||
|
|
||||||
|
assert self.formatter is not None
|
||||||
|
assert self.guide is not None
|
||||||
self.formatter.show_statistics(self.guide.stats)
|
self.formatter.show_statistics(self.guide.stats)
|
||||||
|
|
||||||
def initialize(self, argv: List[str]) -> None:
|
def initialize(self, argv: List[str]) -> None:
|
||||||
|
|
@ -332,6 +352,7 @@ class Application:
|
||||||
|
|
||||||
def report(self):
|
def report(self):
|
||||||
"""Report errors, statistics, and benchmarks."""
|
"""Report errors, statistics, and benchmarks."""
|
||||||
|
assert self.formatter is not None
|
||||||
self.formatter.start()
|
self.formatter.start()
|
||||||
self.report_errors()
|
self.report_errors()
|
||||||
self.report_statistics()
|
self.report_statistics()
|
||||||
|
|
|
||||||
|
|
@ -251,7 +251,9 @@ class PluginManager: # pylint: disable=too-few-public-methods
|
||||||
for plugin_str in local_plugins:
|
for plugin_str in local_plugins:
|
||||||
name, _, entry_str = plugin_str.partition("=")
|
name, _, entry_str = plugin_str.partition("=")
|
||||||
name, entry_str = name.strip(), entry_str.strip()
|
name, entry_str = name.strip(), entry_str.strip()
|
||||||
entry_point = importlib_metadata.EntryPoint(name, entry_str, None)
|
entry_point = importlib_metadata.EntryPoint(
|
||||||
|
name, entry_str, self.namespace
|
||||||
|
)
|
||||||
self._load_plugin_from_entrypoint(entry_point, local=True)
|
self._load_plugin_from_entrypoint(entry_point, local=True)
|
||||||
|
|
||||||
def _load_entrypoint_plugins(self):
|
def _load_entrypoint_plugins(self):
|
||||||
|
|
|
||||||
|
|
@ -54,20 +54,19 @@ def find_noqa(physical_line: str) -> Optional[Match[str]]:
|
||||||
return defaults.NOQA_INLINE_REGEXP.search(physical_line)
|
return defaults.NOQA_INLINE_REGEXP.search(physical_line)
|
||||||
|
|
||||||
|
|
||||||
_Violation = collections.namedtuple(
|
class Violation(
|
||||||
"Violation",
|
collections.namedtuple(
|
||||||
[
|
"Violation",
|
||||||
"code",
|
[
|
||||||
"filename",
|
"code",
|
||||||
"line_number",
|
"filename",
|
||||||
"column_number",
|
"line_number",
|
||||||
"text",
|
"column_number",
|
||||||
"physical_line",
|
"text",
|
||||||
],
|
"physical_line",
|
||||||
)
|
],
|
||||||
|
)
|
||||||
|
):
|
||||||
class Violation(_Violation):
|
|
||||||
"""Class representing a violation reported by Flake8."""
|
"""Class representing a violation reported by Flake8."""
|
||||||
|
|
||||||
def is_inline_ignored(self, disable_noqa: bool) -> bool:
|
def is_inline_ignored(self, disable_noqa: bool) -> bool:
|
||||||
|
|
|
||||||
|
|
@ -57,7 +57,7 @@ def parse_comma_separated_list(
|
||||||
return [item for item in item_gen if item]
|
return [item for item in item_gen if item]
|
||||||
|
|
||||||
|
|
||||||
_Token = collections.namedtuple("Token", ("tp", "src"))
|
_Token = collections.namedtuple("_Token", ("tp", "src"))
|
||||||
_CODE, _FILE, _COLON, _COMMA, _WS = "code", "file", "colon", "comma", "ws"
|
_CODE, _FILE, _COLON, _COMMA, _WS = "code", "file", "colon", "comma", "ws"
|
||||||
_EOF = "eof"
|
_EOF = "eof"
|
||||||
_FILE_LIST_TOKEN_TYPES = [
|
_FILE_LIST_TOKEN_TYPES = [
|
||||||
|
|
|
||||||
|
|
@ -41,7 +41,9 @@ def test_enable_local_plugin_from_config():
|
||||||
app = application.Application()
|
app = application.Application()
|
||||||
app.initialize(['flake8', '--config', LOCAL_PLUGIN_CONFIG])
|
app.initialize(['flake8', '--config', LOCAL_PLUGIN_CONFIG])
|
||||||
|
|
||||||
|
assert app.check_plugins is not None
|
||||||
assert app.check_plugins['XE'].plugin is ExtensionTestPlugin
|
assert app.check_plugins['XE'].plugin is ExtensionTestPlugin
|
||||||
|
assert app.formatting_plugins is not None
|
||||||
assert app.formatting_plugins['XR'].plugin is ReportTestPlugin
|
assert app.formatting_plugins['XR'].plugin is ReportTestPlugin
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -51,6 +53,7 @@ def test_local_plugin_can_add_option():
|
||||||
app.initialize(
|
app.initialize(
|
||||||
['flake8', '--config', LOCAL_PLUGIN_CONFIG, '--anopt', 'foo'])
|
['flake8', '--config', LOCAL_PLUGIN_CONFIG, '--anopt', 'foo'])
|
||||||
|
|
||||||
|
assert app.options is not None
|
||||||
assert app.options.anopt == 'foo'
|
assert app.options.anopt == 'foo'
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -59,4 +62,5 @@ def test_enable_local_plugin_at_non_installed_path():
|
||||||
app = application.Application()
|
app = application.Application()
|
||||||
app.initialize(['flake8', '--config', LOCAL_PLUGIN_PATH_CONFIG])
|
app.initialize(['flake8', '--config', LOCAL_PLUGIN_PATH_CONFIG])
|
||||||
|
|
||||||
|
assert app.check_plugins is not None
|
||||||
assert app.check_plugins['XE'].plugin.name == 'ExtensionTestPlugin2'
|
assert app.check_plugins['XE'].plugin.name == 'ExtensionTestPlugin2'
|
||||||
|
|
|
||||||
|
|
@ -1,48 +1,34 @@
|
||||||
"""Tests for the flake8.exceptions module."""
|
"""Tests for the flake8.exceptions module."""
|
||||||
import pickle
|
import pickle
|
||||||
|
|
||||||
|
import pytest
|
||||||
|
|
||||||
from flake8 import exceptions
|
from flake8 import exceptions
|
||||||
|
|
||||||
|
|
||||||
class _ExceptionTest:
|
@pytest.mark.parametrize(
|
||||||
def test_pickleable(self):
|
'err',
|
||||||
"""Test that the exception is round-trip pickleable."""
|
(
|
||||||
for proto in range(pickle.HIGHEST_PROTOCOL + 1):
|
exceptions.FailedToLoadPlugin(
|
||||||
new_err = pickle.loads(pickle.dumps(self.err, protocol=proto))
|
plugin_name='plugin_name',
|
||||||
assert str(self.err) == str(new_err)
|
exception=ValueError('boom!'),
|
||||||
orig_e = self.err.original_exception
|
),
|
||||||
new_e = new_err.original_exception
|
exceptions.InvalidSyntax(exception=ValueError('Unexpected token: $')),
|
||||||
assert (type(orig_e), orig_e.args) == (type(new_e), new_e.args)
|
exceptions.PluginRequestedUnknownParameters(
|
||||||
|
plugin={'plugin_name': 'plugin_name'},
|
||||||
|
exception=ValueError('boom!'),
|
||||||
class TestFailedToLoadPlugin(_ExceptionTest):
|
),
|
||||||
"""Tests for the FailedToLoadPlugin exception."""
|
exceptions.PluginExecutionFailed(
|
||||||
|
plugin={'plugin_name': 'plugin_name'},
|
||||||
err = exceptions.FailedToLoadPlugin(
|
exception=ValueError('boom!'),
|
||||||
plugin_name='plugin_name',
|
)
|
||||||
exception=ValueError('boom!'),
|
),
|
||||||
)
|
)
|
||||||
|
def test_pickleable(err):
|
||||||
|
"""Ensure that our exceptions can cross pickle boundaries."""
|
||||||
class TestInvalidSyntax(_ExceptionTest):
|
for proto in range(pickle.HIGHEST_PROTOCOL + 1):
|
||||||
"""Tests for the InvalidSyntax exception."""
|
new_err = pickle.loads(pickle.dumps(err, protocol=proto))
|
||||||
|
assert str(err) == str(new_err)
|
||||||
err = exceptions.InvalidSyntax(exception=ValueError('Unexpected token: $'))
|
orig_e = err.original_exception
|
||||||
|
new_e = new_err.original_exception
|
||||||
|
assert (type(orig_e), orig_e.args) == (type(new_e), new_e.args)
|
||||||
class TestPluginRequestedUnknownParameters(_ExceptionTest):
|
|
||||||
"""Tests for the PluginRequestedUnknownParameters exception."""
|
|
||||||
|
|
||||||
err = exceptions.PluginRequestedUnknownParameters(
|
|
||||||
plugin={'plugin_name': 'plugin_name'},
|
|
||||||
exception=ValueError('boom!'),
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
class TestPluginExecutionFailed(_ExceptionTest):
|
|
||||||
"""Tests for the PluginExecutionFailed exception."""
|
|
||||||
|
|
||||||
err = exceptions.PluginExecutionFailed(
|
|
||||||
plugin={'plugin_name': 'plugin_name'},
|
|
||||||
exception=ValueError('boom!'),
|
|
||||||
)
|
|
||||||
|
|
|
||||||
|
|
@ -18,8 +18,8 @@ def test_calls_entrypoints_creates_plugins_automaticaly(entry_points_mck):
|
||||||
"""Verify that we create Plugins on instantiation."""
|
"""Verify that we create Plugins on instantiation."""
|
||||||
entry_points_mck.return_value = {
|
entry_points_mck.return_value = {
|
||||||
'testing.entrypoints': [
|
'testing.entrypoints': [
|
||||||
importlib_metadata.EntryPoint('T100', '', None),
|
importlib_metadata.EntryPoint('T100', '', 'testing.entrypoints'),
|
||||||
importlib_metadata.EntryPoint('T200', '', None),
|
importlib_metadata.EntryPoint('T200', '', 'testing.entrypoints'),
|
||||||
],
|
],
|
||||||
}
|
}
|
||||||
plugin_mgr = manager.PluginManager(namespace='testing.entrypoints')
|
plugin_mgr = manager.PluginManager(namespace='testing.entrypoints')
|
||||||
|
|
@ -36,8 +36,8 @@ def test_handles_mapping_functions_across_plugins(entry_points_mck):
|
||||||
"""Verify we can use the PluginManager call functions on all plugins."""
|
"""Verify we can use the PluginManager call functions on all plugins."""
|
||||||
entry_points_mck.return_value = {
|
entry_points_mck.return_value = {
|
||||||
'testing.entrypoints': [
|
'testing.entrypoints': [
|
||||||
importlib_metadata.EntryPoint('T100', '', None),
|
importlib_metadata.EntryPoint('T100', '', 'testing.entrypoints'),
|
||||||
importlib_metadata.EntryPoint('T200', '', None),
|
importlib_metadata.EntryPoint('T200', '', 'testing.entrypoints'),
|
||||||
],
|
],
|
||||||
}
|
}
|
||||||
plugin_mgr = manager.PluginManager(namespace='testing.entrypoints')
|
plugin_mgr = manager.PluginManager(namespace='testing.entrypoints')
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue