Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Add test case and update code
  • Loading branch information
adhikasp committed Sep 4, 2017
commit 87b40d50f757e138e721b3b0b53c928c0a3768f7
10 changes: 6 additions & 4 deletions autoflake.py
Original file line number Diff line number Diff line change
Expand Up @@ -515,11 +515,13 @@ def get_imported_name(module):
- `a as b` -> b
"""
if '.' in module:
return str(module.split('.')[-1])
elif ' as ' in module:
return str(module.split(' as ')[-1])
name = module.split('.')[-1]
elif re.search(r'\bas\b', module):
name = re.split(r'\bas\b', module)[-1]
else:
name = module
# str() to force python 2 to not use unicode
return str(module)
return str(name.strip())

def get_indentation(line):
"""Return leading whitespace."""
Expand Down
16 changes: 16 additions & 0 deletions test_autoflake.py
Original file line number Diff line number Diff line change
Expand Up @@ -526,6 +526,22 @@ def test_filter_code_populate_all_from_import(self):
""", ''.join(autoflake.filter_code("""
from a.b import Foo
from a.c import Bar
""", populate_all=True)))

def test_filter_code_populate_all_as(self):
self.assertEqual("""
import math as m
__all__ = ['m']
""", ''.join(autoflake.filter_code("""
import math as m
""", populate_all=True)))

def test_filter_code_populate_all_with_tab(self):
self.assertEqual("""
import math\tas\tm
__all__ = ['m']
""", ''.join(autoflake.filter_code("""
import math\tas\tm
""", populate_all=True)))

def test_fix_code(self):
Expand Down