Skip to content

Commit 9815f49

Browse files
authoredApr 7, 2021
Merge pull request #1309 from asottile/improve_coverage
improve code coverage in a few places
2 parents 5899e7d + 737e049 commit 9815f49

File tree

3 files changed

+9
-17
lines changed

3 files changed

+9
-17
lines changed
 

‎src/flake8/processor.py

+1-13
Original file line numberDiff line numberDiff line change
@@ -446,8 +446,6 @@ def log_token(log: logging.Logger, token: _Token) -> None:
446446
)
447447

448448

449-
# NOTE(sigmavirus24): This was taken wholesale from
450-
# https://github.com/PyCQA/pycodestyle
451449
def expand_indent(line: str) -> int:
452450
r"""Return the amount of indentation.
453451
@@ -462,17 +460,7 @@ def expand_indent(line: str) -> int:
462460
>>> expand_indent(' \t')
463461
16
464462
"""
465-
if "\t" not in line:
466-
return len(line) - len(line.lstrip())
467-
result = 0
468-
for char in line:
469-
if char == "\t":
470-
result = result // 8 * 8 + 8
471-
elif char == " ":
472-
result += 1
473-
else:
474-
break
475-
return result
463+
return len(line.expandtabs(8))
476464

477465

478466
# NOTE(sigmavirus24): This was taken wholesale from

‎src/flake8/utils.py

+1-4
Original file line numberDiff line numberDiff line change
@@ -231,9 +231,7 @@ def parse_unified_diff(diff: Optional[str] = None) -> Dict[str, Set[int]]:
231231
parsed_paths: Dict[str, Set[int]] = collections.defaultdict(set)
232232
for line in diff.splitlines():
233233
if number_of_rows:
234-
# NOTE(sigmavirus24): Below we use a slice because stdin may be
235-
# bytes instead of text on Python 3.
236-
if line[:1] != "-":
234+
if not line or line[0] != "-":
237235
number_of_rows -= 1
238236
# We're in the part of the diff that has lines starting with +, -,
239237
# and ' ' to show context and the changes made. We skip these
@@ -317,7 +315,6 @@ def _default_predicate(*args: str) -> bool:
317315
def filenames_from(
318316
arg: str, predicate: Optional[Callable[[str], bool]] = None
319317
) -> Generator[str, None, None]:
320-
# noqa: E501
321318
"""Generate filenames from an argument.
322319
323320
:param str arg:

‎tests/unit/test_utils.py

+7
Original file line numberDiff line numberDiff line change
@@ -313,3 +313,10 @@ def test_stdin_get_value_crlf():
313313
stdin = io.TextIOWrapper(io.BytesIO(b'1\r\n2\r\n'), 'UTF-8')
314314
with mock.patch.object(sys, 'stdin', stdin):
315315
assert utils.stdin_get_value.__wrapped__() == '1\n2\n'
316+
317+
318+
def test_stdin_unknown_coding_token():
319+
"""Ensure we produce source even for unknown encodings."""
320+
stdin = io.TextIOWrapper(io.BytesIO(b'# coding: unknown\n'), 'UTF-8')
321+
with mock.patch.object(sys, 'stdin', stdin):
322+
assert utils.stdin_get_value.__wrapped__() == '# coding: unknown\n'

0 commit comments

Comments
 (0)
Please sign in to comment.