mirror of
https://github.com/PyCQA/flake8.git
synced 2026-04-09 22:34:17 +00:00
Add more processor tests
This commit is contained in:
parent
425f89eee9
commit
81eb3e41cc
1 changed files with 42 additions and 0 deletions
|
|
@ -1,6 +1,7 @@
|
||||||
"""Tests for the FileProcessor class."""
|
"""Tests for the FileProcessor class."""
|
||||||
import ast
|
import ast
|
||||||
import optparse
|
import optparse
|
||||||
|
import tokenize
|
||||||
|
|
||||||
from flake8 import processor
|
from flake8 import processor
|
||||||
|
|
||||||
|
|
@ -249,3 +250,44 @@ def test_expand_indent(string, expected):
|
||||||
"""Verify we correctly measure the amount of indentation."""
|
"""Verify we correctly measure the amount of indentation."""
|
||||||
actual = processor.expand_indent(string)
|
actual = processor.expand_indent(string)
|
||||||
assert expected == actual
|
assert expected == actual
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.mark.parametrize('token, log_string', [
|
||||||
|
[(tokenize.COMMENT, '# this is a comment',
|
||||||
|
(1, 0), # (start_row, start_column)
|
||||||
|
(1, 19), # (end_ro, end_column)
|
||||||
|
'# this is a comment',),
|
||||||
|
"l.1\t[:19]\tCOMMENT\t'# this is a comment'"],
|
||||||
|
[(tokenize.COMMENT, '# this is a comment',
|
||||||
|
(1, 5), # (start_row, start_column)
|
||||||
|
(1, 19), # (end_ro, end_column)
|
||||||
|
'# this is a comment',),
|
||||||
|
"l.1\t[5:19]\tCOMMENT\t'# this is a comment'"],
|
||||||
|
[(tokenize.COMMENT, '# this is a comment',
|
||||||
|
(1, 0), # (start_row, start_column)
|
||||||
|
(2, 19), # (end_ro, end_column)
|
||||||
|
'# this is a comment',),
|
||||||
|
"l.1\tl.2\tCOMMENT\t'# this is a comment'"],
|
||||||
|
])
|
||||||
|
def test_log_token(token, log_string):
|
||||||
|
"""Verify we use the log object passed in."""
|
||||||
|
LOG = mock.Mock()
|
||||||
|
processor.log_token(LOG, token)
|
||||||
|
LOG.log.assert_called_once_with(
|
||||||
|
5, # flake8._EXTRA_VERBOSE
|
||||||
|
log_string,
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.mark.parametrize('current_count, token_text, expected', [
|
||||||
|
(None, '(', 1),
|
||||||
|
(None, '[', 1),
|
||||||
|
(None, '{', 1),
|
||||||
|
(1, ')', 0),
|
||||||
|
(1, ']', 0),
|
||||||
|
(1, '}', 0),
|
||||||
|
(10, '+', 10),
|
||||||
|
])
|
||||||
|
def test_count_parentheses(current_count, token_text, expected):
|
||||||
|
"""Verify our arithmetic is correct."""
|
||||||
|
assert processor.count_parentheses(current_count, token_text) == expected
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue