How to use the flake8.processor.FileProcessor function in flake8

To help you get started, we’ve selected a few flake8 examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github PyCQA / flake8 / tests / unit / test_file_processor.py View on Github external
def test_visited_new_blank_line(default_options):
    """Verify we update the number of blank lines seen."""
    file_processor = processor.FileProcessor('-', default_options, lines=[
        'a = 1\n'
    ])

    assert file_processor.blank_lines == 0
    file_processor.visited_new_blank_line()
    assert file_processor.blank_lines == 1
github PyCQA / flake8 / tests / unit / test_file_processor.py View on Github external
def test_keyword_arguments_for_does_not_handle_attribute_errors(
        default_options,
):
    """Verify we re-raise AttributeErrors."""
    file_processor = processor.FileProcessor('-', default_options, lines=[
        'Line 1',
    ])

    with pytest.raises(AttributeError):
        file_processor.keyword_arguments_for({'fake': True})
github PyCQA / flake8 / tests / unit / test_file_processor.py View on Github external
def test_read_lines_from_stdin(stdin_get_value, default_options):
    """Verify that we use our own utility function to retrieve stdin."""
    stdin_value = mock.Mock()
    stdin_value.splitlines.return_value = []
    stdin_get_value.return_value = stdin_value
    processor.FileProcessor('-', default_options)
    stdin_get_value.assert_called_once_with()
    stdin_value.splitlines.assert_called_once_with(True)
github PyCQA / flake8 / tests / unit / test_file_processor.py View on Github external
def _lines_from_file(tmpdir, contents, options):
    f = tmpdir.join('f.py')
    # be careful to write the bytes exactly to avoid newline munging
    f.write_binary(contents)
    return processor.FileProcessor(f.strpath, options).lines
github PyCQA / flake8 / tests / unit / test_file_processor.py View on Github external
def test_split_line(unsplit_line, expected_lines, default_options):
    """Verify the token line spliting."""
    file_processor = processor.FileProcessor('-', default_options, lines=[
        'Line 1',
    ])

    token = (1, unsplit_line, (0, 0), (0, 0), '')
    actual_lines = list(file_processor.split_line(token))
    assert expected_lines == actual_lines

    assert len(actual_lines) == file_processor.line_number
github PyCQA / flake8 / tests / unit / test_file_processor.py View on Github external
def test_stdin_filename_attribute(stdin_get_value, default_options):
    """Verify that we update the filename attribute."""
    stdin_value = mock.Mock()
    stdin_value.splitlines.return_value = []
    stdin_get_value.return_value = stdin_value
    file_processor = processor.FileProcessor('-', default_options)
    assert file_processor.filename == 'stdin'
github PyCQA / flake8 / tests / unit / test_file_processor.py View on Github external
def test_read_lines_uses_display_name(stdin_get_value, default_options):
    """Verify that when processing stdin we use a display name if present."""
    default_options.stdin_display_name = 'display_name.py'
    stdin_value = mock.Mock()
    stdin_value.splitlines.return_value = []
    stdin_get_value.return_value = stdin_value
    file_processor = processor.FileProcessor('-', default_options)
    assert file_processor.filename == 'display_name.py'
github PyCQA / flake8 / src / flake8 / checker.py View on Github external
def _make_processor(self):
        # type: () -> Optional[processor.FileProcessor]
        try:
            return processor.FileProcessor(self.filename, self.options)
        except IOError as e:
            # If we can not read the file due to an IOError (e.g., the file
            # does not exist or we do not have the permissions to open it)
            # then we need to format that exception for the user.
            # NOTE(sigmavirus24): Historically, pep8 has always reported this
            # as an E902. We probably *want* a better error code for this
            # going forward.
            message = "{0}: {1}".format(type(e).__name__, e)
            self.report("E902", 0, 0, message)
            return None
github kataev / flake8-rst / flake8_rst / checker.py View on Github external
def _make_processor(self):
        content = self.source_block.complete_block if self.source_block else ''
        return FileProcessor(self.filename, self.options, lines=content.splitlines(True))