diff options
author | Timothy Edmund Crosley <timothy.crosley@gmail.com> | 2015-02-19 01:42:11 -0500 |
---|---|---|
committer | Timothy Edmund Crosley <timothy.crosley@gmail.com> | 2015-02-19 01:42:11 -0500 |
commit | 74ddc39485c18cb78972fc0088f82b8af7b24c53 (patch) | |
tree | 6ab5a6c35500b53234c55b0202c7697ac35f16b2 | |
parent | c731b692634a5edfd5831bdba611795a3b1f9cfa (diff) | |
parent | 99a1bc92044b9020a2dec8d4ea915a487c0cf0e9 (diff) | |
download | isort-74ddc39485c18cb78972fc0088f82b8af7b24c53.tar.gz |
Merge pull request #257 from timothycrosley/feature/fix-issue-250
Feature/fix issue 250
-rw-r--r-- | isort/isort.py | 5 | ||||
-rw-r--r-- | test_isort.py | 20 |
2 files changed, 23 insertions, 2 deletions
diff --git a/isort/isort.py b/isort/isort.py index 3edba3a1..b0a740a0 100644 --- a/isort/isort.py +++ b/isort/isort.py @@ -627,7 +627,7 @@ class SortImports(object): import_list.remove(key) import_string = ' '.join(import_list) import_string = import_string.replace("[[i]]", "_import") - return import_string + return import_string.replace("{ ", "{|").replace(" }", "|}") def _parse(self): """Parses a python file taking out and categorizing imports.""" @@ -696,7 +696,8 @@ class SortImports(object): from_import = parts[0].split(" ") import_string = " import ".join([from_import[0] + " " + "".join(from_import[1:])] + parts[1:]) - imports = self._strip_syntax(import_string).split() + imports = [item.replace("{|", "{ ").replace("|}", " }") for item in + self._strip_syntax(import_string).split()] if "as" in imports and (imports.index('as') + 1) < len(imports): while "as" in imports: index = imports.index('as') diff --git a/test_isort.py b/test_isort.py index a26f8cc6..5ca0d67d 100644 --- a/test_isort.py +++ b/test_isort.py @@ -1300,3 +1300,23 @@ from foo import ( lib7 ) """ + + +def test_uses_jinja_variables(): + """Test a basic set of imports that use jinja variables""" + test_input = ("import sys\n" + "import os\n" + "import myproject.{ test }\n" + "import django.{ settings }") + test_output = SortImports(file_contents=test_input, known_third_party=['django'], + known_first_party=['myproject']).output + assert test_output == ("import os\n" + "import sys\n" + "\n" + "import django.{ settings }\n" + "\n" + "import myproject.{ test }\n") + + test_input = ("import {{ cookiecutter.repo_name }}\n" + "from foo import {{ cookiecutter.bar }}\n") + assert SortImports(file_contents=test_input).output == test_input |