mirror of
https://github.com/PyCQA/flake8.git
synced 2026-04-12 07:44:16 +00:00
Merge branch 'simplify-app-tests' into 'master'
Simplify application tests; remove unneeded mocking See merge request !205
This commit is contained in:
commit
cead98598a
1 changed files with 22 additions and 27 deletions
|
|
@ -18,14 +18,9 @@ def options(**kwargs):
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture
|
@pytest.fixture
|
||||||
def mocked_application():
|
def application():
|
||||||
"""Create an application with a mocked OptionManager."""
|
"""Create an application."""
|
||||||
with mock.patch('flake8.options.manager.OptionManager') as optionmanager:
|
return app.Application()
|
||||||
optmgr = optionmanager.return_value = mock.Mock()
|
|
||||||
optmgr.parse_known_args.return_value = (options(), [])
|
|
||||||
application = app.Application()
|
|
||||||
|
|
||||||
return application
|
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.parametrize(
|
@pytest.mark.parametrize(
|
||||||
|
|
@ -36,13 +31,13 @@ def mocked_application():
|
||||||
]
|
]
|
||||||
)
|
)
|
||||||
def test_exit_does_not_raise(result_count, catastrophic, exit_zero,
|
def test_exit_does_not_raise(result_count, catastrophic, exit_zero,
|
||||||
mocked_application):
|
application):
|
||||||
"""Verify Application.exit doesn't raise SystemExit."""
|
"""Verify Application.exit doesn't raise SystemExit."""
|
||||||
mocked_application.result_count = result_count
|
application.result_count = result_count
|
||||||
mocked_application.catastrophic_failure = catastrophic
|
application.catastrophic_failure = catastrophic
|
||||||
mocked_application.options = options(exit_zero=exit_zero)
|
application.options = options(exit_zero=exit_zero)
|
||||||
|
|
||||||
assert mocked_application.exit() is None
|
assert application.exit() is None
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.parametrize(
|
@pytest.mark.parametrize(
|
||||||
|
|
@ -54,50 +49,50 @@ def test_exit_does_not_raise(result_count, catastrophic, exit_zero,
|
||||||
]
|
]
|
||||||
)
|
)
|
||||||
def test_exit_does_raise(result_count, catastrophic, exit_zero, value,
|
def test_exit_does_raise(result_count, catastrophic, exit_zero, value,
|
||||||
mocked_application):
|
application):
|
||||||
"""Verify Application.exit doesn't raise SystemExit."""
|
"""Verify Application.exit doesn't raise SystemExit."""
|
||||||
mocked_application.result_count = result_count
|
application.result_count = result_count
|
||||||
mocked_application.catastrophic_failure = catastrophic
|
application.catastrophic_failure = catastrophic
|
||||||
mocked_application.options = options(exit_zero=exit_zero)
|
application.options = options(exit_zero=exit_zero)
|
||||||
|
|
||||||
with pytest.raises(SystemExit) as excinfo:
|
with pytest.raises(SystemExit) as excinfo:
|
||||||
mocked_application.exit()
|
application.exit()
|
||||||
|
|
||||||
assert excinfo.value.args[0] is value
|
assert excinfo.value.args[0] is value
|
||||||
|
|
||||||
|
|
||||||
def test_missing_default_formatter(mocked_application):
|
def test_missing_default_formatter(application):
|
||||||
"""Verify we raise an ExecutionError when there's no default formatter."""
|
"""Verify we raise an ExecutionError when there's no default formatter."""
|
||||||
mocked_application.formatting_plugins = {}
|
application.formatting_plugins = {}
|
||||||
|
|
||||||
with pytest.raises(exceptions.ExecutionError):
|
with pytest.raises(exceptions.ExecutionError):
|
||||||
mocked_application.formatter_for('fake-plugin-name')
|
application.formatter_for('fake-plugin-name')
|
||||||
|
|
||||||
|
|
||||||
def test_warns_on_unknown_formatter_plugin_name(mocked_application):
|
def test_warns_on_unknown_formatter_plugin_name(application):
|
||||||
"""Verify we log a warning with an unfound plugin."""
|
"""Verify we log a warning with an unfound plugin."""
|
||||||
default = mock.Mock()
|
default = mock.Mock()
|
||||||
execute = default.execute
|
execute = default.execute
|
||||||
mocked_application.formatting_plugins = {
|
application.formatting_plugins = {
|
||||||
'default': default,
|
'default': default,
|
||||||
}
|
}
|
||||||
with mock.patch.object(app.LOG, 'warning') as warning:
|
with mock.patch.object(app.LOG, 'warning') as warning:
|
||||||
assert execute is mocked_application.formatter_for('fake-plugin-name')
|
assert execute is application.formatter_for('fake-plugin-name')
|
||||||
|
|
||||||
assert warning.called is True
|
assert warning.called is True
|
||||||
assert warning.call_count == 1
|
assert warning.call_count == 1
|
||||||
|
|
||||||
|
|
||||||
def test_returns_specified_plugin(mocked_application):
|
def test_returns_specified_plugin(application):
|
||||||
"""Verify we get the plugin we want."""
|
"""Verify we get the plugin we want."""
|
||||||
desired = mock.Mock()
|
desired = mock.Mock()
|
||||||
execute = desired.execute
|
execute = desired.execute
|
||||||
mocked_application.formatting_plugins = {
|
application.formatting_plugins = {
|
||||||
'default': mock.Mock(),
|
'default': mock.Mock(),
|
||||||
'desired': desired,
|
'desired': desired,
|
||||||
}
|
}
|
||||||
|
|
||||||
with mock.patch.object(app.LOG, 'warning') as warning:
|
with mock.patch.object(app.LOG, 'warning') as warning:
|
||||||
assert execute is mocked_application.formatter_for('desired')
|
assert execute is application.formatter_for('desired')
|
||||||
|
|
||||||
assert warning.called is False
|
assert warning.called is False
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue