mirror of
https://github.com/PyCQA/flake8.git
synced 2026-03-30 02:46:52 +00:00
Remove arguments from StyleGuide
- StyleGuides do not need the arguments passed in - Add a test for is_inline_ignored obeying disable_noqa
This commit is contained in:
parent
6d3d955ba9
commit
58b2ca69e4
3 changed files with 20 additions and 12 deletions
|
|
@ -180,5 +180,5 @@ def main(argv=None):
|
|||
options.format, formatting_plugins['default']
|
||||
).execute(options)
|
||||
listener_trie = listening_plugins.build_notifier()
|
||||
guide = style_guide.StyleGuide(options, args, listener_trie, formatter)
|
||||
guide = style_guide.StyleGuide(options, listener_trie, formatter)
|
||||
guide.handle_error('E111', 'stdin', 1, 1, 'faketext')
|
||||
|
|
|
|||
|
|
@ -61,13 +61,12 @@ class StyleGuide(object):
|
|||
re.IGNORECASE
|
||||
)
|
||||
|
||||
def __init__(self, options, arguments, listener_trie, formatter):
|
||||
def __init__(self, options, listener_trie, formatter):
|
||||
"""Initialize our StyleGuide.
|
||||
|
||||
.. todo:: Add parameter documentation.
|
||||
"""
|
||||
self.options = options
|
||||
self.arguments = arguments
|
||||
self.listener = listener_trie
|
||||
self.formatter = formatter
|
||||
self._selected = tuple(options.select)
|
||||
|
|
@ -161,6 +160,10 @@ class StyleGuide(object):
|
|||
|
||||
def is_inline_ignored(self, error):
|
||||
"""Determine if an comment has been added to ignore this line."""
|
||||
# TODO(sigmavirus24): Determine how to handle stdin with linecache
|
||||
if self.options.disable_noqa:
|
||||
return False
|
||||
|
||||
physical_line = linecache.getline(error.filename, error.line_number)
|
||||
noqa_match = self.NOQA_INLINE_REGEXP.search(physical_line)
|
||||
if noqa_match is None:
|
||||
|
|
|
|||
|
|
@ -13,6 +13,7 @@ def create_options(**kwargs):
|
|||
"""Create and return an instance of optparse.Values."""
|
||||
kwargs.setdefault('select', [])
|
||||
kwargs.setdefault('ignore', [])
|
||||
kwargs.setdefault('disable_noqa', False)
|
||||
return optparse.Values(kwargs)
|
||||
|
||||
|
||||
|
|
@ -26,7 +27,6 @@ def create_options(**kwargs):
|
|||
def test_is_user_ignored_ignores_errors(ignore_list, error_code):
|
||||
"""Verify we detect users explicitly ignoring an error."""
|
||||
guide = style_guide.StyleGuide(create_options(ignore=ignore_list),
|
||||
arguments=[],
|
||||
listener_trie=None,
|
||||
formatter=None)
|
||||
|
||||
|
|
@ -43,7 +43,6 @@ def test_is_user_ignored_ignores_errors(ignore_list, error_code):
|
|||
def test_is_user_ignored_implicitly_selects_errors(ignore_list, error_code):
|
||||
"""Verify we detect users does not explicitly ignore an error."""
|
||||
guide = style_guide.StyleGuide(create_options(ignore=ignore_list),
|
||||
arguments=[],
|
||||
listener_trie=None,
|
||||
formatter=None)
|
||||
|
||||
|
|
@ -60,7 +59,6 @@ def test_is_user_ignored_implicitly_selects_errors(ignore_list, error_code):
|
|||
def test_is_user_selected_selects_errors(select_list, error_code):
|
||||
"""Verify we detect users explicitly selecting an error."""
|
||||
guide = style_guide.StyleGuide(create_options(select=select_list),
|
||||
arguments=[],
|
||||
listener_trie=None,
|
||||
formatter=None)
|
||||
|
||||
|
|
@ -73,7 +71,6 @@ def test_is_user_selected_implicitly_selects_errors():
|
|||
select_list = []
|
||||
error_code = 'E121'
|
||||
guide = style_guide.StyleGuide(create_options(select=select_list),
|
||||
arguments=[],
|
||||
listener_trie=None,
|
||||
formatter=None)
|
||||
|
||||
|
|
@ -91,7 +88,6 @@ def test_is_user_selected_implicitly_selects_errors():
|
|||
def test_is_user_selected_excludes_errors(select_list, error_code):
|
||||
"""Verify we detect users implicitly excludes an error."""
|
||||
guide = style_guide.StyleGuide(create_options(select=select_list),
|
||||
arguments=[],
|
||||
listener_trie=None,
|
||||
formatter=None)
|
||||
|
||||
|
|
@ -118,7 +114,6 @@ def test_should_report_error(select_list, ignore_list, error_code, expected):
|
|||
"""Verify we decide when to report an error."""
|
||||
guide = style_guide.StyleGuide(create_options(select=select_list,
|
||||
ignore=ignore_list),
|
||||
arguments=[],
|
||||
listener_trie=None,
|
||||
formatter=None)
|
||||
|
||||
|
|
@ -136,7 +131,6 @@ def test_should_report_error(select_list, ignore_list, error_code, expected):
|
|||
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')
|
||||
|
|
@ -145,6 +139,19 @@ def test_is_inline_ignored(error_code, physical_line, expected_result):
|
|||
assert guide.is_inline_ignored(error) is expected_result
|
||||
|
||||
|
||||
def test_disable_is_inline_ignored():
|
||||
"""Verify that is_inline_ignored exits immediately if disabling NoQA."""
|
||||
guide = style_guide.StyleGuide(create_options(disable_noqa=True),
|
||||
listener_trie=None,
|
||||
formatter=None)
|
||||
error = style_guide.Error('E121', 'filename.py', 1, 1, 'error text')
|
||||
|
||||
with mock.patch('linecache.getline') as getline:
|
||||
assert guide.is_inline_ignored(error) is False
|
||||
|
||||
assert getline.called is False
|
||||
|
||||
|
||||
@pytest.mark.parametrize('select_list,ignore_list,error_code', [
|
||||
(['E111', 'E121'], [], 'E111'),
|
||||
(['E111', 'E121'], [], 'E121'),
|
||||
|
|
@ -158,7 +165,6 @@ def test_handle_error_notifies_listeners(select_list, ignore_list, error_code):
|
|||
formatter = mock.create_autospec(base.BaseFormatter, instance=True)
|
||||
guide = style_guide.StyleGuide(create_options(select=select_list,
|
||||
ignore=ignore_list),
|
||||
arguments=[],
|
||||
listener_trie=listener_trie,
|
||||
formatter=formatter)
|
||||
|
||||
|
|
@ -187,7 +193,6 @@ def test_handle_error_does_not_notify_listeners(select_list, ignore_list,
|
|||
formatter = mock.create_autospec(base.BaseFormatter, instance=True)
|
||||
guide = style_guide.StyleGuide(create_options(select=select_list,
|
||||
ignore=ignore_list),
|
||||
arguments=[],
|
||||
listener_trie=listener_trie,
|
||||
formatter=formatter)
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue