-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add partial support for unused import removal
- Loading branch information
Showing
5 changed files
with
104 additions
and
3 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,59 @@ | ||
""" | ||
Test unused import detection and removal. | ||
""" | ||
|
||
from unittest import skip | ||
|
||
from deadcode.cli import main | ||
from deadcode.utils.base_test_case import BaseTestCase | ||
from deadcode.utils.fix_indent import fix_indent | ||
|
||
|
||
class TestAssignmentExpressionRemoval(BaseTestCase): | ||
def test_variable(self): | ||
self.files = { | ||
'file2.py': """ | ||
from file1 import ( | ||
foo, | ||
bar, | ||
xyz | ||
) | ||
from file1 import foo | ||
def fn(): | ||
pass | ||
fn() | ||
""" | ||
} | ||
|
||
unused_names = main('file2.py --no-color --fix -v'.split()) | ||
|
||
self.assertEqual( | ||
unused_names, | ||
fix_indent("""\ | ||
file2.py:2:4: DC07 Import `foo` is never used | ||
file2.py:3:4: DC07 Import `bar` is never used | ||
file2.py:4:4: DC07 Import `xyz` is never used | ||
file2.py:7:18: DC07 Import `foo` is never used | ||
Removed 4 unused code items!""") | ||
) | ||
|
||
# TODO: empty imports statements should be removed as well. | ||
self.assertFiles( | ||
{ | ||
'file2.py': """ | ||
from file1 import ( | ||
) | ||
from file1 import | ||
def fn(): | ||
pass | ||
fn() | ||
""" | ||
} | ||
) |