extend black formatting to tests as well

This commit is contained in:
Anthony Sottile 2021-04-18 09:17:48 -07:00
parent a7174759e9
commit af1668bf04
45 changed files with 1644 additions and 1307 deletions

View file

@ -10,10 +10,12 @@ from flake8.main.options import JobsArgument
def style_guide_mock():
"""Create a mock StyleGuide object."""
return mock.MagicMock(**{
'options.diff': False,
'options.jobs': JobsArgument("4"),
})
return mock.MagicMock(
**{
"options.diff": False,
"options.jobs": JobsArgument("4"),
}
)
def _parallel_checker_manager():
@ -27,21 +29,21 @@ def _parallel_checker_manager():
def test_oserrors_cause_serial_fall_back():
"""Verify that OSErrors will cause the Manager to fallback to serial."""
err = OSError(errno.ENOSPC, 'Ominous message about spaceeeeee')
with mock.patch('_multiprocessing.SemLock', side_effect=err):
err = OSError(errno.ENOSPC, "Ominous message about spaceeeeee")
with mock.patch("_multiprocessing.SemLock", side_effect=err):
manager = _parallel_checker_manager()
with mock.patch.object(manager, 'run_serial') as serial:
with mock.patch.object(manager, "run_serial") as serial:
manager.run()
assert serial.call_count == 1
@mock.patch('flake8.checker._multiprocessing_is_fork', return_value=True)
@mock.patch("flake8.checker._multiprocessing_is_fork", return_value=True)
def test_oserrors_are_reraised(is_windows):
"""Verify that unexpected OSErrors will cause the Manager to reraise."""
err = OSError(errno.EAGAIN, 'Ominous message')
with mock.patch('_multiprocessing.SemLock', side_effect=err):
err = OSError(errno.EAGAIN, "Ominous message")
with mock.patch("_multiprocessing.SemLock", side_effect=err):
manager = _parallel_checker_manager()
with mock.patch.object(manager, 'run_serial') as serial:
with mock.patch.object(manager, "run_serial") as serial:
with pytest.raises(OSError):
manager.run()
assert serial.call_count == 0
@ -50,7 +52,7 @@ def test_oserrors_are_reraised(is_windows):
def test_multiprocessing_is_disabled():
"""Verify not being able to import multiprocessing forces jobs to 0."""
style_guide = style_guide_mock()
with mock.patch('flake8.checker.multiprocessing', None):
with mock.patch("flake8.checker.multiprocessing", None):
manager = checker.Manager(style_guide, [], [])
assert manager.jobs == 0
@ -58,20 +60,20 @@ def test_multiprocessing_is_disabled():
def test_make_checkers():
"""Verify that we create a list of FileChecker instances."""
style_guide = style_guide_mock()
files = ['file1', 'file2']
files = ["file1", "file2"]
checkplugins = mock.Mock()
checkplugins.to_dictionary.return_value = {
'ast_plugins': [],
'logical_line_plugins': [],
'physical_line_plugins': [],
"ast_plugins": [],
"logical_line_plugins": [],
"physical_line_plugins": [],
}
with mock.patch('flake8.checker.multiprocessing', None):
with mock.patch("flake8.checker.multiprocessing", None):
manager = checker.Manager(style_guide, files, checkplugins)
with mock.patch('flake8.utils.filenames_from') as filenames_from:
filenames_from.side_effect = [['file1'], ['file2']]
with mock.patch('flake8.utils.fnmatch', return_value=True):
with mock.patch('flake8.processor.FileProcessor'):
with mock.patch("flake8.utils.filenames_from") as filenames_from:
filenames_from.side_effect = [["file1"], ["file2"]]
with mock.patch("flake8.utils.fnmatch", return_value=True):
with mock.patch("flake8.processor.FileProcessor"):
manager.make_checkers()
assert manager._all_checkers