mirror of
https://github.com/PyCQA/flake8.git
synced 2026-04-06 13:06:53 +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
|
|
@ -12,51 +12,82 @@ def test_dependencies():
|
|||
assert [] == debug.dependencies()
|
||||
|
||||
|
||||
@pytest.mark.parametrize('plugins, expected', [
|
||||
([], []),
|
||||
([manager.PluginVersion('pycodestyle', '2.0.0', False)],
|
||||
[{'plugin': 'pycodestyle', 'version': '2.0.0', 'is_local': False}]),
|
||||
([manager.PluginVersion('pycodestyle', '2.0.0', False),
|
||||
manager.PluginVersion('mccabe', '0.5.9', False)],
|
||||
[{'plugin': 'mccabe', 'version': '0.5.9', 'is_local': False},
|
||||
{'plugin': 'pycodestyle', 'version': '2.0.0', 'is_local': False}]),
|
||||
([manager.PluginVersion('pycodestyle', '2.0.0', False),
|
||||
manager.PluginVersion('my-local', '0.0.1', True),
|
||||
manager.PluginVersion('mccabe', '0.5.9', False)],
|
||||
[{'plugin': 'mccabe', 'version': '0.5.9', 'is_local': False},
|
||||
{'plugin': 'my-local', 'version': '0.0.1', 'is_local': True},
|
||||
{'plugin': 'pycodestyle', 'version': '2.0.0', 'is_local': False}]),
|
||||
])
|
||||
@pytest.mark.parametrize(
|
||||
"plugins, expected",
|
||||
[
|
||||
([], []),
|
||||
(
|
||||
[manager.PluginVersion("pycodestyle", "2.0.0", False)],
|
||||
[
|
||||
{
|
||||
"plugin": "pycodestyle",
|
||||
"version": "2.0.0",
|
||||
"is_local": False,
|
||||
}
|
||||
],
|
||||
),
|
||||
(
|
||||
[
|
||||
manager.PluginVersion("pycodestyle", "2.0.0", False),
|
||||
manager.PluginVersion("mccabe", "0.5.9", False),
|
||||
],
|
||||
[
|
||||
{"plugin": "mccabe", "version": "0.5.9", "is_local": False},
|
||||
{
|
||||
"plugin": "pycodestyle",
|
||||
"version": "2.0.0",
|
||||
"is_local": False,
|
||||
},
|
||||
],
|
||||
),
|
||||
(
|
||||
[
|
||||
manager.PluginVersion("pycodestyle", "2.0.0", False),
|
||||
manager.PluginVersion("my-local", "0.0.1", True),
|
||||
manager.PluginVersion("mccabe", "0.5.9", False),
|
||||
],
|
||||
[
|
||||
{"plugin": "mccabe", "version": "0.5.9", "is_local": False},
|
||||
{"plugin": "my-local", "version": "0.0.1", "is_local": True},
|
||||
{
|
||||
"plugin": "pycodestyle",
|
||||
"version": "2.0.0",
|
||||
"is_local": False,
|
||||
},
|
||||
],
|
||||
),
|
||||
],
|
||||
)
|
||||
def test_plugins_from(plugins, expected):
|
||||
"""Test that we format plugins appropriately."""
|
||||
option_manager = mock.Mock(registered_plugins=set(plugins))
|
||||
assert expected == debug.plugins_from(option_manager)
|
||||
|
||||
|
||||
@mock.patch('platform.python_implementation', return_value='CPython')
|
||||
@mock.patch('platform.python_version', return_value='3.5.3')
|
||||
@mock.patch('platform.system', return_value='Linux')
|
||||
@mock.patch("platform.python_implementation", return_value="CPython")
|
||||
@mock.patch("platform.python_version", return_value="3.5.3")
|
||||
@mock.patch("platform.system", return_value="Linux")
|
||||
def test_information(system, pyversion, pyimpl):
|
||||
"""Verify that we return all the information we care about."""
|
||||
expected = {
|
||||
'version': '3.1.0',
|
||||
'plugins': [{'plugin': 'mccabe', 'version': '0.5.9',
|
||||
'is_local': False},
|
||||
{'plugin': 'pycodestyle', 'version': '2.0.0',
|
||||
'is_local': False}],
|
||||
'dependencies': [],
|
||||
'platform': {
|
||||
'python_implementation': 'CPython',
|
||||
'python_version': '3.5.3',
|
||||
'system': 'Linux',
|
||||
"version": "3.1.0",
|
||||
"plugins": [
|
||||
{"plugin": "mccabe", "version": "0.5.9", "is_local": False},
|
||||
{"plugin": "pycodestyle", "version": "2.0.0", "is_local": False},
|
||||
],
|
||||
"dependencies": [],
|
||||
"platform": {
|
||||
"python_implementation": "CPython",
|
||||
"python_version": "3.5.3",
|
||||
"system": "Linux",
|
||||
},
|
||||
}
|
||||
option_manager = mock.Mock(
|
||||
registered_plugins={
|
||||
manager.PluginVersion('pycodestyle', '2.0.0', False),
|
||||
manager.PluginVersion('mccabe', '0.5.9', False),
|
||||
manager.PluginVersion("pycodestyle", "2.0.0", False),
|
||||
manager.PluginVersion("mccabe", "0.5.9", False),
|
||||
},
|
||||
version='3.1.0',
|
||||
version="3.1.0",
|
||||
)
|
||||
assert expected == debug.information(option_manager)
|
||||
pyimpl.assert_called_once_with()
|
||||
|
|
@ -64,14 +95,16 @@ def test_information(system, pyversion, pyimpl):
|
|||
system.assert_called_once_with()
|
||||
|
||||
|
||||
@mock.patch('flake8.main.debug.print')
|
||||
@mock.patch('flake8.main.debug.information', return_value={})
|
||||
@mock.patch('json.dumps', return_value='{}')
|
||||
@mock.patch("flake8.main.debug.print")
|
||||
@mock.patch("flake8.main.debug.information", return_value={})
|
||||
@mock.patch("json.dumps", return_value="{}")
|
||||
def test_print_information_no_plugins(dumps, information, print_mock):
|
||||
"""Verify we print and exit only when we have plugins."""
|
||||
option_manager = mock.Mock(registered_plugins=set())
|
||||
action = debug.DebugAction(
|
||||
"--bug-report", dest="bug_report", option_manager=option_manager,
|
||||
"--bug-report",
|
||||
dest="bug_report",
|
||||
option_manager=option_manager,
|
||||
)
|
||||
assert action(None, None, None, None) is None
|
||||
assert dumps.called is False
|
||||
|
|
@ -79,21 +112,23 @@ def test_print_information_no_plugins(dumps, information, print_mock):
|
|||
assert print_mock.called is False
|
||||
|
||||
|
||||
@mock.patch('flake8.main.debug.print')
|
||||
@mock.patch('flake8.main.debug.information', return_value={})
|
||||
@mock.patch('json.dumps', return_value='{}')
|
||||
@mock.patch("flake8.main.debug.print")
|
||||
@mock.patch("flake8.main.debug.information", return_value={})
|
||||
@mock.patch("json.dumps", return_value="{}")
|
||||
def test_print_information(dumps, information, print_mock):
|
||||
"""Verify we print and exit only when we have plugins."""
|
||||
plugins = [
|
||||
manager.PluginVersion('pycodestyle', '2.0.0', False),
|
||||
manager.PluginVersion('mccabe', '0.5.9', False),
|
||||
manager.PluginVersion("pycodestyle", "2.0.0", False),
|
||||
manager.PluginVersion("mccabe", "0.5.9", False),
|
||||
]
|
||||
option_manager = mock.Mock(registered_plugins=set(plugins))
|
||||
action = debug.DebugAction(
|
||||
"--bug-report", dest="bug_report", option_manager=option_manager,
|
||||
"--bug-report",
|
||||
dest="bug_report",
|
||||
option_manager=option_manager,
|
||||
)
|
||||
with pytest.raises(SystemExit):
|
||||
action(None, None, None, None)
|
||||
print_mock.assert_called_once_with('{}')
|
||||
print_mock.assert_called_once_with("{}")
|
||||
dumps.assert_called_once_with({}, indent=2, sort_keys=True)
|
||||
information.assert_called_once_with(option_manager)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue