mirror of
https://github.com/PyCQA/flake8.git
synced 2026-06-29 08:40:45 +00:00
Preserve legacy API options in parallel checks
This commit is contained in:
parent
bb943328ef
commit
0df41b2d56
5 changed files with 85 additions and 10 deletions
|
|
@ -2,6 +2,7 @@
|
|||
from __future__ import annotations
|
||||
|
||||
from flake8.api import legacy
|
||||
from flake8.main.options import JobsArgument
|
||||
|
||||
|
||||
def test_legacy_api(tmpdir):
|
||||
|
|
@ -13,3 +14,17 @@ def test_legacy_api(tmpdir):
|
|||
style_guide = legacy.get_style_guide()
|
||||
report = style_guide.check_files([t_py.strpath])
|
||||
assert report.total_errors == 1
|
||||
|
||||
|
||||
def test_legacy_api_uses_initialized_options_for_parallel_checks(tmpdir):
|
||||
with tmpdir.as_cwd():
|
||||
a_py = tmpdir.join("a.py")
|
||||
b_py = tmpdir.join("b.py")
|
||||
a_py.write('x = "' + "a" * 80 + '"\n')
|
||||
b_py.write('y = "' + "b" * 80 + '"\n')
|
||||
|
||||
style_guide = legacy.get_style_guide(color="never", max_line_length=88)
|
||||
style_guide.options.jobs = JobsArgument("2")
|
||||
report = style_guide.check_files([a_py.strpath, b_py.strpath])
|
||||
|
||||
assert report.total_errors == 0
|
||||
|
|
|
|||
|
|
@ -2,6 +2,7 @@
|
|||
from __future__ import annotations
|
||||
|
||||
import importlib.metadata
|
||||
import pickle
|
||||
from unittest import mock
|
||||
|
||||
import pytest
|
||||
|
|
@ -291,7 +292,24 @@ def test_acquire_when_multiprocessing_pool_can_initialize():
|
|||
with mock.patch("multiprocessing.Pool") as pool:
|
||||
result = checker._try_initialize_processpool(2, [])
|
||||
|
||||
pool.assert_called_once_with(2, checker._mp_init, initargs=([],))
|
||||
pool.assert_called_once_with(
|
||||
2, checker._mp_init, initargs=([], None, None),
|
||||
)
|
||||
assert result is pool.return_value
|
||||
|
||||
|
||||
def test_acquire_when_multiprocessing_pool_uses_initialized_options():
|
||||
plugins = mock.Mock()
|
||||
options = mock.Mock()
|
||||
|
||||
with mock.patch("multiprocessing.Pool") as pool:
|
||||
result = checker._try_initialize_processpool(
|
||||
2, [], plugins=plugins, options=options,
|
||||
)
|
||||
|
||||
pool.assert_called_once_with(
|
||||
2, checker._mp_init, initargs=([], plugins, options),
|
||||
)
|
||||
assert result is pool.return_value
|
||||
|
||||
|
||||
|
|
@ -310,7 +328,21 @@ def test_acquire_when_multiprocessing_pool_can_not_initialize():
|
|||
with mock.patch("multiprocessing.Pool", side_effect=ImportError) as pool:
|
||||
result = checker._try_initialize_processpool(2, [])
|
||||
|
||||
pool.assert_called_once_with(2, checker._mp_init, initargs=([],))
|
||||
pool.assert_called_once_with(
|
||||
2, checker._mp_init, initargs=([], None, None),
|
||||
)
|
||||
assert result is None
|
||||
|
||||
|
||||
def test_acquire_falls_back_when_initialized_options_are_unpickleable():
|
||||
with mock.patch(
|
||||
"multiprocessing.Pool", side_effect=pickle.PicklingError,
|
||||
) as pool:
|
||||
result = checker._try_initialize_processpool(
|
||||
2, [], plugins=mock.Mock(), options=mock.Mock(),
|
||||
)
|
||||
|
||||
pool.assert_called_once()
|
||||
assert result is None
|
||||
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue