mirror of
https://github.com/PyCQA/flake8.git
synced 2026-03-30 10:46:54 +00:00
Merge pull request #1309 from asottile/improve_coverage
improve code coverage in a few places
This commit is contained in:
commit
9815f49cc4
3 changed files with 9 additions and 17 deletions
|
|
@ -446,8 +446,6 @@ def log_token(log: logging.Logger, token: _Token) -> None:
|
|||
)
|
||||
|
||||
|
||||
# NOTE(sigmavirus24): This was taken wholesale from
|
||||
# https://github.com/PyCQA/pycodestyle
|
||||
def expand_indent(line: str) -> int:
|
||||
r"""Return the amount of indentation.
|
||||
|
||||
|
|
@ -462,17 +460,7 @@ def expand_indent(line: str) -> int:
|
|||
>>> expand_indent(' \t')
|
||||
16
|
||||
"""
|
||||
if "\t" not in line:
|
||||
return len(line) - len(line.lstrip())
|
||||
result = 0
|
||||
for char in line:
|
||||
if char == "\t":
|
||||
result = result // 8 * 8 + 8
|
||||
elif char == " ":
|
||||
result += 1
|
||||
else:
|
||||
break
|
||||
return result
|
||||
return len(line.expandtabs(8))
|
||||
|
||||
|
||||
# NOTE(sigmavirus24): This was taken wholesale from
|
||||
|
|
|
|||
|
|
@ -231,9 +231,7 @@ def parse_unified_diff(diff: Optional[str] = None) -> Dict[str, Set[int]]:
|
|||
parsed_paths: Dict[str, Set[int]] = collections.defaultdict(set)
|
||||
for line in diff.splitlines():
|
||||
if number_of_rows:
|
||||
# NOTE(sigmavirus24): Below we use a slice because stdin may be
|
||||
# bytes instead of text on Python 3.
|
||||
if line[:1] != "-":
|
||||
if not line or line[0] != "-":
|
||||
number_of_rows -= 1
|
||||
# We're in the part of the diff that has lines starting with +, -,
|
||||
# and ' ' to show context and the changes made. We skip these
|
||||
|
|
@ -317,7 +315,6 @@ def _default_predicate(*args: str) -> bool:
|
|||
def filenames_from(
|
||||
arg: str, predicate: Optional[Callable[[str], bool]] = None
|
||||
) -> Generator[str, None, None]:
|
||||
# noqa: E501
|
||||
"""Generate filenames from an argument.
|
||||
|
||||
:param str arg:
|
||||
|
|
|
|||
|
|
@ -313,3 +313,10 @@ def test_stdin_get_value_crlf():
|
|||
stdin = io.TextIOWrapper(io.BytesIO(b'1\r\n2\r\n'), 'UTF-8')
|
||||
with mock.patch.object(sys, 'stdin', stdin):
|
||||
assert utils.stdin_get_value.__wrapped__() == '1\n2\n'
|
||||
|
||||
|
||||
def test_stdin_unknown_coding_token():
|
||||
"""Ensure we produce source even for unknown encodings."""
|
||||
stdin = io.TextIOWrapper(io.BytesIO(b'# coding: unknown\n'), 'UTF-8')
|
||||
with mock.patch.object(sys, 'stdin', stdin):
|
||||
assert utils.stdin_get_value.__wrapped__() == '# coding: unknown\n'
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue