mirror of
https://github.com/PyCQA/flake8.git
synced 2026-04-04 12:16:53 +00:00
Fix codes
This commit is contained in:
parent
d23f77d06e
commit
705c16a268
2 changed files with 34 additions and 25 deletions
|
|
@ -36,7 +36,6 @@ class FileProcessor(object):
|
|||
- :attr:`blank_before`
|
||||
- :attr:`blank_lines`
|
||||
- :attr:`checker_state`
|
||||
- :attr:`disable_noqa`
|
||||
- :attr:`indent_char`
|
||||
- :attr:`indent_level`
|
||||
- :attr:`line_number`
|
||||
|
|
@ -78,8 +77,6 @@ class FileProcessor(object):
|
|||
self._checker_states = {} # type: Dict[str, Dict[Any, Any]]
|
||||
#: Current checker state
|
||||
self.checker_state = {} # type: Dict[Any, Any]
|
||||
#: Disable all noqa comments
|
||||
self.disable_noqa = options.disable_noqa # type: bool
|
||||
#: User provided option for hang closing
|
||||
self.hang_closing = options.hang_closing
|
||||
#: Character used for indentation
|
||||
|
|
@ -349,8 +346,10 @@ class FileProcessor(object):
|
|||
:rtype:
|
||||
bool
|
||||
"""
|
||||
if not self.disable_noqa \
|
||||
and any(defaults.NOQA_FILE.match(line) for line in self.lines):
|
||||
if (
|
||||
not self.options.disable_noqa
|
||||
and any(defaults.NOQA_FILE.match(line) for line in self.lines)
|
||||
):
|
||||
return True
|
||||
elif any(defaults.NOQA_FILE.search(line) for line in self.lines):
|
||||
LOG.warning(
|
||||
|
|
|
|||
|
|
@ -57,32 +57,42 @@ def test_strip_utf_bom(first_line, default_options):
|
|||
assert file_processor.lines[0] == '"""Module docstring."""\n'
|
||||
|
||||
|
||||
@pytest.mark.parametrize('lines, expected, disable_noqa', [
|
||||
(['\xEF\xBB\xBF"""Module docstring."""\n'], False, False),
|
||||
([u'\uFEFF"""Module docstring."""\n'], False, False),
|
||||
(['#!/usr/bin/python', '# flake8 is great', 'a = 1'], False, False),
|
||||
(['#!/usr/bin/python', '# flake8: noqa', 'a = 1'], True, False),
|
||||
(['#!/usr/bin/python', '# flake8: noqa', 'a = 1'], False, True),
|
||||
(['#!/usr/bin/python', '# flake8:noqa', 'a = 1'], True, False),
|
||||
(['#!/usr/bin/python', '# flake8:noqa', 'a = 1'], False, True),
|
||||
(['# flake8: noqa', '#!/usr/bin/python', 'a = 1'], True, False),
|
||||
(['# flake8: noqa', '#!/usr/bin/python', 'a = 1'], False, True),
|
||||
(['# flake8:noqa', '#!/usr/bin/python', 'a = 1'], True, False),
|
||||
(['# flake8:noqa', '#!/usr/bin/python', 'a = 1'], False, True),
|
||||
(['#!/usr/bin/python', 'a = 1', '# flake8: noqa'], True, False),
|
||||
(['#!/usr/bin/python', 'a = 1', '# flake8: noqa'], False, True),
|
||||
(['#!/usr/bin/python', 'a = 1', '# flake8:noqa'], True, False),
|
||||
(['#!/usr/bin/python', 'a = 1', '# flake8:noqa'], False, True),
|
||||
(['#!/usr/bin/python', 'a = 1 # flake8: noqa'], False, False),
|
||||
(['#!/usr/bin/python', 'a = 1 # flake8:noqa'], False, False),
|
||||
@pytest.mark.parametrize('lines, expected', [
|
||||
(['\xEF\xBB\xBF"""Module docstring."""\n'], False),
|
||||
([u'\uFEFF"""Module docstring."""\n'], False),
|
||||
(['#!/usr/bin/python', '# flake8 is great', 'a = 1'], False),
|
||||
(['#!/usr/bin/python', '# flake8: noqa', 'a = 1'], True),
|
||||
(['#!/usr/bin/python', '# flake8:noqa', 'a = 1'], True),
|
||||
(['# flake8: noqa', '#!/usr/bin/python', 'a = 1'], True),
|
||||
(['# flake8:noqa', '#!/usr/bin/python', 'a = 1'], True),
|
||||
(['#!/usr/bin/python', 'a = 1', '# flake8: noqa'], True),
|
||||
(['#!/usr/bin/python', 'a = 1', '# flake8:noqa'], True),
|
||||
(['#!/usr/bin/python', 'a = 1 # flake8: noqa'], False),
|
||||
(['#!/usr/bin/python', 'a = 1 # flake8:noqa'], False),
|
||||
])
|
||||
def test_should_ignore_file(lines, expected, disable_noqa, default_options):
|
||||
def test_should_ignore_file(lines, expected, default_options):
|
||||
"""Verify that we ignore a file if told to."""
|
||||
default_options.disable_noqa = disable_noqa
|
||||
file_processor = processor.FileProcessor('-', default_options, lines)
|
||||
assert file_processor.should_ignore_file() is expected
|
||||
|
||||
|
||||
@pytest.mark.parametrize('lines', [
|
||||
['#!/usr/bin/python', '# flake8: noqa', 'a = 1'],
|
||||
['#!/usr/bin/python', '# flake8:noqa', 'a = 1'],
|
||||
['# flake8: noqa', '#!/usr/bin/python', 'a = 1'],
|
||||
['# flake8:noqa', '#!/usr/bin/python', 'a = 1'],
|
||||
['#!/usr/bin/python', 'a = 1', '# flake8: noqa'],
|
||||
['#!/usr/bin/python', 'a = 1', '# flake8:noqa'],
|
||||
])
|
||||
def test_should_ignore_file_to_handle_disable_noqa(lines, default_options):
|
||||
"""Verify that we ignore a file if told to."""
|
||||
file_processor = processor.FileProcessor('-', default_options, lines)
|
||||
assert file_processor.should_ignore_file() is True
|
||||
default_options.disable_noqa = True
|
||||
file_processor = processor.FileProcessor('-', default_options, lines)
|
||||
assert file_processor.should_ignore_file() is False
|
||||
|
||||
|
||||
@mock.patch('flake8.utils.stdin_get_value')
|
||||
def test_read_lines_from_stdin(stdin_get_value, default_options):
|
||||
"""Verify that we use our own utility function to retrieve stdin."""
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue