mirror of
https://github.com/PyCQA/flake8.git
synced 2026-04-07 05:26:53 +00:00
Normalize 'per-file-ignores' file paths
Leverage the `type` keyword argument to `ArgumentParser.add_option()` for converting the raw string, either from a configuration file or the command-line, into a data structure for later use. Now with `OptionManager.parse_args()` feeding configuration file values as default values to be considered by the `ArgumentParser.parse_args()` framework, normalization of the file paths occur in single place.
This commit is contained in:
parent
8cd1e0ecc7
commit
31aad5975a
5 changed files with 33 additions and 23 deletions
|
|
@ -94,14 +94,14 @@ per-file-ignores =
|
|||
|
||||
with tmpdir.as_cwd():
|
||||
tmpdir.join('setup.cfg').write(setup_cfg)
|
||||
_call_main(['.'], retv=1)
|
||||
_call_main(['.'], retv=2)
|
||||
|
||||
out, err = capsys.readouterr()
|
||||
assert out == '''\
|
||||
There was a critical error during execution of Flake8:
|
||||
Expected `per-file-ignores` to be a mapping from file exclude patterns to ignore codes.
|
||||
assert err == '''\
|
||||
usage: flake8 [options] file file ...
|
||||
flake8: error: argument --per-file-ignores: Expected a mapping from file exclude patterns to ignore codes.
|
||||
|
||||
Configured `per-file-ignores` setting:
|
||||
Found:
|
||||
|
||||
incorrect/*
|
||||
values/*
|
||||
|
|
|
|||
|
|
@ -45,11 +45,11 @@ def test_style_guide_manager():
|
|||
assert len(guide.style_guides) == 1
|
||||
|
||||
|
||||
PER_FILE_IGNORES_UNPARSED = [
|
||||
"first_file.py:W9",
|
||||
"second_file.py:F4,F9",
|
||||
"third_file.py:E3",
|
||||
"sub_dir/*:F4",
|
||||
PER_FILE_IGNORES_PARSED = [
|
||||
("first_file.py", ["W9"]),
|
||||
("second_file.py", ["F4", "F9"]),
|
||||
("third_file.py", ["E3"]),
|
||||
("sub_dir/*", ["F4"]),
|
||||
]
|
||||
|
||||
|
||||
|
|
@ -75,7 +75,7 @@ def test_style_guide_applies_to(style_guide_file, filename, expected):
|
|||
def test_style_guide_manager_pre_file_ignores_parsing():
|
||||
"""Verify how the StyleGuideManager creates a default style guide."""
|
||||
formatter = mock.create_autospec(base.BaseFormatter, instance=True)
|
||||
options = create_options(per_file_ignores=PER_FILE_IGNORES_UNPARSED)
|
||||
options = create_options(per_file_ignores=PER_FILE_IGNORES_PARSED)
|
||||
guide = style_guide.StyleGuideManager(options, formatter=formatter)
|
||||
assert len(guide.style_guides) == 5
|
||||
assert list(map(utils.normalize_path,
|
||||
|
|
@ -98,7 +98,7 @@ def test_style_guide_manager_pre_file_ignores(ignores, violation, filename,
|
|||
formatter = mock.create_autospec(base.BaseFormatter, instance=True)
|
||||
options = create_options(ignore=ignores,
|
||||
select=['E', 'F', 'W'],
|
||||
per_file_ignores=PER_FILE_IGNORES_UNPARSED)
|
||||
per_file_ignores=PER_FILE_IGNORES_PARSED)
|
||||
guide = style_guide.StyleGuideManager(options, formatter=formatter)
|
||||
assert (guide.handle_error(violation, filename, 1, 1, "Fake text")
|
||||
== handle_error_return)
|
||||
|
|
@ -115,7 +115,7 @@ def test_style_guide_manager_pre_file_ignores(ignores, violation, filename,
|
|||
def test_style_guide_manager_style_guide_for(filename, expected):
|
||||
"""Verify the style guide selection function."""
|
||||
formatter = mock.create_autospec(base.BaseFormatter, instance=True)
|
||||
options = create_options(per_file_ignores=PER_FILE_IGNORES_UNPARSED)
|
||||
options = create_options(per_file_ignores=PER_FILE_IGNORES_PARSED)
|
||||
guide = style_guide.StyleGuideManager(options, formatter=formatter)
|
||||
|
||||
file_guide = guide.style_guide_for(filename)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue