diff options
author | Timothy Edmund Crosley <timothy.crosley@gmail.com> | 2015-02-19 00:21:16 -0500 |
---|---|---|
committer | Timothy Edmund Crosley <timothy.crosley@gmail.com> | 2015-02-19 00:21:16 -0500 |
commit | 5739c006e405575e1d273c4474fa5122e3e6a127 (patch) | |
tree | ef6f4298088429ae0871f58f73db98375f77d736 | |
parent | ccc26ffd42b9aca07f1c101d49d5526a7a07c497 (diff) | |
parent | 5722a60e58e7f42e9aaff556db04a8704fc00fcb (diff) | |
download | isort-5739c006e405575e1d273c4474fa5122e3e6a127.tar.gz |
Merge pull request #256 from NorthIsUp/patch-1
force_grid_wrap code and setting had different names
-rw-r--r-- | isort/isort.py | 6 | ||||
-rw-r--r-- | test_isort.py | 31 |
2 files changed, 30 insertions, 7 deletions
diff --git a/isort/isort.py b/isort/isort.py index 13dc6d44..3edba3a1 100644 --- a/isort/isort.py +++ b/isort/isort.py @@ -380,11 +380,9 @@ class SortImports(object): import_statement = self._add_comments(comments, import_start + (", ").join(from_imports)) if not from_imports: import_statement = "" - if len(import_statement) > self.config['line_length']: - import_statement = self._wrap(import_statement) if len(from_imports) > 1 and ( len(import_statement) > self.config['line_length'] - or self.config.get('force_from_wrap') + or self.config.get('force_grid_wrap') ): output_mode = settings.WrapModes._fields[self.config.get('multi_line_output', 0)].lower() @@ -409,6 +407,8 @@ class SortImports(object): new_import_statement = formatter(import_start, copy.copy(from_imports), dynamic_indent, indent, line_length, comments) lines = new_import_statement.split("\n") + elif len(import_statement) > self.config['line_length']: + import_statement = self._wrap(import_statement) if import_statement: above_comments = self.comments['above']['from'].get(module, None) diff --git a/test_isort.py b/test_isort.py index 457b9ef2..2c354147 100644 --- a/test_isort.py +++ b/test_isort.py @@ -1264,17 +1264,40 @@ def test_consistency(): def test_force_grid_wrap(): """Ensures removing imports works as expected.""" - test_input = ("from foo import lib6, lib7\n" - "from bar import lib2\n") + test_input = ( + "from foo import lib6, lib7\n" + "from bar import lib2\n" + ) test_output = SortImports( file_contents=test_input, - force_from_wrap=True, + force_grid_wrap=True, multi_line_output=WrapModes.VERTICAL_HANGING_INDENT ).output - print(test_output) assert test_output == """from bar import lib2 from foo import ( lib6, lib7 ) """ + +def test_force_grid_wrap_long(): + """Ensure that force grid wrap still happens with long line length""" + test_input = ( + "from foo import lib6, lib7\n" + "from bar import lib2\n" + "from babar import something_that_is_kind_of_long" + ) + test_output = SortImports( + file_contents=test_input, + force_grid_wrap=True, + multi_line_output=WrapModes.VERTICAL_HANGING_INDENT, + line_length=9999, + ).output + print(test_output) + assert test_output == """from babar import something_that_is_kind_of_long +from bar import lib2 +from foo import ( + lib6, + lib7 +) +""" |