Skip to content

Commit

Permalink
100% test coverage for new identify module
Browse files Browse the repository at this point in the history
  • Loading branch information
timothycrosley committed Dec 31, 2020
1 parent 0383c36 commit 8e70db8
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 9 deletions.
18 changes: 10 additions & 8 deletions isort/identify.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ def imports(
break

stripped_line = next_line.strip().split("#")[0]
continue
continue # pragma: no cover

line, *end_of_line_comment = raw_line.split("#", 1)
statements = [line.strip() for line in line.split(";")]
Expand All @@ -88,7 +88,7 @@ def imports(
elif line.startswith("from "):
type_of_import = "from"
else:
continue
continue # pragma: no cover

import_string, _ = parse_comments(line)
normalized_import_string = (
Expand Down Expand Up @@ -135,13 +135,15 @@ def imports(
break
line, _ = parse_comments(next_line)
import_string += "\n" + line

if import_string.strip().endswith(
(" import", " cimport")
) or line.strip().startswith(("import ", "cimport ")):
import_string += "\n" + line
else:
import_string = import_string.rstrip().rstrip("\\") + " " + line.lstrip()
if import_string.strip().endswith(
(" import", " cimport")
) or line.strip().startswith(("import ", "cimport ")):
import_string += "\n" + line
else:
import_string = (
import_string.rstrip().rstrip("\\") + " " + line.lstrip()
)

if type_of_import == "from":
import_string = (
Expand Down
28 changes: 27 additions & 1 deletion tests/unit/test_identify.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
from typing import List

from isort import Config, identify
from isort.identify import Import


def imports_in_code(code: str, **kwargs) -> List[identify.Import]:
Expand Down Expand Up @@ -219,12 +220,37 @@ def test_complex_examples():
from os (
import path
)
from os import \\
path
from os \\
import (
path
)
from os import ( \\"""
)
)
== 7
== 9
)
assert not imports_in_code("from os import \\")
assert (
imports_in_code(
"""
from os \\
import (
system"""
)
== [
Import(
line_number=2,
indented=False,
module="os",
attribute="system",
alias=None,
cimport=False,
file_path=None,
)
]
)


def test_aliases():
Expand Down

0 comments on commit 8e70db8

Please sign in to comment.