mirror of
https://github.com/PyCQA/flake8.git
synced 2026-04-09 06:14:17 +00:00
rework plugin loading
This commit is contained in:
parent
38c5eceda9
commit
50d69150c1
36 changed files with 1277 additions and 1505 deletions
|
|
@ -1,7 +1,5 @@
|
|||
"""Tests for the Application class."""
|
||||
import argparse
|
||||
import sys
|
||||
from unittest import mock
|
||||
|
||||
import pytest
|
||||
|
||||
|
|
@ -44,62 +42,3 @@ def test_application_exit_code(
|
|||
application.options = options(exit_zero=exit_zero)
|
||||
|
||||
assert application.exit_code() == value
|
||||
|
||||
|
||||
def test_warns_on_unknown_formatter_plugin_name(application):
|
||||
"""Verify we log a warning with an unfound plugin."""
|
||||
default = mock.Mock()
|
||||
execute = default.execute
|
||||
application.formatting_plugins = {
|
||||
"default": default,
|
||||
}
|
||||
with mock.patch.object(app.LOG, "warning") as warning:
|
||||
assert execute is application.formatter_for("fake-plugin-name")
|
||||
|
||||
assert warning.called is True
|
||||
assert warning.call_count == 1
|
||||
|
||||
|
||||
def test_returns_specified_plugin(application):
|
||||
"""Verify we get the plugin we want."""
|
||||
desired = mock.Mock()
|
||||
execute = desired.execute
|
||||
application.formatting_plugins = {
|
||||
"default": mock.Mock(),
|
||||
"desired": desired,
|
||||
}
|
||||
|
||||
with mock.patch.object(app.LOG, "warning") as warning:
|
||||
assert execute is application.formatter_for("desired")
|
||||
|
||||
assert warning.called is False
|
||||
|
||||
|
||||
def test_prelim_opts_args(application):
|
||||
"""Verify we get sensible prelim opts and args."""
|
||||
opts, args = application.parse_preliminary_options(
|
||||
["--foo", "--verbose", "src", "setup.py", "--statistics", "--version"]
|
||||
)
|
||||
|
||||
assert opts.verbose
|
||||
assert args == ["--foo", "src", "setup.py", "--statistics", "--version"]
|
||||
|
||||
|
||||
def test_prelim_opts_ignore_help(application):
|
||||
"""Verify -h/--help is not handled."""
|
||||
# GIVEN
|
||||
|
||||
# WHEN
|
||||
_, args = application.parse_preliminary_options(["--help", "-h"])
|
||||
|
||||
# THEN
|
||||
assert args == ["--help", "-h"]
|
||||
|
||||
|
||||
def test_prelim_opts_handles_empty(application):
|
||||
"""Verify empty argv lists are handled correctly."""
|
||||
irrelevant_args = ["myexe", "/path/to/foo"]
|
||||
with mock.patch.object(sys, "argv", irrelevant_args):
|
||||
opts, args = application.parse_preliminary_options([])
|
||||
|
||||
assert args == []
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue