1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50
|
import pytest
from isort import wrap
from isort.settings import Config
from isort.wrap_modes import WrapModes
def test_import_statement():
assert wrap.import_statement("", [], []) == ""
assert (
wrap.import_statement("from x import ", ["y"], [], config=Config(balanced_wrapping=True))
== "from x import (y)"
)
assert (
wrap.import_statement("from long_import ", ["verylong"] * 10, [])
== """from long_import (verylong, verylong, verylong, verylong, verylong, verylong,
verylong, verylong, verylong, verylong)"""
)
assert wrap.import_statement("from x import ", ["y", "z"], [], explode=True) == (
"from x import (\n y,\n z,\n)"
)
@pytest.mark.parametrize(
("multi_line_output", "expected"),
[
(
WrapModes.VERTICAL_HANGING_INDENT, # type: ignore
"""from a import (
b as c # comment that is long enough that this import doesn't fit in one line (parens)
)""",
),
(
WrapModes.VERTICAL, # type: ignore
"""from a import (
b as c) # comment that is long enough that this import doesn't fit in one line (parens)""",
),
],
)
def test_line__comment_with_brackets__expects_unchanged_comment(multi_line_output, expected):
content = (
"from a import b as c "
"# comment that is long enough that this import doesn't fit in one line (parens)"
)
config = Config(
multi_line_output=multi_line_output,
use_parentheses=True,
)
assert wrap.line(content=content, line_separator="\n", config=config) == expected
|