mirror of
https://github.com/PyCQA/flake8.git
synced 2026-04-07 13:36:54 +00:00
extend black formatting to tests as well
This commit is contained in:
parent
a7174759e9
commit
af1668bf04
45 changed files with 1644 additions and 1307 deletions
|
|
@ -10,10 +10,10 @@ from flake8.main import application as app
|
|||
|
||||
def options(**kwargs):
|
||||
"""Generate argparse.Namespace for our Application."""
|
||||
kwargs.setdefault('verbose', 0)
|
||||
kwargs.setdefault('output_file', None)
|
||||
kwargs.setdefault('count', False)
|
||||
kwargs.setdefault('exit_zero', False)
|
||||
kwargs.setdefault("verbose", 0)
|
||||
kwargs.setdefault("output_file", None)
|
||||
kwargs.setdefault("count", False)
|
||||
kwargs.setdefault("exit_zero", False)
|
||||
return argparse.Namespace(**kwargs)
|
||||
|
||||
|
||||
|
|
@ -24,19 +24,20 @@ def application():
|
|||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
'result_count, catastrophic, exit_zero, value', [
|
||||
"result_count, catastrophic, exit_zero, value",
|
||||
[
|
||||
(0, False, False, False),
|
||||
(0, True, False, True),
|
||||
(2, False, False, True),
|
||||
(2, True, False, True),
|
||||
|
||||
(0, True, True, True),
|
||||
(2, False, True, False),
|
||||
(2, True, True, True),
|
||||
]
|
||||
],
|
||||
)
|
||||
def test_exit_does_raise(result_count, catastrophic, exit_zero, value,
|
||||
application):
|
||||
def test_exit_does_raise(
|
||||
result_count, catastrophic, exit_zero, value, application
|
||||
):
|
||||
"""Verify Application.exit doesn't raise SystemExit."""
|
||||
application.result_count = result_count
|
||||
application.catastrophic_failure = catastrophic
|
||||
|
|
@ -53,10 +54,10 @@ def test_warns_on_unknown_formatter_plugin_name(application):
|
|||
default = mock.Mock()
|
||||
execute = default.execute
|
||||
application.formatting_plugins = {
|
||||
'default': default,
|
||||
"default": default,
|
||||
}
|
||||
with mock.patch.object(app.LOG, 'warning') as warning:
|
||||
assert execute is application.formatter_for('fake-plugin-name')
|
||||
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
|
||||
|
|
@ -67,12 +68,12 @@ def test_returns_specified_plugin(application):
|
|||
desired = mock.Mock()
|
||||
execute = desired.execute
|
||||
application.formatting_plugins = {
|
||||
'default': mock.Mock(),
|
||||
'desired': desired,
|
||||
"default": mock.Mock(),
|
||||
"desired": desired,
|
||||
}
|
||||
|
||||
with mock.patch.object(app.LOG, 'warning') as warning:
|
||||
assert execute is application.formatter_for('desired')
|
||||
with mock.patch.object(app.LOG, "warning") as warning:
|
||||
assert execute is application.formatter_for("desired")
|
||||
|
||||
assert warning.called is False
|
||||
|
||||
|
|
@ -80,10 +81,11 @@ def test_returns_specified_plugin(application):
|
|||
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'])
|
||||
["--foo", "--verbose", "src", "setup.py", "--statistics", "--version"]
|
||||
)
|
||||
|
||||
assert opts.verbose
|
||||
assert args == ['--foo', 'src', 'setup.py', '--statistics', '--version']
|
||||
assert args == ["--foo", "src", "setup.py", "--statistics", "--version"]
|
||||
|
||||
|
||||
def test_prelim_opts_ignore_help(application):
|
||||
|
|
@ -91,16 +93,16 @@ def test_prelim_opts_ignore_help(application):
|
|||
# GIVEN
|
||||
|
||||
# WHEN
|
||||
_, args = application.parse_preliminary_options(['--help', '-h'])
|
||||
_, args = application.parse_preliminary_options(["--help", "-h"])
|
||||
|
||||
# THEN
|
||||
assert args == ['--help', '-h']
|
||||
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):
|
||||
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