mirror of
https://github.com/PyCQA/flake8.git
synced 2026-04-12 15:44:17 +00:00
Add specific tests for is_inline_ignored
Update the logic so someone can use a class in their ``# noqa`` ignore list
This commit is contained in:
parent
f4b18229a0
commit
fbd5944f15
2 changed files with 21 additions and 1 deletions
|
|
@ -173,7 +173,7 @@ class StyleGuide(object):
|
||||||
return True
|
return True
|
||||||
|
|
||||||
codes = set(utils.parse_comma_separated_list(codes_str))
|
codes = set(utils.parse_comma_separated_list(codes_str))
|
||||||
if error.code in codes:
|
if error.code in codes or error.code.startswith(tuple(codes)):
|
||||||
LOG.debug('%r is ignored specifically inline with ``# noqa: %s``',
|
LOG.debug('%r is ignored specifically inline with ``# noqa: %s``',
|
||||||
error, codes_str)
|
error, codes_str)
|
||||||
return True
|
return True
|
||||||
|
|
|
||||||
|
|
@ -125,6 +125,26 @@ def test_should_report_error(select_list, ignore_list, error_code, expected):
|
||||||
assert guide.should_report_error(error_code) is expected
|
assert guide.should_report_error(error_code) is expected
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.mark.parametrize('error_code,physical_line,expected_result', [
|
||||||
|
('E111', 'a = 1', False),
|
||||||
|
('E121', 'a = 1 # noqa: E111', False),
|
||||||
|
('E121', 'a = 1 # noqa: E111,W123,F821', False),
|
||||||
|
('E111', 'a = 1 # noqa: E111,W123,F821', True),
|
||||||
|
('W123', 'a = 1 # noqa: E111,W123,F821', True),
|
||||||
|
('E111', 'a = 1 # noqa: E11,W123,F821', True),
|
||||||
|
])
|
||||||
|
def test_is_inline_ignored(error_code, physical_line, expected_result):
|
||||||
|
"""Verify that we detect inline usage of ``# noqa``."""
|
||||||
|
guide = style_guide.StyleGuide(create_options(select=['E', 'W', 'F']),
|
||||||
|
arguments=[],
|
||||||
|
listener_trie=None,
|
||||||
|
formatter=None)
|
||||||
|
error = style_guide.Error(error_code, 'filename.py', 1, 1, 'error text')
|
||||||
|
|
||||||
|
with mock.patch('linecache.getline', return_value=physical_line):
|
||||||
|
assert guide.is_inline_ignored(error) is expected_result
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.parametrize('select_list,ignore_list,error_code', [
|
@pytest.mark.parametrize('select_list,ignore_list,error_code', [
|
||||||
(['E111', 'E121'], [], 'E111'),
|
(['E111', 'E121'], [], 'E111'),
|
||||||
(['E111', 'E121'], [], 'E121'),
|
(['E111', 'E121'], [], 'E121'),
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue