summaryrefslogtreecommitdiff
path: root/test_isort.py
diff options
context:
space:
mode:
authorGraeme Coupar <grambo@grambo.me.uk>2018-01-19 15:17:08 +0000
committerGraeme Coupar <grambo@grambo.me.uk>2018-01-19 15:17:08 +0000
commit92f53fc47e2ad217ee137c145d6892291cb31fb8 (patch)
tree014f56922ee9fe8ab71e9c363193db32ad54125c /test_isort.py
parent3b011412742d09ba768346379a52cd0784d1514f (diff)
downloadisort-92f53fc47e2ad217ee137c145d6892291cb31fb8.tar.gz
Don't add un-neccesary line break in grouped vertical grid.
Prior to this change, isort was always adding 1 to the current line length when determining whether or not the current line had got too long when outputting a vertical grid. - For imports that are not last, this is fine. We need to account for the comma after the import. - For the final import in vertical grid mode this is also fine. We need to account for the closing `)`. - For the final import in the grouped vertical grid we put the closing ) on the next line, so adding 1 to the line length causes isort to add un-neccesary line breaks when the final import would only just fit onto the line by one character. For example, with a line length of 20: ``` from x import ( abcd, efgh, ijkl ) ``` will end up reformatted as ``` from x import ( abcd, efgh, ijkl ) ``` This is causing problems for us, as we run yapf on our code as well as isort, and our imports change depending on which tool ran last.
Diffstat (limited to 'test_isort.py')
-rw-r--r--test_isort.py10
1 files changed, 10 insertions, 0 deletions
diff --git a/test_isort.py b/test_isort.py
index de4f8c9c..5e4e179a 100644
--- a/test_isort.py
+++ b/test_isort.py
@@ -36,6 +36,8 @@ SHORT_IMPORT = "from third_party import lib1, lib2, lib3, lib4"
SINGLE_FROM_IMPORT = "from third_party import lib1"
+SINGLE_LINE_LONG_IMPORT = "from third_party import lib1, lib2, lib3, lib4, lib5, lib5ab"
+
REALLY_LONG_IMPORT = ("from third_party import lib1, lib2, lib3, lib4, lib5, lib6, lib7, lib8, lib9, lib10, lib11,"
"lib12, lib13, lib14, lib15, lib16, lib17, lib18, lib20, lib21, lib22")
REALLY_LONG_IMPORT_WITH_COMMENT = ("from third_party import lib1, lib2, lib3, lib4, lib5, lib6, lib7, lib8, lib9, "
@@ -352,6 +354,14 @@ def test_output_modes():
multi_line_output=WrapModes.NOQA).output
assert output_noqa == "from third_party import lib1, lib2, lib3, lib4, lib5, lib6, lib7, lib8, lib9, lib10, lib11, lib12, lib13, lib14, lib15, lib16, lib17, lib18, lib20, lib21, lib22 # NOQA comment\n" # NOQA
+ test_output_vertical_grid_grouped_doesnt_wrap_early = SortImports(file_contents=SINGLE_LINE_LONG_IMPORT,
+ multi_line_output=WrapModes.VERTICAL_GRID_GROUPED,
+ line_length=40, indent=' ').output
+ assert test_output_vertical_grid_grouped_doesnt_wrap_early == ("from third_party import (\n"
+ " lib1, lib2, lib3, lib4, lib5, lib5ab\n"
+ ")\n")
+
+
def test_qa_comment_case():
test_input = "from veryveryveryveryveryveryveryveryveryveryvery import X # NOQA"