-
Notifications
You must be signed in to change notification settings - Fork 51
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
3 changed files
with
110 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
from lib2to3.fixes import fix_imports | ||
|
||
|
||
class FixImportsSix(fix_imports.FixImports): | ||
|
||
mapping = { | ||
'__builtin__': 'six.moves.builtins', | ||
'_winreg': 'six.moves.winreg', | ||
'BaseHTTPServer': 'six.moves.BaseHTTPServer', | ||
'CGIHTTPServer': 'six.moves.CGIHTTPServer', | ||
'ConfigParser': 'six.moves.configparser', | ||
'copy_reg': 'six.moves.copyreg', | ||
'Cookie': 'six.moves.http_cookies', | ||
'cookielib': 'six.moves.http_cookiejar', | ||
'cPickle': 'six.moves.cPickle', | ||
'Dialog': 'six.moves.tkinter_dialog', | ||
'dummy_thread': 'six.moves._dummy_thread', | ||
# cStringIO.StringIO() | ||
# email.MIMEBase | ||
# email.MIMEMultipart | ||
# email.MIMENonMultipart | ||
# email.MIMEText | ||
'FileDialog': 'six.moves.tkinter_filedialog', | ||
'gdbm': 'six.moves.dbm_gnu', | ||
'htmlentitydefs': 'six.moves.html_entities', | ||
'HTMLParser': 'six.moves.html_parser', | ||
'httplib': 'six.moves.http_client', | ||
# intern() | ||
# itertools.ifilter() | ||
# itertools.ifilterfalse() | ||
# itertools.imap() | ||
# itertools.izip() | ||
# itertools.zip_longest() | ||
# pipes.quote | ||
'Queue': 'six.moves.queue', | ||
# reduce() | ||
# reload() | ||
'repr': 'six.moves.reprlib', | ||
'robotparser': 'six.moves.urllib_robotparser', | ||
'ScrolledText': 'six.moves.tkinter_scrolledtext', | ||
'SimpleDialog': 'six.moves.tkinter_simpledialog', | ||
'SimpleHTTPServer': 'six.moves.SimpleHTTPServer', | ||
'SimpleXMLRPCServer': 'six.moves.xmlrpc_server', | ||
'SocketServer': 'six.moves.socketserver', | ||
'thread': 'six.moves._thread', | ||
'Tix': 'six.moves.tkinter_tix', | ||
'tkColorChooser': 'six.moves.tkinter_colorchooser', | ||
'tkCommonDialog': 'six.moves.tkinter_commondialog', | ||
'Tkconstants': 'six.moves.tkinter_constants', | ||
'Tkdnd': 'six.moves.tkinter_dnd', | ||
'tkFileDialog': 'six.moves.tkinter_filedialog', | ||
'tkFont': 'six.moves.tkinter_font', | ||
'Tkinter': 'six.moves.tkinter', | ||
'tkMessageBox': 'six.moves.tkinter_messagebox', | ||
'tkSimpleDialog': 'six.moves.tkinter_tksimpledialog', | ||
'ttk': 'six.moves.tkinter_ttk', | ||
# urllib | ||
# UserDict.UserDict | ||
# UserList.UserList | ||
# UserString.UserString | ||
'xmlrpclib': 'six.moves.xmlrpc_client', | ||
} |
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,47 @@ | ||
from __future__ import absolute_import | ||
|
||
import sys | ||
|
||
try: | ||
from six.moves import tkinter | ||
except ImportError: | ||
tkinter = None | ||
|
||
from libmodernize.fixes import fix_imports_six | ||
|
||
from utils import check_on_input | ||
|
||
|
||
MOVED_MODULE = ("""\ | ||
import ConfigParser | ||
ConfigParser.ConfigParser() | ||
""", """\ | ||
import six.moves.configparser | ||
six.moves.configparser.ConfigParser() | ||
""") | ||
|
||
MOVED_MODULE_FROMLIST = ("""\ | ||
from ConfigParser import ConfigParser | ||
ConfigParser() | ||
""", """\ | ||
from six.moves.configparser import ConfigParser | ||
ConfigParser() | ||
""") | ||
|
||
|
||
def test_moved_module(): | ||
check_on_input(*MOVED_MODULE) | ||
|
||
def test_moved_module_fromlist(): | ||
check_on_input(*MOVED_MODULE_FROMLIST) | ||
|
||
def test_validate_mapping(): | ||
for py2_name, six_name in fix_imports_six.FixImportsSix.mapping.items(): | ||
try: | ||
__import__(py2_name) | ||
__import__(six_name) | ||
except ImportError as exc: | ||
if 'tkinter' in six_name and tkinter is not None: | ||
raise | ||
elif 'winreg' in six_name and sys.platform.startswith('win'): | ||
raise |