-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Updated libcst dependency to include some recent fixes. Should be updated again with a new libcst release. - Added tests to ensure imports are being added at the right place. - Removed a workaround in NameResolutionMixin
- Loading branch information
1 parent
e2dabb5
commit 6c4edd6
Showing
5 changed files
with
57 additions
and
15 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
from libcst.codemod import CodemodTest | ||
from libcst.codemod.visitors import AddImportsVisitor | ||
from libcst.codemod.visitors import ImportItem | ||
|
||
|
||
class TestAddImports(CodemodTest): | ||
TRANSFORM = AddImportsVisitor | ||
|
||
def test_add_only_at_top(self): | ||
before = """ | ||
b() | ||
import a | ||
""" | ||
|
||
after = """ | ||
import b | ||
b() | ||
import a | ||
""" | ||
|
||
self.assertCodemod(before, after, imports=[ImportItem("b", None, None)]) | ||
|
||
def test_may_duplicate_imports(self): | ||
before = """ | ||
a() | ||
import a | ||
""" | ||
|
||
after = """ | ||
import a | ||
a() | ||
import a | ||
""" | ||
self.assertCodemod(before, after, imports=[ImportItem("a", None, None)]) | ||
|
||
def test_may_duplicate_from_imports(self): | ||
before = """ | ||
y() | ||
from a import x | ||
""" | ||
|
||
after = """ | ||
from a import y | ||
y() | ||
from a import x | ||
""" | ||
self.assertCodemod(before, after, imports=[ImportItem("a", "y", None)]) |