[Python-checkins] r63356 - in sandbox/trunk/2to3/lib2to3: fixes/fix_imports.py tests/test_fixers.py

alexandre.vassalotti python-checkins at python.org
Fri May 16 08:55:45 CEST 2008


Author: alexandre.vassalotti
Date: Fri May 16 08:55:44 2008
New Revision: 63356

Log:
Added new tests for fix_imports.
Added refactoring support of from-import statements of the style:
  from foo import bar, baz


Modified:
   sandbox/trunk/2to3/lib2to3/fixes/fix_imports.py
   sandbox/trunk/2to3/lib2to3/tests/test_fixers.py

Modified: sandbox/trunk/2to3/lib2to3/fixes/fix_imports.py
==============================================================================
--- sandbox/trunk/2to3/lib2to3/fixes/fix_imports.py	(original)
+++ sandbox/trunk/2to3/lib2to3/fixes/fix_imports.py	Fri May 16 08:55:44 2008
@@ -62,7 +62,8 @@
                               | dotted_as_names< any* module=%r any* >) >
               """ % (old_module, old_module)
         yield """import_from< 'from' module_name=%r 'import'
-                   ( %s | import_as_name< %s 'as' any >) >
+                   ( %s | import_as_name< %s 'as' any > |
+                     import_as_names< any* >) >
               """ % (old_module, members, members)
         yield """import_from< 'from' module_name=%r 'import' star='*' >
               """ % old_module

Modified: sandbox/trunk/2to3/lib2to3/tests/test_fixers.py
==============================================================================
--- sandbox/trunk/2to3/lib2to3/tests/test_fixers.py	(original)
+++ sandbox/trunk/2to3/lib2to3/tests/test_fixers.py	Fri May 16 08:55:44 2008
@@ -1409,7 +1409,15 @@
     modules = {"StringIO":  ("io", ["StringIO"]),
                "cStringIO": ("io", ["StringIO"]),
                "__builtin__" : ("builtins", ["open", "Exception",
-                   "__debug__", "str"]),
+                                             "__debug__", "str"]),
+               "Queue": ("queue", ["Empty", "Queue", "LifoQueue"]),
+               "ConfigParser": ("configparser", ["ConfigParser",
+                                                 "NoOptionError",
+                                                 "NoSectionError"]),
+               "SocketServer": ("socketserver", ["TCPServer",
+                                                 "ForkingMixIn"
+                    #XXX: This is failing. Why?? "BaseServer"
+                                                 ]),
               }
 
     def test_import_module(self):
@@ -1432,6 +1440,13 @@
                 s = "from foo import %s" % member
                 self.unchanged(s)
 
+            b = "from %s import %s" % (old, ", ".join(members))
+            a = "from %s import %s" % (new, ", ".join(members))
+            self.check(b, a)
+
+            s = "from foo import %s" % ", ".join(members)
+            self.unchanged(s)
+
     def test_import_module_as(self):
         for old, (new, members) in self.modules.items():
             b = "import %s as foo_bar" % old
@@ -1479,6 +1494,16 @@
                     foo(%s, %s())
                     """ % (new, member, member, member)
                 self.check(b, a)
+            b = """
+                from %s import %s
+                foo(%s)
+                """ % (old, ", ".join(members), ", ".join(members))
+            a = """
+                from %s import %s
+                foo(%s)
+                """ % (new, ", ".join(members), ", ".join(members))
+            self.check(b, a)
+
 
 class Test_input(FixerTestCase):
     fixer = "input"


More information about the Python-checkins mailing list