mirror of
https://github.com/PyCQA/flake8.git
synced 2026-04-10 06:44:18 +00:00
Fix bug for plugins using extend_default_ignore
Since Flake8 3.0 we've had the ability for plugins to use `extend_default_ignore` to register codes they want disabled by default. This, however, was a permanent disabling unfortunately. Our code didn't have a way of understanding that this new set of `ignore` codes was actually the 'default' set for that run. Much like the extended_select_list, we now attach extended_ignore_list to be able to confidently determine if the ignore we get in the DecisionEngine is actually the Default Ignore list and what plugins what us to ignore by default. Refs https://github.com/PyCQA/pep8-naming/pull/157
This commit is contained in:
parent
992bb77d22
commit
2bb0308363
4 changed files with 405 additions and 177 deletions
|
|
@ -12,14 +12,15 @@ from flake8.formatting import base
|
|||
|
||||
def create_options(**kwargs):
|
||||
"""Create and return an instance of argparse.Namespace."""
|
||||
kwargs.setdefault('select', [])
|
||||
kwargs.setdefault('extended_default_select', [])
|
||||
kwargs.setdefault('extend_select', [])
|
||||
kwargs.setdefault('ignore', [])
|
||||
kwargs.setdefault('extend_ignore', [])
|
||||
kwargs.setdefault('disable_noqa', False)
|
||||
kwargs.setdefault('enable_extensions', [])
|
||||
kwargs.setdefault('per_file_ignores', [])
|
||||
kwargs.setdefault("select", [])
|
||||
kwargs.setdefault("extended_default_select", [])
|
||||
kwargs.setdefault("extended_default_ignore", [])
|
||||
kwargs.setdefault("extend_select", [])
|
||||
kwargs.setdefault("ignore", [])
|
||||
kwargs.setdefault("extend_ignore", [])
|
||||
kwargs.setdefault("disable_noqa", False)
|
||||
kwargs.setdefault("enable_extensions", [])
|
||||
kwargs.setdefault("per_file_ignores", [])
|
||||
return argparse.Namespace(**kwargs)
|
||||
|
||||
|
||||
|
|
@ -27,13 +28,13 @@ def test_handle_error_does_not_raise_type_errors():
|
|||
"""Verify that we handle our inputs better."""
|
||||
formatter = mock.create_autospec(base.BaseFormatter, instance=True)
|
||||
guide = style_guide.StyleGuide(
|
||||
create_options(select=['T111'], ignore=[]),
|
||||
create_options(select=["T111"], ignore=[]),
|
||||
formatter=formatter,
|
||||
stats=statistics.Statistics(),
|
||||
)
|
||||
|
||||
assert 1 == guide.handle_error(
|
||||
'T111', 'file.py', 1, None, 'error found', 'a = 1'
|
||||
"T111", "file.py", 1, None, "error found", "a = 1"
|
||||
)
|
||||
|
||||
|
||||
|
|
@ -54,13 +55,16 @@ PER_FILE_IGNORES_UNPARSED = [
|
|||
]
|
||||
|
||||
|
||||
@pytest.mark.parametrize('style_guide_file,filename,expected', [
|
||||
("first_file.py", "first_file.py", True),
|
||||
("first_file.py", "second_file.py", False),
|
||||
("sub_dir/*.py", "first_file.py", False),
|
||||
("sub_dir/*.py", "sub_dir/file.py", True),
|
||||
("sub_dir/*.py", "other_dir/file.py", False),
|
||||
])
|
||||
@pytest.mark.parametrize(
|
||||
"style_guide_file,filename,expected",
|
||||
[
|
||||
("first_file.py", "first_file.py", True),
|
||||
("first_file.py", "second_file.py", False),
|
||||
("sub_dir/*.py", "first_file.py", False),
|
||||
("sub_dir/*.py", "sub_dir/file.py", True),
|
||||
("sub_dir/*.py", "other_dir/file.py", False),
|
||||
],
|
||||
)
|
||||
def test_style_guide_applies_to(style_guide_file, filename, expected):
|
||||
"""Verify that we match a file to its style guide."""
|
||||
formatter = mock.create_autospec(base.BaseFormatter, instance=True)
|
||||
|
|
@ -69,7 +73,8 @@ def test_style_guide_applies_to(style_guide_file, filename, expected):
|
|||
options,
|
||||
formatter=formatter,
|
||||
stats=statistics.Statistics(),
|
||||
filename=style_guide_file)
|
||||
filename=style_guide_file,
|
||||
)
|
||||
assert guide.applies_to(filename) is expected
|
||||
|
||||
|
||||
|
|
@ -80,41 +85,56 @@ def test_style_guide_manager_pre_file_ignores_parsing():
|
|||
guide = style_guide.StyleGuideManager(options, formatter=formatter)
|
||||
assert len(guide.style_guides) == 5
|
||||
expected = [
|
||||
utils.normalize_path(p) for p in [
|
||||
"first_file.py", "second_file.py", "third_file.py", "sub_dir/*",
|
||||
utils.normalize_path(p)
|
||||
for p in [
|
||||
"first_file.py",
|
||||
"second_file.py",
|
||||
"third_file.py",
|
||||
"sub_dir/*",
|
||||
]
|
||||
]
|
||||
assert expected == [g.filename for g in guide.style_guides[1:]]
|
||||
|
||||
|
||||
@pytest.mark.parametrize('ignores,violation,filename,handle_error_return', [
|
||||
(['E1', 'E2'], 'F401', 'first_file.py', 1),
|
||||
(['E1', 'E2'], 'E121', 'first_file.py', 0),
|
||||
(['E1', 'E2'], 'F401', 'second_file.py', 0),
|
||||
(['E1', 'E2'], 'F401', 'third_file.py', 1),
|
||||
(['E1', 'E2'], 'E311', 'third_file.py', 0),
|
||||
(['E1', 'E2'], 'F401', 'sub_dir/file.py', 0),
|
||||
])
|
||||
def test_style_guide_manager_pre_file_ignores(ignores, violation, filename,
|
||||
handle_error_return):
|
||||
@pytest.mark.parametrize(
|
||||
"ignores,violation,filename,handle_error_return",
|
||||
[
|
||||
(["E1", "E2"], "F401", "first_file.py", 1),
|
||||
(["E1", "E2"], "E121", "first_file.py", 0),
|
||||
(["E1", "E2"], "F401", "second_file.py", 0),
|
||||
(["E1", "E2"], "F401", "third_file.py", 1),
|
||||
(["E1", "E2"], "E311", "third_file.py", 0),
|
||||
(["E1", "E2"], "F401", "sub_dir/file.py", 0),
|
||||
],
|
||||
)
|
||||
def test_style_guide_manager_pre_file_ignores(
|
||||
ignores, violation, filename, handle_error_return
|
||||
):
|
||||
"""Verify how the StyleGuideManager creates a default style guide."""
|
||||
formatter = mock.create_autospec(base.BaseFormatter, instance=True)
|
||||
options = create_options(ignore=ignores,
|
||||
select=['E', 'F', 'W'],
|
||||
per_file_ignores=PER_FILE_IGNORES_UNPARSED)
|
||||
options = create_options(
|
||||
ignore=ignores,
|
||||
select=["E", "F", "W"],
|
||||
per_file_ignores=PER_FILE_IGNORES_UNPARSED,
|
||||
)
|
||||
guide = style_guide.StyleGuideManager(options, formatter=formatter)
|
||||
assert (guide.handle_error(violation, filename, 1, 1, "Fake text")
|
||||
== handle_error_return)
|
||||
assert (
|
||||
guide.handle_error(violation, filename, 1, 1, "Fake text")
|
||||
== handle_error_return
|
||||
)
|
||||
|
||||
|
||||
@pytest.mark.parametrize('filename,expected', [
|
||||
('first_file.py', utils.normalize_path('first_file.py')),
|
||||
('second_file.py', utils.normalize_path('second_file.py')),
|
||||
('third_file.py', utils.normalize_path('third_file.py')),
|
||||
('fourth_file.py', None),
|
||||
('sub_dir/__init__.py', utils.normalize_path('sub_dir/*')),
|
||||
('other_dir/__init__.py', None),
|
||||
])
|
||||
@pytest.mark.parametrize(
|
||||
"filename,expected",
|
||||
[
|
||||
("first_file.py", utils.normalize_path("first_file.py")),
|
||||
("second_file.py", utils.normalize_path("second_file.py")),
|
||||
("third_file.py", utils.normalize_path("third_file.py")),
|
||||
("fourth_file.py", None),
|
||||
("sub_dir/__init__.py", utils.normalize_path("sub_dir/*")),
|
||||
("other_dir/__init__.py", None),
|
||||
],
|
||||
)
|
||||
def test_style_guide_manager_style_guide_for(filename, expected):
|
||||
"""Verify the style guide selection function."""
|
||||
formatter = mock.create_autospec(base.BaseFormatter, instance=True)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue