-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
91cb291
commit ef71809
Showing
8 changed files
with
174 additions
and
40 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
from hogwarts.magic_views.gen_imports import ImportsGenerator | ||
from hogwarts.utils import code_strip | ||
|
||
code = """ | ||
import ast | ||
import datetime | ||
from django.views.generic import DetailView, ListView | ||
from .forms import MyForm | ||
""" | ||
|
||
|
||
def test_it_generates_imports_from_code(): | ||
gen = ImportsGenerator() | ||
expected = { | ||
None: ["ast", "datetime"], | ||
"django.views.generic": ["DetailView", "ListView"], | ||
".forms": ["MyForm"], | ||
} | ||
gen.parse_imports(code_strip(code)) | ||
|
||
assert gen.get_merge_imports() == expected | ||
|
||
|
||
def test_it_merges_import_with_code(): | ||
gen = ImportsGenerator() | ||
|
||
expected_code = """ | ||
import ast, datetime | ||
from django.views.generic import DetailView, ListView, UpdateView | ||
from .forms import MyForm, YouForm | ||
""" | ||
|
||
gen.parse_imports(code_strip(code)) | ||
gen.add("django.views.generic", "UpdateView") | ||
gen.add(".forms", "YouForm") | ||
|
||
assert gen.gen() == code_strip(expected_code) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters