2008-03-19 02:04:44 -03:00
|
|
|
""" Test suite for the fixer modules """
|
|
|
|
|
|
|
|
# Python imports
|
2008-10-04 18:04:36 -03:00
|
|
|
import os
|
2008-03-19 02:04:44 -03:00
|
|
|
import unittest
|
Merged revisions 64286 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk
................
r64286 | benjamin.peterson | 2008-06-14 21:31:05 -0500 (Sat, 14 Jun 2008) | 49 lines
Merged revisions 63661,63666,63695,63711,63729,63769,63790,63880,63886 via svnmerge from
svn+ssh://pythondev@svn.python.org/sandbox/trunk/2to3/lib2to3
........
r63661 | georg.brandl | 2008-05-26 05:26:20 -0500 (Mon, 26 May 2008) | 2 lines
Add import fixes for dbm package.
........
r63666 | georg.brandl | 2008-05-26 05:49:09 -0500 (Mon, 26 May 2008) | 2 lines
Add xmlrpc package fixes.
........
r63695 | georg.brandl | 2008-05-26 10:14:33 -0500 (Mon, 26 May 2008) | 2 lines
Add fixer entries for http package.
........
r63711 | benjamin.peterson | 2008-05-26 13:43:51 -0500 (Mon, 26 May 2008) | 2 lines
add import mapping for test.test_support -> test.support
........
r63729 | benjamin.peterson | 2008-05-26 16:31:03 -0500 (Mon, 26 May 2008) | 2 lines
mapping for commands module -> subprocess
........
r63769 | brett.cannon | 2008-05-29 00:13:13 -0500 (Thu, 29 May 2008) | 1 line
Fixer for UserString.UserString over to the collections module.
........
r63790 | brett.cannon | 2008-05-29 14:13:51 -0500 (Thu, 29 May 2008) | 4 lines
Add a fixer for UserList.
Closes issue #2878. Thanks to Quentin Gallet-Gilles for the patch.
........
r63880 | collin.winter | 2008-06-01 18:09:38 -0500 (Sun, 01 Jun 2008) | 6 lines
Move lib2to3/fixes/{basefix,util}.py down to lib2to3/.
This is step 1 of turning lib2to3/ into a general-purpose refactoring
library, reusable by other projects.
........
r63886 | collin.winter | 2008-06-01 22:15:01 -0500 (Sun, 01 Jun 2008) | 5 lines
Allow refactoring tools to specify a directory for fixer modules.
This is step 2 of turning lib2to3/ into a general-purpose refactoring
library, reusable by other projects. Step 1: r63880.
........
................
2008-06-14 23:57:40 -03:00
|
|
|
from itertools import chain
|
Merged revisions 65019 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk
................
r65019 | benjamin.peterson | 2008-07-16 12:01:46 -0500 (Wed, 16 Jul 2008) | 43 lines
Merged revisions 64863,64868,64870,64942,65001-65002,65017-65018 via svnmerge from
svn+ssh://pythondev@svn.python.org/sandbox/trunk/2to3/lib2to3
........
r64863 | brett.cannon | 2008-07-10 19:42:32 -0500 (Thu, 10 Jul 2008) | 1 line
Add urlparse -> urllib.parse to fix_imports.
........
r64868 | brett.cannon | 2008-07-10 20:00:10 -0500 (Thu, 10 Jul 2008) | 1 line
Add robotparser -> urllib.robotparser to fix_imports.
........
r64870 | brett.cannon | 2008-07-11 00:56:27 -0500 (Fri, 11 Jul 2008) | 6 lines
Fix the fixers for the new dbm package.
Had to create a new fixer (fix_imports2) which did fixes in post-order. This
because ``import anydbm`` was being translated into ``import dbm`` which was
then subsequently changed into ``import dbm.ndbm``; one transform too many.
........
r64942 | collin.winter | 2008-07-13 20:19:05 -0500 (Sun, 13 Jul 2008) | 1 line
Add a comment explaining part of fix_imports.py
........
r65001 | brett.cannon | 2008-07-16 00:11:12 -0500 (Wed, 16 Jul 2008) | 2 lines
Remove some extraneous whitespace.
........
r65002 | brett.cannon | 2008-07-16 00:12:04 -0500 (Wed, 16 Jul 2008) | 4 lines
Implement a fixer for urllib(2).
Thanks Nick Edds for the patch.
........
r65017 | benjamin.peterson | 2008-07-16 11:04:19 -0500 (Wed, 16 Jul 2008) | 1 line
fix 2to3 in Python 2.6
........
r65018 | benjamin.peterson | 2008-07-16 11:55:21 -0500 (Wed, 16 Jul 2008) | 1 line
normalize whitespace
........
................
2008-07-16 15:44:47 -03:00
|
|
|
from operator import itemgetter
|
2008-03-19 02:04:44 -03:00
|
|
|
|
|
|
|
# Local imports
|
Merged revisions 67428 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk
................
r67428 | benjamin.peterson | 2008-11-28 16:12:14 -0600 (Fri, 28 Nov 2008) | 57 lines
Merged revisions 67384,67386-67387,67389-67390,67392,67399-67400,67403-67405,67426 via svnmerge from
svn+ssh://pythondev@svn.python.org/sandbox/trunk/2to3/lib2to3
........
r67384 | benjamin.peterson | 2008-11-25 16:13:31 -0600 (Tue, 25 Nov 2008) | 4 lines
don't duplicate calls to start_tree()
RefactoringTool.pre_order values now holds a list of the fixers while pre_order_mapping holds the dict.
........
r67386 | benjamin.peterson | 2008-11-25 16:44:52 -0600 (Tue, 25 Nov 2008) | 1 line
#4423 fix_imports was still replacing usage of a module if attributes were being used
........
r67387 | benjamin.peterson | 2008-11-25 16:47:54 -0600 (Tue, 25 Nov 2008) | 1 line
fix broken test
........
r67389 | benjamin.peterson | 2008-11-25 17:13:17 -0600 (Tue, 25 Nov 2008) | 1 line
remove compatibility code; we only cater to 2.5+
........
r67390 | benjamin.peterson | 2008-11-25 22:03:36 -0600 (Tue, 25 Nov 2008) | 1 line
fix #3994; the usage of changed imports was fixed in nested cases
........
r67392 | benjamin.peterson | 2008-11-26 11:11:40 -0600 (Wed, 26 Nov 2008) | 1 line
simpilfy and comment fix_imports
........
r67399 | benjamin.peterson | 2008-11-26 11:47:03 -0600 (Wed, 26 Nov 2008) | 1 line
remove more compatibility code
........
r67400 | benjamin.peterson | 2008-11-26 12:07:41 -0600 (Wed, 26 Nov 2008) | 1 line
set svn:ignore
........
r67403 | benjamin.peterson | 2008-11-26 13:11:11 -0600 (Wed, 26 Nov 2008) | 1 line
wrap import
........
r67404 | benjamin.peterson | 2008-11-26 13:29:49 -0600 (Wed, 26 Nov 2008) | 1 line
build the fix_imports pattern in compile_pattern, so MAPPING can be changed and reflected in the pattern
........
r67405 | benjamin.peterson | 2008-11-26 14:01:24 -0600 (Wed, 26 Nov 2008) | 1 line
stop ugly messages about runtime errors being from printed
........
r67426 | benjamin.peterson | 2008-11-28 16:01:40 -0600 (Fri, 28 Nov 2008) | 5 lines
don't replace a module name if it is in the middle of a attribute lookup
This fix also stops module names from being replaced if they are not in an attribute lookup.
........
................
2008-11-28 19:01:28 -04:00
|
|
|
from lib2to3 import pygram, pytree, refactor, fixer_util
|
Merged revisions 73370 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk
................
r73370 | benjamin.peterson | 2009-06-11 17:06:46 -0500 (Thu, 11 Jun 2009) | 105 lines
Merged revisions 72523,72950-72951,72994,73003,73033,73036-73040,73091-73093,73096,73179-73181,73192,73231,73244,73255-73256,73365 via svnmerge from
svn+ssh://pythondev@svn.python.org/sandbox/trunk/2to3/lib2to3
........
r72523 | benjamin.peterson | 2009-05-09 14:42:26 -0500 (Sat, 09 May 2009) | 1 line
remove parenthesis
........
r72950 | benjamin.peterson | 2009-05-26 18:19:45 -0500 (Tue, 26 May 2009) | 1 line
remove unused imports
........
r72951 | benjamin.peterson | 2009-05-26 18:27:00 -0500 (Tue, 26 May 2009) | 1 line
this is no longer executable
........
r72994 | benjamin.peterson | 2009-05-28 15:32:54 -0500 (Thu, 28 May 2009) | 1 line
fix test_all_fixers on Windows #6134
........
r73003 | benjamin.peterson | 2009-05-28 21:57:28 -0500 (Thu, 28 May 2009) | 4 lines
make 2to3 test utilities easier to use with other applications (3to2)
Patch by Joe Amenta
........
r73033 | benjamin.peterson | 2009-05-29 16:58:32 -0500 (Fri, 29 May 2009) | 1 line
update grammar for multi with statement
........
r73036 | benjamin.peterson | 2009-05-29 17:33:20 -0500 (Fri, 29 May 2009) | 1 line
simplify fix_unicode
........
r73037 | benjamin.peterson | 2009-05-29 17:53:03 -0500 (Fri, 29 May 2009) | 1 line
add custom error for pattern syntax errors
........
r73038 | benjamin.peterson | 2009-05-29 17:55:00 -0500 (Fri, 29 May 2009) | 1 line
complain if details are attached to a token
........
r73039 | benjamin.peterson | 2009-05-29 18:00:28 -0500 (Fri, 29 May 2009) | 1 line
add a test for whitespace
........
r73040 | benjamin.peterson | 2009-05-29 18:01:17 -0500 (Fri, 29 May 2009) | 1 line
a fix for emacs highlighting
........
r73091 | benjamin.peterson | 2009-05-31 20:55:25 -0500 (Sun, 31 May 2009) | 1 line
deprecate set_prefix() and get_prefix() in favor of a prefix property
........
r73092 | benjamin.peterson | 2009-05-31 21:00:51 -0500 (Sun, 31 May 2009) | 1 line
change hideous java naming scheme
........
r73093 | benjamin.peterson | 2009-05-31 21:01:39 -0500 (Sun, 31 May 2009) | 1 line
remove dated comment
........
r73096 | benjamin.peterson | 2009-05-31 21:40:53 -0500 (Sun, 31 May 2009) | 1 line
group tests
........
r73179 | benjamin.peterson | 2009-06-03 13:09:53 -0500 (Wed, 03 Jun 2009) | 1 line
handle the case where there's multiple trailers #6185
........
r73180 | benjamin.peterson | 2009-06-03 13:18:05 -0500 (Wed, 03 Jun 2009) | 1 line
scrap __main__ section
........
r73181 | benjamin.peterson | 2009-06-03 13:24:48 -0500 (Wed, 03 Jun 2009) | 1 line
remove shebang lines and __main__ sections
........
r73192 | benjamin.peterson | 2009-06-03 19:16:30 -0500 (Wed, 03 Jun 2009) | 4 lines
actually test something here
Thanks to Joe Amenta for noticing.y
........
r73231 | benjamin.peterson | 2009-06-04 13:38:50 -0500 (Thu, 04 Jun 2009) | 1 line
remove unused variable
........
r73244 | benjamin.peterson | 2009-06-05 08:39:25 -0500 (Fri, 05 Jun 2009) | 1 line
allow fixers to give different options in setUp
........
r73255 | benjamin.peterson | 2009-06-06 11:23:46 -0500 (Sat, 06 Jun 2009) | 1 line
fix the except fixer on one line suites #6222
........
r73256 | benjamin.peterson | 2009-06-06 11:27:40 -0500 (Sat, 06 Jun 2009) | 1 line
test one-line else and finally clauses
........
r73365 | benjamin.peterson | 2009-06-11 17:01:32 -0500 (Thu, 11 Jun 2009) | 1 line
normalize whitespace
........
................
2009-06-11 20:47:38 -03:00
|
|
|
from lib2to3.tests import support
|
2008-04-09 23:50:50 -03:00
|
|
|
|
2008-03-19 02:04:44 -03:00
|
|
|
|
|
|
|
class FixerTestCase(support.TestCase):
|
Merged revisions 73370 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk
................
r73370 | benjamin.peterson | 2009-06-11 17:06:46 -0500 (Thu, 11 Jun 2009) | 105 lines
Merged revisions 72523,72950-72951,72994,73003,73033,73036-73040,73091-73093,73096,73179-73181,73192,73231,73244,73255-73256,73365 via svnmerge from
svn+ssh://pythondev@svn.python.org/sandbox/trunk/2to3/lib2to3
........
r72523 | benjamin.peterson | 2009-05-09 14:42:26 -0500 (Sat, 09 May 2009) | 1 line
remove parenthesis
........
r72950 | benjamin.peterson | 2009-05-26 18:19:45 -0500 (Tue, 26 May 2009) | 1 line
remove unused imports
........
r72951 | benjamin.peterson | 2009-05-26 18:27:00 -0500 (Tue, 26 May 2009) | 1 line
this is no longer executable
........
r72994 | benjamin.peterson | 2009-05-28 15:32:54 -0500 (Thu, 28 May 2009) | 1 line
fix test_all_fixers on Windows #6134
........
r73003 | benjamin.peterson | 2009-05-28 21:57:28 -0500 (Thu, 28 May 2009) | 4 lines
make 2to3 test utilities easier to use with other applications (3to2)
Patch by Joe Amenta
........
r73033 | benjamin.peterson | 2009-05-29 16:58:32 -0500 (Fri, 29 May 2009) | 1 line
update grammar for multi with statement
........
r73036 | benjamin.peterson | 2009-05-29 17:33:20 -0500 (Fri, 29 May 2009) | 1 line
simplify fix_unicode
........
r73037 | benjamin.peterson | 2009-05-29 17:53:03 -0500 (Fri, 29 May 2009) | 1 line
add custom error for pattern syntax errors
........
r73038 | benjamin.peterson | 2009-05-29 17:55:00 -0500 (Fri, 29 May 2009) | 1 line
complain if details are attached to a token
........
r73039 | benjamin.peterson | 2009-05-29 18:00:28 -0500 (Fri, 29 May 2009) | 1 line
add a test for whitespace
........
r73040 | benjamin.peterson | 2009-05-29 18:01:17 -0500 (Fri, 29 May 2009) | 1 line
a fix for emacs highlighting
........
r73091 | benjamin.peterson | 2009-05-31 20:55:25 -0500 (Sun, 31 May 2009) | 1 line
deprecate set_prefix() and get_prefix() in favor of a prefix property
........
r73092 | benjamin.peterson | 2009-05-31 21:00:51 -0500 (Sun, 31 May 2009) | 1 line
change hideous java naming scheme
........
r73093 | benjamin.peterson | 2009-05-31 21:01:39 -0500 (Sun, 31 May 2009) | 1 line
remove dated comment
........
r73096 | benjamin.peterson | 2009-05-31 21:40:53 -0500 (Sun, 31 May 2009) | 1 line
group tests
........
r73179 | benjamin.peterson | 2009-06-03 13:09:53 -0500 (Wed, 03 Jun 2009) | 1 line
handle the case where there's multiple trailers #6185
........
r73180 | benjamin.peterson | 2009-06-03 13:18:05 -0500 (Wed, 03 Jun 2009) | 1 line
scrap __main__ section
........
r73181 | benjamin.peterson | 2009-06-03 13:24:48 -0500 (Wed, 03 Jun 2009) | 1 line
remove shebang lines and __main__ sections
........
r73192 | benjamin.peterson | 2009-06-03 19:16:30 -0500 (Wed, 03 Jun 2009) | 4 lines
actually test something here
Thanks to Joe Amenta for noticing.y
........
r73231 | benjamin.peterson | 2009-06-04 13:38:50 -0500 (Thu, 04 Jun 2009) | 1 line
remove unused variable
........
r73244 | benjamin.peterson | 2009-06-05 08:39:25 -0500 (Fri, 05 Jun 2009) | 1 line
allow fixers to give different options in setUp
........
r73255 | benjamin.peterson | 2009-06-06 11:23:46 -0500 (Sat, 06 Jun 2009) | 1 line
fix the except fixer on one line suites #6222
........
r73256 | benjamin.peterson | 2009-06-06 11:27:40 -0500 (Sat, 06 Jun 2009) | 1 line
test one-line else and finally clauses
........
r73365 | benjamin.peterson | 2009-06-11 17:01:32 -0500 (Thu, 11 Jun 2009) | 1 line
normalize whitespace
........
................
2009-06-11 20:47:38 -03:00
|
|
|
|
|
|
|
# Other test cases can subclass this class and replace "fixer_pkg" with
|
|
|
|
# their own.
|
|
|
|
def setUp(self, fix_list=None, fixer_pkg="lib2to3", options=None):
|
2008-09-02 23:27:16 -03:00
|
|
|
if fix_list is None:
|
Merged revisions 65019 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk
................
r65019 | benjamin.peterson | 2008-07-16 12:01:46 -0500 (Wed, 16 Jul 2008) | 43 lines
Merged revisions 64863,64868,64870,64942,65001-65002,65017-65018 via svnmerge from
svn+ssh://pythondev@svn.python.org/sandbox/trunk/2to3/lib2to3
........
r64863 | brett.cannon | 2008-07-10 19:42:32 -0500 (Thu, 10 Jul 2008) | 1 line
Add urlparse -> urllib.parse to fix_imports.
........
r64868 | brett.cannon | 2008-07-10 20:00:10 -0500 (Thu, 10 Jul 2008) | 1 line
Add robotparser -> urllib.robotparser to fix_imports.
........
r64870 | brett.cannon | 2008-07-11 00:56:27 -0500 (Fri, 11 Jul 2008) | 6 lines
Fix the fixers for the new dbm package.
Had to create a new fixer (fix_imports2) which did fixes in post-order. This
because ``import anydbm`` was being translated into ``import dbm`` which was
then subsequently changed into ``import dbm.ndbm``; one transform too many.
........
r64942 | collin.winter | 2008-07-13 20:19:05 -0500 (Sun, 13 Jul 2008) | 1 line
Add a comment explaining part of fix_imports.py
........
r65001 | brett.cannon | 2008-07-16 00:11:12 -0500 (Wed, 16 Jul 2008) | 2 lines
Remove some extraneous whitespace.
........
r65002 | brett.cannon | 2008-07-16 00:12:04 -0500 (Wed, 16 Jul 2008) | 4 lines
Implement a fixer for urllib(2).
Thanks Nick Edds for the patch.
........
r65017 | benjamin.peterson | 2008-07-16 11:04:19 -0500 (Wed, 16 Jul 2008) | 1 line
fix 2to3 in Python 2.6
........
r65018 | benjamin.peterson | 2008-07-16 11:55:21 -0500 (Wed, 16 Jul 2008) | 1 line
normalize whitespace
........
................
2008-07-16 15:44:47 -03:00
|
|
|
fix_list = [self.fixer]
|
Merged revisions 73370 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk
................
r73370 | benjamin.peterson | 2009-06-11 17:06:46 -0500 (Thu, 11 Jun 2009) | 105 lines
Merged revisions 72523,72950-72951,72994,73003,73033,73036-73040,73091-73093,73096,73179-73181,73192,73231,73244,73255-73256,73365 via svnmerge from
svn+ssh://pythondev@svn.python.org/sandbox/trunk/2to3/lib2to3
........
r72523 | benjamin.peterson | 2009-05-09 14:42:26 -0500 (Sat, 09 May 2009) | 1 line
remove parenthesis
........
r72950 | benjamin.peterson | 2009-05-26 18:19:45 -0500 (Tue, 26 May 2009) | 1 line
remove unused imports
........
r72951 | benjamin.peterson | 2009-05-26 18:27:00 -0500 (Tue, 26 May 2009) | 1 line
this is no longer executable
........
r72994 | benjamin.peterson | 2009-05-28 15:32:54 -0500 (Thu, 28 May 2009) | 1 line
fix test_all_fixers on Windows #6134
........
r73003 | benjamin.peterson | 2009-05-28 21:57:28 -0500 (Thu, 28 May 2009) | 4 lines
make 2to3 test utilities easier to use with other applications (3to2)
Patch by Joe Amenta
........
r73033 | benjamin.peterson | 2009-05-29 16:58:32 -0500 (Fri, 29 May 2009) | 1 line
update grammar for multi with statement
........
r73036 | benjamin.peterson | 2009-05-29 17:33:20 -0500 (Fri, 29 May 2009) | 1 line
simplify fix_unicode
........
r73037 | benjamin.peterson | 2009-05-29 17:53:03 -0500 (Fri, 29 May 2009) | 1 line
add custom error for pattern syntax errors
........
r73038 | benjamin.peterson | 2009-05-29 17:55:00 -0500 (Fri, 29 May 2009) | 1 line
complain if details are attached to a token
........
r73039 | benjamin.peterson | 2009-05-29 18:00:28 -0500 (Fri, 29 May 2009) | 1 line
add a test for whitespace
........
r73040 | benjamin.peterson | 2009-05-29 18:01:17 -0500 (Fri, 29 May 2009) | 1 line
a fix for emacs highlighting
........
r73091 | benjamin.peterson | 2009-05-31 20:55:25 -0500 (Sun, 31 May 2009) | 1 line
deprecate set_prefix() and get_prefix() in favor of a prefix property
........
r73092 | benjamin.peterson | 2009-05-31 21:00:51 -0500 (Sun, 31 May 2009) | 1 line
change hideous java naming scheme
........
r73093 | benjamin.peterson | 2009-05-31 21:01:39 -0500 (Sun, 31 May 2009) | 1 line
remove dated comment
........
r73096 | benjamin.peterson | 2009-05-31 21:40:53 -0500 (Sun, 31 May 2009) | 1 line
group tests
........
r73179 | benjamin.peterson | 2009-06-03 13:09:53 -0500 (Wed, 03 Jun 2009) | 1 line
handle the case where there's multiple trailers #6185
........
r73180 | benjamin.peterson | 2009-06-03 13:18:05 -0500 (Wed, 03 Jun 2009) | 1 line
scrap __main__ section
........
r73181 | benjamin.peterson | 2009-06-03 13:24:48 -0500 (Wed, 03 Jun 2009) | 1 line
remove shebang lines and __main__ sections
........
r73192 | benjamin.peterson | 2009-06-03 19:16:30 -0500 (Wed, 03 Jun 2009) | 4 lines
actually test something here
Thanks to Joe Amenta for noticing.y
........
r73231 | benjamin.peterson | 2009-06-04 13:38:50 -0500 (Thu, 04 Jun 2009) | 1 line
remove unused variable
........
r73244 | benjamin.peterson | 2009-06-05 08:39:25 -0500 (Fri, 05 Jun 2009) | 1 line
allow fixers to give different options in setUp
........
r73255 | benjamin.peterson | 2009-06-06 11:23:46 -0500 (Sat, 06 Jun 2009) | 1 line
fix the except fixer on one line suites #6222
........
r73256 | benjamin.peterson | 2009-06-06 11:27:40 -0500 (Sat, 06 Jun 2009) | 1 line
test one-line else and finally clauses
........
r73365 | benjamin.peterson | 2009-06-11 17:01:32 -0500 (Thu, 11 Jun 2009) | 1 line
normalize whitespace
........
................
2009-06-11 20:47:38 -03:00
|
|
|
self.refactor = support.get_refactorer(fixer_pkg, fix_list, options)
|
2008-03-19 02:04:44 -03:00
|
|
|
self.fixer_log = []
|
Merged revisions 61724-61725 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk
................
r61724 | martin.v.loewis | 2008-03-22 01:01:12 +0100 (Sa, 22 Mär 2008) | 49 lines
Merged revisions 61602-61723 via svnmerge from
svn+ssh://pythondev@svn.python.org/sandbox/trunk/2to3/lib2to3
........
r61626 | david.wolever | 2008-03-19 17:19:16 +0100 (Mi, 19 Mär 2008) | 1 line
Added fixer for implicit local imports. See #2414.
........
r61628 | david.wolever | 2008-03-19 17:57:43 +0100 (Mi, 19 Mär 2008) | 1 line
Added a class for tests which should not run if a particular import is found.
........
r61629 | collin.winter | 2008-03-19 17:58:19 +0100 (Mi, 19 Mär 2008) | 1 line
Two more relative import fixes in pgen2.
........
r61635 | david.wolever | 2008-03-19 20:16:03 +0100 (Mi, 19 Mär 2008) | 1 line
Fixed print fixer so it will do the Right Thing when it encounters __future__.print_function. 2to3 gets upset, though, so the tests have been commented out.
........
r61637 | david.wolever | 2008-03-19 21:37:17 +0100 (Mi, 19 Mär 2008) | 3 lines
Added a fixer for itertools imports (from itertools import imap, ifilterfalse --> from itertools import filterfalse)
........
r61645 | david.wolever | 2008-03-19 23:22:35 +0100 (Mi, 19 Mär 2008) | 1 line
SVN is happier when you add the files you create... -_-'
........
r61654 | david.wolever | 2008-03-20 01:09:56 +0100 (Do, 20 Mär 2008) | 1 line
Added an explicit sort order to fixers -- fixes problems like #2427
........
r61664 | david.wolever | 2008-03-20 04:32:40 +0100 (Do, 20 Mär 2008) | 3 lines
Fixes #2428 -- comments are no longer eatten by __future__ fixer.
........
r61673 | david.wolever | 2008-03-20 17:22:40 +0100 (Do, 20 Mär 2008) | 1 line
Added 2to3 node pretty-printer
........
r61679 | david.wolever | 2008-03-20 20:50:42 +0100 (Do, 20 Mär 2008) | 1 line
Made node printing a little bit prettier
........
r61723 | martin.v.loewis | 2008-03-22 00:59:27 +0100 (Sa, 22 Mär 2008) | 2 lines
Fix whitespace.
........
................
r61725 | martin.v.loewis | 2008-03-22 01:02:41 +0100 (Sa, 22 Mär 2008) | 2 lines
Install lib2to3.
................
2008-03-21 21:07:09 -03:00
|
|
|
self.filename = "<string>"
|
2008-03-19 02:04:44 -03:00
|
|
|
|
Merged revisions 67428 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk
................
r67428 | benjamin.peterson | 2008-11-28 16:12:14 -0600 (Fri, 28 Nov 2008) | 57 lines
Merged revisions 67384,67386-67387,67389-67390,67392,67399-67400,67403-67405,67426 via svnmerge from
svn+ssh://pythondev@svn.python.org/sandbox/trunk/2to3/lib2to3
........
r67384 | benjamin.peterson | 2008-11-25 16:13:31 -0600 (Tue, 25 Nov 2008) | 4 lines
don't duplicate calls to start_tree()
RefactoringTool.pre_order values now holds a list of the fixers while pre_order_mapping holds the dict.
........
r67386 | benjamin.peterson | 2008-11-25 16:44:52 -0600 (Tue, 25 Nov 2008) | 1 line
#4423 fix_imports was still replacing usage of a module if attributes were being used
........
r67387 | benjamin.peterson | 2008-11-25 16:47:54 -0600 (Tue, 25 Nov 2008) | 1 line
fix broken test
........
r67389 | benjamin.peterson | 2008-11-25 17:13:17 -0600 (Tue, 25 Nov 2008) | 1 line
remove compatibility code; we only cater to 2.5+
........
r67390 | benjamin.peterson | 2008-11-25 22:03:36 -0600 (Tue, 25 Nov 2008) | 1 line
fix #3994; the usage of changed imports was fixed in nested cases
........
r67392 | benjamin.peterson | 2008-11-26 11:11:40 -0600 (Wed, 26 Nov 2008) | 1 line
simpilfy and comment fix_imports
........
r67399 | benjamin.peterson | 2008-11-26 11:47:03 -0600 (Wed, 26 Nov 2008) | 1 line
remove more compatibility code
........
r67400 | benjamin.peterson | 2008-11-26 12:07:41 -0600 (Wed, 26 Nov 2008) | 1 line
set svn:ignore
........
r67403 | benjamin.peterson | 2008-11-26 13:11:11 -0600 (Wed, 26 Nov 2008) | 1 line
wrap import
........
r67404 | benjamin.peterson | 2008-11-26 13:29:49 -0600 (Wed, 26 Nov 2008) | 1 line
build the fix_imports pattern in compile_pattern, so MAPPING can be changed and reflected in the pattern
........
r67405 | benjamin.peterson | 2008-11-26 14:01:24 -0600 (Wed, 26 Nov 2008) | 1 line
stop ugly messages about runtime errors being from printed
........
r67426 | benjamin.peterson | 2008-11-28 16:01:40 -0600 (Fri, 28 Nov 2008) | 5 lines
don't replace a module name if it is in the middle of a attribute lookup
This fix also stops module names from being replaced if they are not in an attribute lookup.
........
................
2008-11-28 19:01:28 -04:00
|
|
|
for fixer in chain(self.refactor.pre_order,
|
|
|
|
self.refactor.post_order):
|
|
|
|
fixer.log = self.fixer_log
|
2008-03-19 02:04:44 -03:00
|
|
|
|
|
|
|
def _check(self, before, after):
|
|
|
|
before = support.reformat(before)
|
|
|
|
after = support.reformat(after)
|
Merged revisions 61724-61725 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk
................
r61724 | martin.v.loewis | 2008-03-22 01:01:12 +0100 (Sa, 22 Mär 2008) | 49 lines
Merged revisions 61602-61723 via svnmerge from
svn+ssh://pythondev@svn.python.org/sandbox/trunk/2to3/lib2to3
........
r61626 | david.wolever | 2008-03-19 17:19:16 +0100 (Mi, 19 Mär 2008) | 1 line
Added fixer for implicit local imports. See #2414.
........
r61628 | david.wolever | 2008-03-19 17:57:43 +0100 (Mi, 19 Mär 2008) | 1 line
Added a class for tests which should not run if a particular import is found.
........
r61629 | collin.winter | 2008-03-19 17:58:19 +0100 (Mi, 19 Mär 2008) | 1 line
Two more relative import fixes in pgen2.
........
r61635 | david.wolever | 2008-03-19 20:16:03 +0100 (Mi, 19 Mär 2008) | 1 line
Fixed print fixer so it will do the Right Thing when it encounters __future__.print_function. 2to3 gets upset, though, so the tests have been commented out.
........
r61637 | david.wolever | 2008-03-19 21:37:17 +0100 (Mi, 19 Mär 2008) | 3 lines
Added a fixer for itertools imports (from itertools import imap, ifilterfalse --> from itertools import filterfalse)
........
r61645 | david.wolever | 2008-03-19 23:22:35 +0100 (Mi, 19 Mär 2008) | 1 line
SVN is happier when you add the files you create... -_-'
........
r61654 | david.wolever | 2008-03-20 01:09:56 +0100 (Do, 20 Mär 2008) | 1 line
Added an explicit sort order to fixers -- fixes problems like #2427
........
r61664 | david.wolever | 2008-03-20 04:32:40 +0100 (Do, 20 Mär 2008) | 3 lines
Fixes #2428 -- comments are no longer eatten by __future__ fixer.
........
r61673 | david.wolever | 2008-03-20 17:22:40 +0100 (Do, 20 Mär 2008) | 1 line
Added 2to3 node pretty-printer
........
r61679 | david.wolever | 2008-03-20 20:50:42 +0100 (Do, 20 Mär 2008) | 1 line
Made node printing a little bit prettier
........
r61723 | martin.v.loewis | 2008-03-22 00:59:27 +0100 (Sa, 22 Mär 2008) | 2 lines
Fix whitespace.
........
................
r61725 | martin.v.loewis | 2008-03-22 01:02:41 +0100 (Sa, 22 Mär 2008) | 2 lines
Install lib2to3.
................
2008-03-21 21:07:09 -03:00
|
|
|
tree = self.refactor.refactor_string(before, self.filename)
|
2009-06-30 22:15:26 -03:00
|
|
|
self.assertEqual(after, str(tree))
|
2008-03-19 02:04:44 -03:00
|
|
|
return tree
|
|
|
|
|
|
|
|
def check(self, before, after, ignore_warnings=False):
|
|
|
|
tree = self._check(before, after)
|
2009-06-30 22:15:26 -03:00
|
|
|
self.assertTrue(tree.was_changed)
|
2008-03-19 02:04:44 -03:00
|
|
|
if not ignore_warnings:
|
2009-06-30 22:15:26 -03:00
|
|
|
self.assertEqual(self.fixer_log, [])
|
2008-03-19 02:04:44 -03:00
|
|
|
|
|
|
|
def warns(self, before, after, message, unchanged=False):
|
|
|
|
tree = self._check(before, after)
|
2009-06-30 22:15:26 -03:00
|
|
|
self.assertTrue(message in "".join(self.fixer_log))
|
2008-03-19 02:04:44 -03:00
|
|
|
if not unchanged:
|
2009-06-30 22:15:26 -03:00
|
|
|
self.assertTrue(tree.was_changed)
|
2008-03-19 02:04:44 -03:00
|
|
|
|
|
|
|
def warns_unchanged(self, before, message):
|
|
|
|
self.warns(before, before, message, unchanged=True)
|
|
|
|
|
|
|
|
def unchanged(self, before, ignore_warnings=False):
|
|
|
|
self._check(before, before)
|
|
|
|
if not ignore_warnings:
|
2009-06-30 22:15:26 -03:00
|
|
|
self.assertEqual(self.fixer_log, [])
|
2008-03-19 02:04:44 -03:00
|
|
|
|
Merged revisions 61724-61725 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk
................
r61724 | martin.v.loewis | 2008-03-22 01:01:12 +0100 (Sa, 22 Mär 2008) | 49 lines
Merged revisions 61602-61723 via svnmerge from
svn+ssh://pythondev@svn.python.org/sandbox/trunk/2to3/lib2to3
........
r61626 | david.wolever | 2008-03-19 17:19:16 +0100 (Mi, 19 Mär 2008) | 1 line
Added fixer for implicit local imports. See #2414.
........
r61628 | david.wolever | 2008-03-19 17:57:43 +0100 (Mi, 19 Mär 2008) | 1 line
Added a class for tests which should not run if a particular import is found.
........
r61629 | collin.winter | 2008-03-19 17:58:19 +0100 (Mi, 19 Mär 2008) | 1 line
Two more relative import fixes in pgen2.
........
r61635 | david.wolever | 2008-03-19 20:16:03 +0100 (Mi, 19 Mär 2008) | 1 line
Fixed print fixer so it will do the Right Thing when it encounters __future__.print_function. 2to3 gets upset, though, so the tests have been commented out.
........
r61637 | david.wolever | 2008-03-19 21:37:17 +0100 (Mi, 19 Mär 2008) | 3 lines
Added a fixer for itertools imports (from itertools import imap, ifilterfalse --> from itertools import filterfalse)
........
r61645 | david.wolever | 2008-03-19 23:22:35 +0100 (Mi, 19 Mär 2008) | 1 line
SVN is happier when you add the files you create... -_-'
........
r61654 | david.wolever | 2008-03-20 01:09:56 +0100 (Do, 20 Mär 2008) | 1 line
Added an explicit sort order to fixers -- fixes problems like #2427
........
r61664 | david.wolever | 2008-03-20 04:32:40 +0100 (Do, 20 Mär 2008) | 3 lines
Fixes #2428 -- comments are no longer eatten by __future__ fixer.
........
r61673 | david.wolever | 2008-03-20 17:22:40 +0100 (Do, 20 Mär 2008) | 1 line
Added 2to3 node pretty-printer
........
r61679 | david.wolever | 2008-03-20 20:50:42 +0100 (Do, 20 Mär 2008) | 1 line
Made node printing a little bit prettier
........
r61723 | martin.v.loewis | 2008-03-22 00:59:27 +0100 (Sa, 22 Mär 2008) | 2 lines
Fix whitespace.
........
................
r61725 | martin.v.loewis | 2008-03-22 01:02:41 +0100 (Sa, 22 Mär 2008) | 2 lines
Install lib2to3.
................
2008-03-21 21:07:09 -03:00
|
|
|
def assert_runs_after(self, *names):
|
2008-09-02 23:27:16 -03:00
|
|
|
fixes = [self.fixer]
|
|
|
|
fixes.extend(names)
|
2009-07-21 09:55:57 -03:00
|
|
|
r = support.get_refactorer("lib2to3", fixes)
|
Merged revisions 61724-61725 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk
................
r61724 | martin.v.loewis | 2008-03-22 01:01:12 +0100 (Sa, 22 Mär 2008) | 49 lines
Merged revisions 61602-61723 via svnmerge from
svn+ssh://pythondev@svn.python.org/sandbox/trunk/2to3/lib2to3
........
r61626 | david.wolever | 2008-03-19 17:19:16 +0100 (Mi, 19 Mär 2008) | 1 line
Added fixer for implicit local imports. See #2414.
........
r61628 | david.wolever | 2008-03-19 17:57:43 +0100 (Mi, 19 Mär 2008) | 1 line
Added a class for tests which should not run if a particular import is found.
........
r61629 | collin.winter | 2008-03-19 17:58:19 +0100 (Mi, 19 Mär 2008) | 1 line
Two more relative import fixes in pgen2.
........
r61635 | david.wolever | 2008-03-19 20:16:03 +0100 (Mi, 19 Mär 2008) | 1 line
Fixed print fixer so it will do the Right Thing when it encounters __future__.print_function. 2to3 gets upset, though, so the tests have been commented out.
........
r61637 | david.wolever | 2008-03-19 21:37:17 +0100 (Mi, 19 Mär 2008) | 3 lines
Added a fixer for itertools imports (from itertools import imap, ifilterfalse --> from itertools import filterfalse)
........
r61645 | david.wolever | 2008-03-19 23:22:35 +0100 (Mi, 19 Mär 2008) | 1 line
SVN is happier when you add the files you create... -_-'
........
r61654 | david.wolever | 2008-03-20 01:09:56 +0100 (Do, 20 Mär 2008) | 1 line
Added an explicit sort order to fixers -- fixes problems like #2427
........
r61664 | david.wolever | 2008-03-20 04:32:40 +0100 (Do, 20 Mär 2008) | 3 lines
Fixes #2428 -- comments are no longer eatten by __future__ fixer.
........
r61673 | david.wolever | 2008-03-20 17:22:40 +0100 (Do, 20 Mär 2008) | 1 line
Added 2to3 node pretty-printer
........
r61679 | david.wolever | 2008-03-20 20:50:42 +0100 (Do, 20 Mär 2008) | 1 line
Made node printing a little bit prettier
........
r61723 | martin.v.loewis | 2008-03-22 00:59:27 +0100 (Sa, 22 Mär 2008) | 2 lines
Fix whitespace.
........
................
r61725 | martin.v.loewis | 2008-03-22 01:02:41 +0100 (Sa, 22 Mär 2008) | 2 lines
Install lib2to3.
................
2008-03-21 21:07:09 -03:00
|
|
|
(pre, post) = r.get_fixers()
|
|
|
|
n = "fix_" + self.fixer
|
|
|
|
if post and post[-1].__class__.__module__.endswith(n):
|
|
|
|
# We're the last fixer to run
|
|
|
|
return
|
|
|
|
if pre and pre[-1].__class__.__module__.endswith(n) and not post:
|
|
|
|
# We're the last in pre and post is empty
|
|
|
|
return
|
|
|
|
self.fail("Fixer run order (%s) is incorrect; %s should be last."\
|
|
|
|
%(", ".join([x.__class__.__module__ for x in (pre+post)]), n))
|
2008-03-19 02:04:44 -03:00
|
|
|
|
|
|
|
class Test_ne(FixerTestCase):
|
|
|
|
fixer = "ne"
|
|
|
|
|
|
|
|
def test_basic(self):
|
|
|
|
b = """if x <> y:
|
|
|
|
pass"""
|
|
|
|
|
|
|
|
a = """if x != y:
|
|
|
|
pass"""
|
|
|
|
self.check(b, a)
|
|
|
|
|
|
|
|
def test_no_spaces(self):
|
|
|
|
b = """if x<>y:
|
|
|
|
pass"""
|
|
|
|
|
|
|
|
a = """if x!=y:
|
|
|
|
pass"""
|
|
|
|
self.check(b, a)
|
|
|
|
|
|
|
|
def test_chained(self):
|
|
|
|
b = """if x<>y<>z:
|
|
|
|
pass"""
|
|
|
|
|
|
|
|
a = """if x!=y!=z:
|
|
|
|
pass"""
|
|
|
|
self.check(b, a)
|
|
|
|
|
|
|
|
class Test_has_key(FixerTestCase):
|
|
|
|
fixer = "has_key"
|
|
|
|
|
|
|
|
def test_1(self):
|
|
|
|
b = """x = d.has_key("x") or d.has_key("y")"""
|
|
|
|
a = """x = "x" in d or "y" in d"""
|
|
|
|
self.check(b, a)
|
|
|
|
|
|
|
|
def test_2(self):
|
|
|
|
b = """x = a.b.c.d.has_key("x") ** 3"""
|
|
|
|
a = """x = ("x" in a.b.c.d) ** 3"""
|
|
|
|
self.check(b, a)
|
|
|
|
|
|
|
|
def test_3(self):
|
|
|
|
b = """x = a.b.has_key(1 + 2).__repr__()"""
|
|
|
|
a = """x = (1 + 2 in a.b).__repr__()"""
|
|
|
|
self.check(b, a)
|
|
|
|
|
|
|
|
def test_4(self):
|
|
|
|
b = """x = a.b.has_key(1 + 2).__repr__() ** -3 ** 4"""
|
|
|
|
a = """x = (1 + 2 in a.b).__repr__() ** -3 ** 4"""
|
|
|
|
self.check(b, a)
|
|
|
|
|
|
|
|
def test_5(self):
|
|
|
|
b = """x = a.has_key(f or g)"""
|
|
|
|
a = """x = (f or g) in a"""
|
|
|
|
self.check(b, a)
|
|
|
|
|
|
|
|
def test_6(self):
|
|
|
|
b = """x = a + b.has_key(c)"""
|
|
|
|
a = """x = a + (c in b)"""
|
|
|
|
self.check(b, a)
|
|
|
|
|
|
|
|
def test_7(self):
|
|
|
|
b = """x = a.has_key(lambda: 12)"""
|
|
|
|
a = """x = (lambda: 12) in a"""
|
|
|
|
self.check(b, a)
|
|
|
|
|
|
|
|
def test_8(self):
|
|
|
|
b = """x = a.has_key(a for a in b)"""
|
|
|
|
a = """x = (a for a in b) in a"""
|
|
|
|
self.check(b, a)
|
|
|
|
|
|
|
|
def test_9(self):
|
|
|
|
b = """if not a.has_key(b): pass"""
|
|
|
|
a = """if b not in a: pass"""
|
|
|
|
self.check(b, a)
|
|
|
|
|
|
|
|
def test_10(self):
|
|
|
|
b = """if not a.has_key(b).__repr__(): pass"""
|
|
|
|
a = """if not (b in a).__repr__(): pass"""
|
|
|
|
self.check(b, a)
|
|
|
|
|
|
|
|
def test_11(self):
|
|
|
|
b = """if not a.has_key(b) ** 2: pass"""
|
|
|
|
a = """if not (b in a) ** 2: pass"""
|
|
|
|
self.check(b, a)
|
|
|
|
|
|
|
|
class Test_apply(FixerTestCase):
|
|
|
|
fixer = "apply"
|
|
|
|
|
|
|
|
def test_1(self):
|
|
|
|
b = """x = apply(f, g + h)"""
|
|
|
|
a = """x = f(*g + h)"""
|
|
|
|
self.check(b, a)
|
|
|
|
|
|
|
|
def test_2(self):
|
|
|
|
b = """y = apply(f, g, h)"""
|
|
|
|
a = """y = f(*g, **h)"""
|
|
|
|
self.check(b, a)
|
|
|
|
|
|
|
|
def test_3(self):
|
|
|
|
b = """z = apply(fs[0], g or h, h or g)"""
|
|
|
|
a = """z = fs[0](*g or h, **h or g)"""
|
|
|
|
self.check(b, a)
|
|
|
|
|
|
|
|
def test_4(self):
|
|
|
|
b = """apply(f, (x, y) + t)"""
|
|
|
|
a = """f(*(x, y) + t)"""
|
|
|
|
self.check(b, a)
|
|
|
|
|
|
|
|
def test_5(self):
|
|
|
|
b = """apply(f, args,)"""
|
|
|
|
a = """f(*args)"""
|
|
|
|
self.check(b, a)
|
|
|
|
|
|
|
|
def test_6(self):
|
|
|
|
b = """apply(f, args, kwds,)"""
|
|
|
|
a = """f(*args, **kwds)"""
|
|
|
|
self.check(b, a)
|
|
|
|
|
|
|
|
# Test that complex functions are parenthesized
|
|
|
|
|
|
|
|
def test_complex_1(self):
|
|
|
|
b = """x = apply(f+g, args)"""
|
|
|
|
a = """x = (f+g)(*args)"""
|
|
|
|
self.check(b, a)
|
|
|
|
|
|
|
|
def test_complex_2(self):
|
|
|
|
b = """x = apply(f*g, args)"""
|
|
|
|
a = """x = (f*g)(*args)"""
|
|
|
|
self.check(b, a)
|
|
|
|
|
|
|
|
def test_complex_3(self):
|
|
|
|
b = """x = apply(f**g, args)"""
|
|
|
|
a = """x = (f**g)(*args)"""
|
|
|
|
self.check(b, a)
|
|
|
|
|
|
|
|
# But dotted names etc. not
|
|
|
|
|
|
|
|
def test_dotted_name(self):
|
|
|
|
b = """x = apply(f.g, args)"""
|
|
|
|
a = """x = f.g(*args)"""
|
|
|
|
self.check(b, a)
|
|
|
|
|
|
|
|
def test_subscript(self):
|
|
|
|
b = """x = apply(f[x], args)"""
|
|
|
|
a = """x = f[x](*args)"""
|
|
|
|
self.check(b, a)
|
|
|
|
|
|
|
|
def test_call(self):
|
|
|
|
b = """x = apply(f(), args)"""
|
|
|
|
a = """x = f()(*args)"""
|
|
|
|
self.check(b, a)
|
|
|
|
|
|
|
|
# Extreme case
|
|
|
|
def test_extreme(self):
|
|
|
|
b = """x = apply(a.b.c.d.e.f, args, kwds)"""
|
|
|
|
a = """x = a.b.c.d.e.f(*args, **kwds)"""
|
|
|
|
self.check(b, a)
|
|
|
|
|
|
|
|
# XXX Comments in weird places still get lost
|
|
|
|
def test_weird_comments(self):
|
|
|
|
b = """apply( # foo
|
|
|
|
f, # bar
|
|
|
|
args)"""
|
|
|
|
a = """f(*args)"""
|
|
|
|
self.check(b, a)
|
|
|
|
|
|
|
|
# These should *not* be touched
|
|
|
|
|
|
|
|
def test_unchanged_1(self):
|
|
|
|
s = """apply()"""
|
|
|
|
self.unchanged(s)
|
|
|
|
|
|
|
|
def test_unchanged_2(self):
|
|
|
|
s = """apply(f)"""
|
|
|
|
self.unchanged(s)
|
|
|
|
|
|
|
|
def test_unchanged_3(self):
|
|
|
|
s = """apply(f,)"""
|
|
|
|
self.unchanged(s)
|
|
|
|
|
|
|
|
def test_unchanged_4(self):
|
|
|
|
s = """apply(f, args, kwds, extras)"""
|
|
|
|
self.unchanged(s)
|
|
|
|
|
|
|
|
def test_unchanged_5(self):
|
|
|
|
s = """apply(f, *args, **kwds)"""
|
|
|
|
self.unchanged(s)
|
|
|
|
|
|
|
|
def test_unchanged_6(self):
|
|
|
|
s = """apply(f, *args)"""
|
|
|
|
self.unchanged(s)
|
|
|
|
|
|
|
|
def test_unchanged_7(self):
|
|
|
|
s = """apply(func=f, args=args, kwds=kwds)"""
|
|
|
|
self.unchanged(s)
|
|
|
|
|
|
|
|
def test_unchanged_8(self):
|
|
|
|
s = """apply(f, args=args, kwds=kwds)"""
|
|
|
|
self.unchanged(s)
|
|
|
|
|
|
|
|
def test_unchanged_9(self):
|
|
|
|
s = """apply(f, args, kwds=kwds)"""
|
|
|
|
self.unchanged(s)
|
|
|
|
|
|
|
|
def test_space_1(self):
|
|
|
|
a = """apply( f, args, kwds)"""
|
|
|
|
b = """f(*args, **kwds)"""
|
|
|
|
self.check(a, b)
|
|
|
|
|
|
|
|
def test_space_2(self):
|
|
|
|
a = """apply( f ,args,kwds )"""
|
|
|
|
b = """f(*args, **kwds)"""
|
|
|
|
self.check(a, b)
|
|
|
|
|
|
|
|
class Test_intern(FixerTestCase):
|
|
|
|
fixer = "intern"
|
|
|
|
|
|
|
|
def test_prefix_preservation(self):
|
|
|
|
b = """x = intern( a )"""
|
Merged revisions 67806 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk
................
r67806 | benjamin.peterson | 2008-12-15 21:35:28 -0600 (Mon, 15 Dec 2008) | 111 lines
Merged revisions 67427,67431,67433,67435,67630,67652,67656-67657,67674-67675,67678-67679,67705-67706,67716,67723,67765-67771,67774,67776,67778 via svnmerge from
svn+ssh://pythondev@svn.python.org/sandbox/trunk/2to3/lib2to3
........
r67427 | benjamin.peterson | 2008-11-28 16:07:41 -0600 (Fri, 28 Nov 2008) | 1 line
fix spelling in comment
........
r67431 | benjamin.peterson | 2008-11-28 17:14:08 -0600 (Fri, 28 Nov 2008) | 1 line
add a scripts directory; move things to it
........
r67433 | benjamin.peterson | 2008-11-28 17:18:48 -0600 (Fri, 28 Nov 2008) | 1 line
run svneol.py
........
r67435 | benjamin.peterson | 2008-11-28 17:25:03 -0600 (Fri, 28 Nov 2008) | 1 line
rename pre/post_order_mapping to pre/post_order_heads
........
r67630 | alexandre.vassalotti | 2008-12-06 21:51:56 -0600 (Sat, 06 Dec 2008) | 2 lines
Fix typo in the urllib2.HTTPDigestAuthHandler fixer.
........
r67652 | armin.ronacher | 2008-12-07 15:39:43 -0600 (Sun, 07 Dec 2008) | 5 lines
Added a fixer that cleans up a tuple argument to isinstance after the tokens
in it were fixed. This is mainly used to remove double occurrences of
tokens as a leftover of the long -> int / unicode -> str conversion.
........
r67656 | armin.ronacher | 2008-12-07 16:54:16 -0600 (Sun, 07 Dec 2008) | 3 lines
Added missing copyright fo 2to3 fix_isinstance.
........
r67657 | armin.ronacher | 2008-12-07 18:29:35 -0600 (Sun, 07 Dec 2008) | 3 lines
2to3: intern and reduce fixes now add the imports if missing. Because that is a common task the fixer_util module now has a function "touch_import" that adds imports if missing.
........
r67674 | benjamin.peterson | 2008-12-08 19:58:11 -0600 (Mon, 08 Dec 2008) | 1 line
copy permission bits when making backup files #4602
........
r67675 | benjamin.peterson | 2008-12-08 19:59:11 -0600 (Mon, 08 Dec 2008) | 1 line
add forgotten import
........
r67678 | benjamin.peterson | 2008-12-08 20:08:30 -0600 (Mon, 08 Dec 2008) | 1 line
fix #4602 for real
........
r67679 | armin.ronacher | 2008-12-09 00:54:03 -0600 (Tue, 09 Dec 2008) | 3 lines
Removed redudant code from the 2to3 long fixer. This fixes #4590.
........
r67705 | benjamin.peterson | 2008-12-11 13:04:08 -0600 (Thu, 11 Dec 2008) | 1 line
put trailers after a range call after the list()
........
r67706 | benjamin.peterson | 2008-12-11 13:17:57 -0600 (Thu, 11 Dec 2008) | 1 line
add html related modules to the fix_imports mapping
........
r67716 | benjamin.peterson | 2008-12-11 22:16:47 -0600 (Thu, 11 Dec 2008) | 1 line
consolidate tests
........
r67723 | benjamin.peterson | 2008-12-12 19:49:31 -0600 (Fri, 12 Dec 2008) | 1 line
fix name
........
r67765 | benjamin.peterson | 2008-12-14 14:05:05 -0600 (Sun, 14 Dec 2008) | 1 line
run fix_isinstance after fix_long and fix_unicode
........
r67766 | benjamin.peterson | 2008-12-14 14:13:05 -0600 (Sun, 14 Dec 2008) | 1 line
use run_order instead of order
........
r67767 | benjamin.peterson | 2008-12-14 14:28:12 -0600 (Sun, 14 Dec 2008) | 1 line
don't retain parenthesis if there is only one item left
........
r67768 | benjamin.peterson | 2008-12-14 14:32:30 -0600 (Sun, 14 Dec 2008) | 1 line
use insert_child()
........
r67769 | benjamin.peterson | 2008-12-14 14:59:10 -0600 (Sun, 14 Dec 2008) | 1 line
parenthesize doesn't belong in pygram or FixerBase
........
r67770 | alexandre.vassalotti | 2008-12-14 15:15:36 -0600 (Sun, 14 Dec 2008) | 2 lines
Fix typo: html.paser -> html.parser.
........
r67771 | benjamin.peterson | 2008-12-14 15:22:09 -0600 (Sun, 14 Dec 2008) | 1 line
altering .children needs to call changed()
........
r67774 | benjamin.peterson | 2008-12-14 15:55:38 -0600 (Sun, 14 Dec 2008) | 1 line
employ an evil hack to fix multiple names in the same import statement
........
r67776 | benjamin.peterson | 2008-12-14 16:22:38 -0600 (Sun, 14 Dec 2008) | 1 line
make a common mixin class for Test_imports and friends
........
r67778 | alexandre.vassalotti | 2008-12-14 17:48:20 -0600 (Sun, 14 Dec 2008) | 2 lines
Make fix_imports refactor multiple imports as.
........
................
2008-12-15 23:57:54 -04:00
|
|
|
a = """import sys\nx = sys.intern( a )"""
|
2008-03-19 02:04:44 -03:00
|
|
|
self.check(b, a)
|
|
|
|
|
|
|
|
b = """y = intern("b" # test
|
|
|
|
)"""
|
Merged revisions 67806 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk
................
r67806 | benjamin.peterson | 2008-12-15 21:35:28 -0600 (Mon, 15 Dec 2008) | 111 lines
Merged revisions 67427,67431,67433,67435,67630,67652,67656-67657,67674-67675,67678-67679,67705-67706,67716,67723,67765-67771,67774,67776,67778 via svnmerge from
svn+ssh://pythondev@svn.python.org/sandbox/trunk/2to3/lib2to3
........
r67427 | benjamin.peterson | 2008-11-28 16:07:41 -0600 (Fri, 28 Nov 2008) | 1 line
fix spelling in comment
........
r67431 | benjamin.peterson | 2008-11-28 17:14:08 -0600 (Fri, 28 Nov 2008) | 1 line
add a scripts directory; move things to it
........
r67433 | benjamin.peterson | 2008-11-28 17:18:48 -0600 (Fri, 28 Nov 2008) | 1 line
run svneol.py
........
r67435 | benjamin.peterson | 2008-11-28 17:25:03 -0600 (Fri, 28 Nov 2008) | 1 line
rename pre/post_order_mapping to pre/post_order_heads
........
r67630 | alexandre.vassalotti | 2008-12-06 21:51:56 -0600 (Sat, 06 Dec 2008) | 2 lines
Fix typo in the urllib2.HTTPDigestAuthHandler fixer.
........
r67652 | armin.ronacher | 2008-12-07 15:39:43 -0600 (Sun, 07 Dec 2008) | 5 lines
Added a fixer that cleans up a tuple argument to isinstance after the tokens
in it were fixed. This is mainly used to remove double occurrences of
tokens as a leftover of the long -> int / unicode -> str conversion.
........
r67656 | armin.ronacher | 2008-12-07 16:54:16 -0600 (Sun, 07 Dec 2008) | 3 lines
Added missing copyright fo 2to3 fix_isinstance.
........
r67657 | armin.ronacher | 2008-12-07 18:29:35 -0600 (Sun, 07 Dec 2008) | 3 lines
2to3: intern and reduce fixes now add the imports if missing. Because that is a common task the fixer_util module now has a function "touch_import" that adds imports if missing.
........
r67674 | benjamin.peterson | 2008-12-08 19:58:11 -0600 (Mon, 08 Dec 2008) | 1 line
copy permission bits when making backup files #4602
........
r67675 | benjamin.peterson | 2008-12-08 19:59:11 -0600 (Mon, 08 Dec 2008) | 1 line
add forgotten import
........
r67678 | benjamin.peterson | 2008-12-08 20:08:30 -0600 (Mon, 08 Dec 2008) | 1 line
fix #4602 for real
........
r67679 | armin.ronacher | 2008-12-09 00:54:03 -0600 (Tue, 09 Dec 2008) | 3 lines
Removed redudant code from the 2to3 long fixer. This fixes #4590.
........
r67705 | benjamin.peterson | 2008-12-11 13:04:08 -0600 (Thu, 11 Dec 2008) | 1 line
put trailers after a range call after the list()
........
r67706 | benjamin.peterson | 2008-12-11 13:17:57 -0600 (Thu, 11 Dec 2008) | 1 line
add html related modules to the fix_imports mapping
........
r67716 | benjamin.peterson | 2008-12-11 22:16:47 -0600 (Thu, 11 Dec 2008) | 1 line
consolidate tests
........
r67723 | benjamin.peterson | 2008-12-12 19:49:31 -0600 (Fri, 12 Dec 2008) | 1 line
fix name
........
r67765 | benjamin.peterson | 2008-12-14 14:05:05 -0600 (Sun, 14 Dec 2008) | 1 line
run fix_isinstance after fix_long and fix_unicode
........
r67766 | benjamin.peterson | 2008-12-14 14:13:05 -0600 (Sun, 14 Dec 2008) | 1 line
use run_order instead of order
........
r67767 | benjamin.peterson | 2008-12-14 14:28:12 -0600 (Sun, 14 Dec 2008) | 1 line
don't retain parenthesis if there is only one item left
........
r67768 | benjamin.peterson | 2008-12-14 14:32:30 -0600 (Sun, 14 Dec 2008) | 1 line
use insert_child()
........
r67769 | benjamin.peterson | 2008-12-14 14:59:10 -0600 (Sun, 14 Dec 2008) | 1 line
parenthesize doesn't belong in pygram or FixerBase
........
r67770 | alexandre.vassalotti | 2008-12-14 15:15:36 -0600 (Sun, 14 Dec 2008) | 2 lines
Fix typo: html.paser -> html.parser.
........
r67771 | benjamin.peterson | 2008-12-14 15:22:09 -0600 (Sun, 14 Dec 2008) | 1 line
altering .children needs to call changed()
........
r67774 | benjamin.peterson | 2008-12-14 15:55:38 -0600 (Sun, 14 Dec 2008) | 1 line
employ an evil hack to fix multiple names in the same import statement
........
r67776 | benjamin.peterson | 2008-12-14 16:22:38 -0600 (Sun, 14 Dec 2008) | 1 line
make a common mixin class for Test_imports and friends
........
r67778 | alexandre.vassalotti | 2008-12-14 17:48:20 -0600 (Sun, 14 Dec 2008) | 2 lines
Make fix_imports refactor multiple imports as.
........
................
2008-12-15 23:57:54 -04:00
|
|
|
a = """import sys\ny = sys.intern("b" # test
|
2008-03-19 02:04:44 -03:00
|
|
|
)"""
|
|
|
|
self.check(b, a)
|
|
|
|
|
|
|
|
b = """z = intern(a+b+c.d, )"""
|
Merged revisions 67806 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk
................
r67806 | benjamin.peterson | 2008-12-15 21:35:28 -0600 (Mon, 15 Dec 2008) | 111 lines
Merged revisions 67427,67431,67433,67435,67630,67652,67656-67657,67674-67675,67678-67679,67705-67706,67716,67723,67765-67771,67774,67776,67778 via svnmerge from
svn+ssh://pythondev@svn.python.org/sandbox/trunk/2to3/lib2to3
........
r67427 | benjamin.peterson | 2008-11-28 16:07:41 -0600 (Fri, 28 Nov 2008) | 1 line
fix spelling in comment
........
r67431 | benjamin.peterson | 2008-11-28 17:14:08 -0600 (Fri, 28 Nov 2008) | 1 line
add a scripts directory; move things to it
........
r67433 | benjamin.peterson | 2008-11-28 17:18:48 -0600 (Fri, 28 Nov 2008) | 1 line
run svneol.py
........
r67435 | benjamin.peterson | 2008-11-28 17:25:03 -0600 (Fri, 28 Nov 2008) | 1 line
rename pre/post_order_mapping to pre/post_order_heads
........
r67630 | alexandre.vassalotti | 2008-12-06 21:51:56 -0600 (Sat, 06 Dec 2008) | 2 lines
Fix typo in the urllib2.HTTPDigestAuthHandler fixer.
........
r67652 | armin.ronacher | 2008-12-07 15:39:43 -0600 (Sun, 07 Dec 2008) | 5 lines
Added a fixer that cleans up a tuple argument to isinstance after the tokens
in it were fixed. This is mainly used to remove double occurrences of
tokens as a leftover of the long -> int / unicode -> str conversion.
........
r67656 | armin.ronacher | 2008-12-07 16:54:16 -0600 (Sun, 07 Dec 2008) | 3 lines
Added missing copyright fo 2to3 fix_isinstance.
........
r67657 | armin.ronacher | 2008-12-07 18:29:35 -0600 (Sun, 07 Dec 2008) | 3 lines
2to3: intern and reduce fixes now add the imports if missing. Because that is a common task the fixer_util module now has a function "touch_import" that adds imports if missing.
........
r67674 | benjamin.peterson | 2008-12-08 19:58:11 -0600 (Mon, 08 Dec 2008) | 1 line
copy permission bits when making backup files #4602
........
r67675 | benjamin.peterson | 2008-12-08 19:59:11 -0600 (Mon, 08 Dec 2008) | 1 line
add forgotten import
........
r67678 | benjamin.peterson | 2008-12-08 20:08:30 -0600 (Mon, 08 Dec 2008) | 1 line
fix #4602 for real
........
r67679 | armin.ronacher | 2008-12-09 00:54:03 -0600 (Tue, 09 Dec 2008) | 3 lines
Removed redudant code from the 2to3 long fixer. This fixes #4590.
........
r67705 | benjamin.peterson | 2008-12-11 13:04:08 -0600 (Thu, 11 Dec 2008) | 1 line
put trailers after a range call after the list()
........
r67706 | benjamin.peterson | 2008-12-11 13:17:57 -0600 (Thu, 11 Dec 2008) | 1 line
add html related modules to the fix_imports mapping
........
r67716 | benjamin.peterson | 2008-12-11 22:16:47 -0600 (Thu, 11 Dec 2008) | 1 line
consolidate tests
........
r67723 | benjamin.peterson | 2008-12-12 19:49:31 -0600 (Fri, 12 Dec 2008) | 1 line
fix name
........
r67765 | benjamin.peterson | 2008-12-14 14:05:05 -0600 (Sun, 14 Dec 2008) | 1 line
run fix_isinstance after fix_long and fix_unicode
........
r67766 | benjamin.peterson | 2008-12-14 14:13:05 -0600 (Sun, 14 Dec 2008) | 1 line
use run_order instead of order
........
r67767 | benjamin.peterson | 2008-12-14 14:28:12 -0600 (Sun, 14 Dec 2008) | 1 line
don't retain parenthesis if there is only one item left
........
r67768 | benjamin.peterson | 2008-12-14 14:32:30 -0600 (Sun, 14 Dec 2008) | 1 line
use insert_child()
........
r67769 | benjamin.peterson | 2008-12-14 14:59:10 -0600 (Sun, 14 Dec 2008) | 1 line
parenthesize doesn't belong in pygram or FixerBase
........
r67770 | alexandre.vassalotti | 2008-12-14 15:15:36 -0600 (Sun, 14 Dec 2008) | 2 lines
Fix typo: html.paser -> html.parser.
........
r67771 | benjamin.peterson | 2008-12-14 15:22:09 -0600 (Sun, 14 Dec 2008) | 1 line
altering .children needs to call changed()
........
r67774 | benjamin.peterson | 2008-12-14 15:55:38 -0600 (Sun, 14 Dec 2008) | 1 line
employ an evil hack to fix multiple names in the same import statement
........
r67776 | benjamin.peterson | 2008-12-14 16:22:38 -0600 (Sun, 14 Dec 2008) | 1 line
make a common mixin class for Test_imports and friends
........
r67778 | alexandre.vassalotti | 2008-12-14 17:48:20 -0600 (Sun, 14 Dec 2008) | 2 lines
Make fix_imports refactor multiple imports as.
........
................
2008-12-15 23:57:54 -04:00
|
|
|
a = """import sys\nz = sys.intern(a+b+c.d, )"""
|
2008-03-19 02:04:44 -03:00
|
|
|
self.check(b, a)
|
|
|
|
|
|
|
|
def test(self):
|
|
|
|
b = """x = intern(a)"""
|
Merged revisions 67806 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk
................
r67806 | benjamin.peterson | 2008-12-15 21:35:28 -0600 (Mon, 15 Dec 2008) | 111 lines
Merged revisions 67427,67431,67433,67435,67630,67652,67656-67657,67674-67675,67678-67679,67705-67706,67716,67723,67765-67771,67774,67776,67778 via svnmerge from
svn+ssh://pythondev@svn.python.org/sandbox/trunk/2to3/lib2to3
........
r67427 | benjamin.peterson | 2008-11-28 16:07:41 -0600 (Fri, 28 Nov 2008) | 1 line
fix spelling in comment
........
r67431 | benjamin.peterson | 2008-11-28 17:14:08 -0600 (Fri, 28 Nov 2008) | 1 line
add a scripts directory; move things to it
........
r67433 | benjamin.peterson | 2008-11-28 17:18:48 -0600 (Fri, 28 Nov 2008) | 1 line
run svneol.py
........
r67435 | benjamin.peterson | 2008-11-28 17:25:03 -0600 (Fri, 28 Nov 2008) | 1 line
rename pre/post_order_mapping to pre/post_order_heads
........
r67630 | alexandre.vassalotti | 2008-12-06 21:51:56 -0600 (Sat, 06 Dec 2008) | 2 lines
Fix typo in the urllib2.HTTPDigestAuthHandler fixer.
........
r67652 | armin.ronacher | 2008-12-07 15:39:43 -0600 (Sun, 07 Dec 2008) | 5 lines
Added a fixer that cleans up a tuple argument to isinstance after the tokens
in it were fixed. This is mainly used to remove double occurrences of
tokens as a leftover of the long -> int / unicode -> str conversion.
........
r67656 | armin.ronacher | 2008-12-07 16:54:16 -0600 (Sun, 07 Dec 2008) | 3 lines
Added missing copyright fo 2to3 fix_isinstance.
........
r67657 | armin.ronacher | 2008-12-07 18:29:35 -0600 (Sun, 07 Dec 2008) | 3 lines
2to3: intern and reduce fixes now add the imports if missing. Because that is a common task the fixer_util module now has a function "touch_import" that adds imports if missing.
........
r67674 | benjamin.peterson | 2008-12-08 19:58:11 -0600 (Mon, 08 Dec 2008) | 1 line
copy permission bits when making backup files #4602
........
r67675 | benjamin.peterson | 2008-12-08 19:59:11 -0600 (Mon, 08 Dec 2008) | 1 line
add forgotten import
........
r67678 | benjamin.peterson | 2008-12-08 20:08:30 -0600 (Mon, 08 Dec 2008) | 1 line
fix #4602 for real
........
r67679 | armin.ronacher | 2008-12-09 00:54:03 -0600 (Tue, 09 Dec 2008) | 3 lines
Removed redudant code from the 2to3 long fixer. This fixes #4590.
........
r67705 | benjamin.peterson | 2008-12-11 13:04:08 -0600 (Thu, 11 Dec 2008) | 1 line
put trailers after a range call after the list()
........
r67706 | benjamin.peterson | 2008-12-11 13:17:57 -0600 (Thu, 11 Dec 2008) | 1 line
add html related modules to the fix_imports mapping
........
r67716 | benjamin.peterson | 2008-12-11 22:16:47 -0600 (Thu, 11 Dec 2008) | 1 line
consolidate tests
........
r67723 | benjamin.peterson | 2008-12-12 19:49:31 -0600 (Fri, 12 Dec 2008) | 1 line
fix name
........
r67765 | benjamin.peterson | 2008-12-14 14:05:05 -0600 (Sun, 14 Dec 2008) | 1 line
run fix_isinstance after fix_long and fix_unicode
........
r67766 | benjamin.peterson | 2008-12-14 14:13:05 -0600 (Sun, 14 Dec 2008) | 1 line
use run_order instead of order
........
r67767 | benjamin.peterson | 2008-12-14 14:28:12 -0600 (Sun, 14 Dec 2008) | 1 line
don't retain parenthesis if there is only one item left
........
r67768 | benjamin.peterson | 2008-12-14 14:32:30 -0600 (Sun, 14 Dec 2008) | 1 line
use insert_child()
........
r67769 | benjamin.peterson | 2008-12-14 14:59:10 -0600 (Sun, 14 Dec 2008) | 1 line
parenthesize doesn't belong in pygram or FixerBase
........
r67770 | alexandre.vassalotti | 2008-12-14 15:15:36 -0600 (Sun, 14 Dec 2008) | 2 lines
Fix typo: html.paser -> html.parser.
........
r67771 | benjamin.peterson | 2008-12-14 15:22:09 -0600 (Sun, 14 Dec 2008) | 1 line
altering .children needs to call changed()
........
r67774 | benjamin.peterson | 2008-12-14 15:55:38 -0600 (Sun, 14 Dec 2008) | 1 line
employ an evil hack to fix multiple names in the same import statement
........
r67776 | benjamin.peterson | 2008-12-14 16:22:38 -0600 (Sun, 14 Dec 2008) | 1 line
make a common mixin class for Test_imports and friends
........
r67778 | alexandre.vassalotti | 2008-12-14 17:48:20 -0600 (Sun, 14 Dec 2008) | 2 lines
Make fix_imports refactor multiple imports as.
........
................
2008-12-15 23:57:54 -04:00
|
|
|
a = """import sys\nx = sys.intern(a)"""
|
2008-03-19 02:04:44 -03:00
|
|
|
self.check(b, a)
|
|
|
|
|
|
|
|
b = """z = intern(a+b+c.d,)"""
|
Merged revisions 67806 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk
................
r67806 | benjamin.peterson | 2008-12-15 21:35:28 -0600 (Mon, 15 Dec 2008) | 111 lines
Merged revisions 67427,67431,67433,67435,67630,67652,67656-67657,67674-67675,67678-67679,67705-67706,67716,67723,67765-67771,67774,67776,67778 via svnmerge from
svn+ssh://pythondev@svn.python.org/sandbox/trunk/2to3/lib2to3
........
r67427 | benjamin.peterson | 2008-11-28 16:07:41 -0600 (Fri, 28 Nov 2008) | 1 line
fix spelling in comment
........
r67431 | benjamin.peterson | 2008-11-28 17:14:08 -0600 (Fri, 28 Nov 2008) | 1 line
add a scripts directory; move things to it
........
r67433 | benjamin.peterson | 2008-11-28 17:18:48 -0600 (Fri, 28 Nov 2008) | 1 line
run svneol.py
........
r67435 | benjamin.peterson | 2008-11-28 17:25:03 -0600 (Fri, 28 Nov 2008) | 1 line
rename pre/post_order_mapping to pre/post_order_heads
........
r67630 | alexandre.vassalotti | 2008-12-06 21:51:56 -0600 (Sat, 06 Dec 2008) | 2 lines
Fix typo in the urllib2.HTTPDigestAuthHandler fixer.
........
r67652 | armin.ronacher | 2008-12-07 15:39:43 -0600 (Sun, 07 Dec 2008) | 5 lines
Added a fixer that cleans up a tuple argument to isinstance after the tokens
in it were fixed. This is mainly used to remove double occurrences of
tokens as a leftover of the long -> int / unicode -> str conversion.
........
r67656 | armin.ronacher | 2008-12-07 16:54:16 -0600 (Sun, 07 Dec 2008) | 3 lines
Added missing copyright fo 2to3 fix_isinstance.
........
r67657 | armin.ronacher | 2008-12-07 18:29:35 -0600 (Sun, 07 Dec 2008) | 3 lines
2to3: intern and reduce fixes now add the imports if missing. Because that is a common task the fixer_util module now has a function "touch_import" that adds imports if missing.
........
r67674 | benjamin.peterson | 2008-12-08 19:58:11 -0600 (Mon, 08 Dec 2008) | 1 line
copy permission bits when making backup files #4602
........
r67675 | benjamin.peterson | 2008-12-08 19:59:11 -0600 (Mon, 08 Dec 2008) | 1 line
add forgotten import
........
r67678 | benjamin.peterson | 2008-12-08 20:08:30 -0600 (Mon, 08 Dec 2008) | 1 line
fix #4602 for real
........
r67679 | armin.ronacher | 2008-12-09 00:54:03 -0600 (Tue, 09 Dec 2008) | 3 lines
Removed redudant code from the 2to3 long fixer. This fixes #4590.
........
r67705 | benjamin.peterson | 2008-12-11 13:04:08 -0600 (Thu, 11 Dec 2008) | 1 line
put trailers after a range call after the list()
........
r67706 | benjamin.peterson | 2008-12-11 13:17:57 -0600 (Thu, 11 Dec 2008) | 1 line
add html related modules to the fix_imports mapping
........
r67716 | benjamin.peterson | 2008-12-11 22:16:47 -0600 (Thu, 11 Dec 2008) | 1 line
consolidate tests
........
r67723 | benjamin.peterson | 2008-12-12 19:49:31 -0600 (Fri, 12 Dec 2008) | 1 line
fix name
........
r67765 | benjamin.peterson | 2008-12-14 14:05:05 -0600 (Sun, 14 Dec 2008) | 1 line
run fix_isinstance after fix_long and fix_unicode
........
r67766 | benjamin.peterson | 2008-12-14 14:13:05 -0600 (Sun, 14 Dec 2008) | 1 line
use run_order instead of order
........
r67767 | benjamin.peterson | 2008-12-14 14:28:12 -0600 (Sun, 14 Dec 2008) | 1 line
don't retain parenthesis if there is only one item left
........
r67768 | benjamin.peterson | 2008-12-14 14:32:30 -0600 (Sun, 14 Dec 2008) | 1 line
use insert_child()
........
r67769 | benjamin.peterson | 2008-12-14 14:59:10 -0600 (Sun, 14 Dec 2008) | 1 line
parenthesize doesn't belong in pygram or FixerBase
........
r67770 | alexandre.vassalotti | 2008-12-14 15:15:36 -0600 (Sun, 14 Dec 2008) | 2 lines
Fix typo: html.paser -> html.parser.
........
r67771 | benjamin.peterson | 2008-12-14 15:22:09 -0600 (Sun, 14 Dec 2008) | 1 line
altering .children needs to call changed()
........
r67774 | benjamin.peterson | 2008-12-14 15:55:38 -0600 (Sun, 14 Dec 2008) | 1 line
employ an evil hack to fix multiple names in the same import statement
........
r67776 | benjamin.peterson | 2008-12-14 16:22:38 -0600 (Sun, 14 Dec 2008) | 1 line
make a common mixin class for Test_imports and friends
........
r67778 | alexandre.vassalotti | 2008-12-14 17:48:20 -0600 (Sun, 14 Dec 2008) | 2 lines
Make fix_imports refactor multiple imports as.
........
................
2008-12-15 23:57:54 -04:00
|
|
|
a = """import sys\nz = sys.intern(a+b+c.d,)"""
|
2008-03-19 02:04:44 -03:00
|
|
|
self.check(b, a)
|
|
|
|
|
|
|
|
b = """intern("y%s" % 5).replace("y", "")"""
|
Merged revisions 67806 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk
................
r67806 | benjamin.peterson | 2008-12-15 21:35:28 -0600 (Mon, 15 Dec 2008) | 111 lines
Merged revisions 67427,67431,67433,67435,67630,67652,67656-67657,67674-67675,67678-67679,67705-67706,67716,67723,67765-67771,67774,67776,67778 via svnmerge from
svn+ssh://pythondev@svn.python.org/sandbox/trunk/2to3/lib2to3
........
r67427 | benjamin.peterson | 2008-11-28 16:07:41 -0600 (Fri, 28 Nov 2008) | 1 line
fix spelling in comment
........
r67431 | benjamin.peterson | 2008-11-28 17:14:08 -0600 (Fri, 28 Nov 2008) | 1 line
add a scripts directory; move things to it
........
r67433 | benjamin.peterson | 2008-11-28 17:18:48 -0600 (Fri, 28 Nov 2008) | 1 line
run svneol.py
........
r67435 | benjamin.peterson | 2008-11-28 17:25:03 -0600 (Fri, 28 Nov 2008) | 1 line
rename pre/post_order_mapping to pre/post_order_heads
........
r67630 | alexandre.vassalotti | 2008-12-06 21:51:56 -0600 (Sat, 06 Dec 2008) | 2 lines
Fix typo in the urllib2.HTTPDigestAuthHandler fixer.
........
r67652 | armin.ronacher | 2008-12-07 15:39:43 -0600 (Sun, 07 Dec 2008) | 5 lines
Added a fixer that cleans up a tuple argument to isinstance after the tokens
in it were fixed. This is mainly used to remove double occurrences of
tokens as a leftover of the long -> int / unicode -> str conversion.
........
r67656 | armin.ronacher | 2008-12-07 16:54:16 -0600 (Sun, 07 Dec 2008) | 3 lines
Added missing copyright fo 2to3 fix_isinstance.
........
r67657 | armin.ronacher | 2008-12-07 18:29:35 -0600 (Sun, 07 Dec 2008) | 3 lines
2to3: intern and reduce fixes now add the imports if missing. Because that is a common task the fixer_util module now has a function "touch_import" that adds imports if missing.
........
r67674 | benjamin.peterson | 2008-12-08 19:58:11 -0600 (Mon, 08 Dec 2008) | 1 line
copy permission bits when making backup files #4602
........
r67675 | benjamin.peterson | 2008-12-08 19:59:11 -0600 (Mon, 08 Dec 2008) | 1 line
add forgotten import
........
r67678 | benjamin.peterson | 2008-12-08 20:08:30 -0600 (Mon, 08 Dec 2008) | 1 line
fix #4602 for real
........
r67679 | armin.ronacher | 2008-12-09 00:54:03 -0600 (Tue, 09 Dec 2008) | 3 lines
Removed redudant code from the 2to3 long fixer. This fixes #4590.
........
r67705 | benjamin.peterson | 2008-12-11 13:04:08 -0600 (Thu, 11 Dec 2008) | 1 line
put trailers after a range call after the list()
........
r67706 | benjamin.peterson | 2008-12-11 13:17:57 -0600 (Thu, 11 Dec 2008) | 1 line
add html related modules to the fix_imports mapping
........
r67716 | benjamin.peterson | 2008-12-11 22:16:47 -0600 (Thu, 11 Dec 2008) | 1 line
consolidate tests
........
r67723 | benjamin.peterson | 2008-12-12 19:49:31 -0600 (Fri, 12 Dec 2008) | 1 line
fix name
........
r67765 | benjamin.peterson | 2008-12-14 14:05:05 -0600 (Sun, 14 Dec 2008) | 1 line
run fix_isinstance after fix_long and fix_unicode
........
r67766 | benjamin.peterson | 2008-12-14 14:13:05 -0600 (Sun, 14 Dec 2008) | 1 line
use run_order instead of order
........
r67767 | benjamin.peterson | 2008-12-14 14:28:12 -0600 (Sun, 14 Dec 2008) | 1 line
don't retain parenthesis if there is only one item left
........
r67768 | benjamin.peterson | 2008-12-14 14:32:30 -0600 (Sun, 14 Dec 2008) | 1 line
use insert_child()
........
r67769 | benjamin.peterson | 2008-12-14 14:59:10 -0600 (Sun, 14 Dec 2008) | 1 line
parenthesize doesn't belong in pygram or FixerBase
........
r67770 | alexandre.vassalotti | 2008-12-14 15:15:36 -0600 (Sun, 14 Dec 2008) | 2 lines
Fix typo: html.paser -> html.parser.
........
r67771 | benjamin.peterson | 2008-12-14 15:22:09 -0600 (Sun, 14 Dec 2008) | 1 line
altering .children needs to call changed()
........
r67774 | benjamin.peterson | 2008-12-14 15:55:38 -0600 (Sun, 14 Dec 2008) | 1 line
employ an evil hack to fix multiple names in the same import statement
........
r67776 | benjamin.peterson | 2008-12-14 16:22:38 -0600 (Sun, 14 Dec 2008) | 1 line
make a common mixin class for Test_imports and friends
........
r67778 | alexandre.vassalotti | 2008-12-14 17:48:20 -0600 (Sun, 14 Dec 2008) | 2 lines
Make fix_imports refactor multiple imports as.
........
................
2008-12-15 23:57:54 -04:00
|
|
|
a = """import sys\nsys.intern("y%s" % 5).replace("y", "")"""
|
2008-03-19 02:04:44 -03:00
|
|
|
self.check(b, a)
|
|
|
|
|
|
|
|
# These should not be refactored
|
|
|
|
|
|
|
|
def test_unchanged(self):
|
|
|
|
s = """intern(a=1)"""
|
|
|
|
self.unchanged(s)
|
|
|
|
|
|
|
|
s = """intern(f, g)"""
|
|
|
|
self.unchanged(s)
|
|
|
|
|
|
|
|
s = """intern(*h)"""
|
|
|
|
self.unchanged(s)
|
|
|
|
|
|
|
|
s = """intern(**i)"""
|
|
|
|
self.unchanged(s)
|
|
|
|
|
|
|
|
s = """intern()"""
|
|
|
|
self.unchanged(s)
|
|
|
|
|
Merged revisions 67806 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk
................
r67806 | benjamin.peterson | 2008-12-15 21:35:28 -0600 (Mon, 15 Dec 2008) | 111 lines
Merged revisions 67427,67431,67433,67435,67630,67652,67656-67657,67674-67675,67678-67679,67705-67706,67716,67723,67765-67771,67774,67776,67778 via svnmerge from
svn+ssh://pythondev@svn.python.org/sandbox/trunk/2to3/lib2to3
........
r67427 | benjamin.peterson | 2008-11-28 16:07:41 -0600 (Fri, 28 Nov 2008) | 1 line
fix spelling in comment
........
r67431 | benjamin.peterson | 2008-11-28 17:14:08 -0600 (Fri, 28 Nov 2008) | 1 line
add a scripts directory; move things to it
........
r67433 | benjamin.peterson | 2008-11-28 17:18:48 -0600 (Fri, 28 Nov 2008) | 1 line
run svneol.py
........
r67435 | benjamin.peterson | 2008-11-28 17:25:03 -0600 (Fri, 28 Nov 2008) | 1 line
rename pre/post_order_mapping to pre/post_order_heads
........
r67630 | alexandre.vassalotti | 2008-12-06 21:51:56 -0600 (Sat, 06 Dec 2008) | 2 lines
Fix typo in the urllib2.HTTPDigestAuthHandler fixer.
........
r67652 | armin.ronacher | 2008-12-07 15:39:43 -0600 (Sun, 07 Dec 2008) | 5 lines
Added a fixer that cleans up a tuple argument to isinstance after the tokens
in it were fixed. This is mainly used to remove double occurrences of
tokens as a leftover of the long -> int / unicode -> str conversion.
........
r67656 | armin.ronacher | 2008-12-07 16:54:16 -0600 (Sun, 07 Dec 2008) | 3 lines
Added missing copyright fo 2to3 fix_isinstance.
........
r67657 | armin.ronacher | 2008-12-07 18:29:35 -0600 (Sun, 07 Dec 2008) | 3 lines
2to3: intern and reduce fixes now add the imports if missing. Because that is a common task the fixer_util module now has a function "touch_import" that adds imports if missing.
........
r67674 | benjamin.peterson | 2008-12-08 19:58:11 -0600 (Mon, 08 Dec 2008) | 1 line
copy permission bits when making backup files #4602
........
r67675 | benjamin.peterson | 2008-12-08 19:59:11 -0600 (Mon, 08 Dec 2008) | 1 line
add forgotten import
........
r67678 | benjamin.peterson | 2008-12-08 20:08:30 -0600 (Mon, 08 Dec 2008) | 1 line
fix #4602 for real
........
r67679 | armin.ronacher | 2008-12-09 00:54:03 -0600 (Tue, 09 Dec 2008) | 3 lines
Removed redudant code from the 2to3 long fixer. This fixes #4590.
........
r67705 | benjamin.peterson | 2008-12-11 13:04:08 -0600 (Thu, 11 Dec 2008) | 1 line
put trailers after a range call after the list()
........
r67706 | benjamin.peterson | 2008-12-11 13:17:57 -0600 (Thu, 11 Dec 2008) | 1 line
add html related modules to the fix_imports mapping
........
r67716 | benjamin.peterson | 2008-12-11 22:16:47 -0600 (Thu, 11 Dec 2008) | 1 line
consolidate tests
........
r67723 | benjamin.peterson | 2008-12-12 19:49:31 -0600 (Fri, 12 Dec 2008) | 1 line
fix name
........
r67765 | benjamin.peterson | 2008-12-14 14:05:05 -0600 (Sun, 14 Dec 2008) | 1 line
run fix_isinstance after fix_long and fix_unicode
........
r67766 | benjamin.peterson | 2008-12-14 14:13:05 -0600 (Sun, 14 Dec 2008) | 1 line
use run_order instead of order
........
r67767 | benjamin.peterson | 2008-12-14 14:28:12 -0600 (Sun, 14 Dec 2008) | 1 line
don't retain parenthesis if there is only one item left
........
r67768 | benjamin.peterson | 2008-12-14 14:32:30 -0600 (Sun, 14 Dec 2008) | 1 line
use insert_child()
........
r67769 | benjamin.peterson | 2008-12-14 14:59:10 -0600 (Sun, 14 Dec 2008) | 1 line
parenthesize doesn't belong in pygram or FixerBase
........
r67770 | alexandre.vassalotti | 2008-12-14 15:15:36 -0600 (Sun, 14 Dec 2008) | 2 lines
Fix typo: html.paser -> html.parser.
........
r67771 | benjamin.peterson | 2008-12-14 15:22:09 -0600 (Sun, 14 Dec 2008) | 1 line
altering .children needs to call changed()
........
r67774 | benjamin.peterson | 2008-12-14 15:55:38 -0600 (Sun, 14 Dec 2008) | 1 line
employ an evil hack to fix multiple names in the same import statement
........
r67776 | benjamin.peterson | 2008-12-14 16:22:38 -0600 (Sun, 14 Dec 2008) | 1 line
make a common mixin class for Test_imports and friends
........
r67778 | alexandre.vassalotti | 2008-12-14 17:48:20 -0600 (Sun, 14 Dec 2008) | 2 lines
Make fix_imports refactor multiple imports as.
........
................
2008-12-15 23:57:54 -04:00
|
|
|
class Test_reduce(FixerTestCase):
|
|
|
|
fixer = "reduce"
|
|
|
|
|
|
|
|
def test_simple_call(self):
|
|
|
|
b = "reduce(a, b, c)"
|
|
|
|
a = "from functools import reduce\nreduce(a, b, c)"
|
|
|
|
self.check(b, a)
|
|
|
|
|
Merged revisions 76063,76068 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/branches/py3k
................
r76063 | benjamin.peterson | 2009-11-02 12:16:28 -0600 (Mon, 02 Nov 2009) | 77 lines
Merged revisions 76062 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk
................
r76062 | benjamin.peterson | 2009-11-02 12:12:12 -0600 (Mon, 02 Nov 2009) | 70 lines
Merged revisions 74359,75081,75088,75213,75278,75303,75427-75428,75734-75736,75865,76059-76061 via svnmerge from
svn+ssh://pythondev@svn.python.org/sandbox/trunk/2to3/lib2to3
........
r74359 | benjamin.peterson | 2009-08-12 17:23:13 -0500 (Wed, 12 Aug 2009) | 1 line
don't pass the deprecated print_function option
........
r75081 | benjamin.peterson | 2009-09-26 22:02:57 -0500 (Sat, 26 Sep 2009) | 1 line
let 2to3 work with extended iterable unpacking
........
r75088 | benjamin.peterson | 2009-09-27 11:25:21 -0500 (Sun, 27 Sep 2009) | 1 line
look on the type only for __call__
........
r75213 | benjamin.peterson | 2009-10-03 10:09:46 -0500 (Sat, 03 Oct 2009) | 5 lines
revert 75212; it's not correct
People can use isinstance(x, collections.Callable) if they expect objects with
__call__ in their instance dictionaries.
........
r75278 | benjamin.peterson | 2009-10-07 16:25:56 -0500 (Wed, 07 Oct 2009) | 4 lines
fix whitespace problems with fix_idioms #3563
Patch by Joe Amenta.
........
r75303 | benjamin.peterson | 2009-10-09 16:59:11 -0500 (Fri, 09 Oct 2009) | 1 line
port latin-1 and utf-8 cookie improvements
........
r75427 | benjamin.peterson | 2009-10-14 20:35:57 -0500 (Wed, 14 Oct 2009) | 1 line
force floor division
........
r75428 | benjamin.peterson | 2009-10-14 20:39:21 -0500 (Wed, 14 Oct 2009) | 1 line
silence -3 warnings about __hash__
........
r75734 | benjamin.peterson | 2009-10-26 16:25:53 -0500 (Mon, 26 Oct 2009) | 2 lines
warn on map(None, ...) with more than 2 arguments #7203
........
r75735 | benjamin.peterson | 2009-10-26 16:28:25 -0500 (Mon, 26 Oct 2009) | 1 line
remove unused result
........
r75736 | benjamin.peterson | 2009-10-26 16:29:02 -0500 (Mon, 26 Oct 2009) | 1 line
using get() here is a bit pointless
........
r75865 | benjamin.peterson | 2009-10-27 15:49:00 -0500 (Tue, 27 Oct 2009) | 1 line
explain reason for warning
........
r76059 | benjamin.peterson | 2009-11-02 11:43:47 -0600 (Mon, 02 Nov 2009) | 1 line
tuples are no longer used for children
........
r76060 | benjamin.peterson | 2009-11-02 11:55:40 -0600 (Mon, 02 Nov 2009) | 1 line
revert r76059; apparently some fixers rely on Leaf no () for children
........
r76061 | benjamin.peterson | 2009-11-02 12:06:17 -0600 (Mon, 02 Nov 2009) | 1 line
make fix_tuple_params keep the tree valid #7253
........
................
................
r76068 | benjamin.peterson | 2009-11-02 12:30:48 -0600 (Mon, 02 Nov 2009) | 24 lines
Merged revisions 76064,76066-76067 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk
................
r76064 | benjamin.peterson | 2009-11-02 12:16:36 -0600 (Mon, 02 Nov 2009) | 1 line
add space
................
r76066 | benjamin.peterson | 2009-11-02 12:22:53 -0600 (Mon, 02 Nov 2009) | 9 lines
Merged revisions 76065 via svnmerge from
svn+ssh://pythondev@svn.python.org/sandbox/trunk/2to3/lib2to3
........
r76065 | benjamin.peterson | 2009-11-02 12:21:25 -0600 (Mon, 02 Nov 2009) | 1 line
don't print stuff in tests
........
................
r76067 | benjamin.peterson | 2009-11-02 12:24:57 -0600 (Mon, 02 Nov 2009) | 1 line
enable test_parser in lib2to3
................
................
2009-11-02 14:33:36 -04:00
|
|
|
def test_bug_7253(self):
|
|
|
|
# fix_tuple_params was being bad and orphaning nodes in the tree.
|
|
|
|
b = "def x(arg): reduce(sum, [])"
|
|
|
|
a = "from functools import reduce\ndef x(arg): reduce(sum, [])"
|
|
|
|
self.check(b, a)
|
|
|
|
|
Merged revisions 67806 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk
................
r67806 | benjamin.peterson | 2008-12-15 21:35:28 -0600 (Mon, 15 Dec 2008) | 111 lines
Merged revisions 67427,67431,67433,67435,67630,67652,67656-67657,67674-67675,67678-67679,67705-67706,67716,67723,67765-67771,67774,67776,67778 via svnmerge from
svn+ssh://pythondev@svn.python.org/sandbox/trunk/2to3/lib2to3
........
r67427 | benjamin.peterson | 2008-11-28 16:07:41 -0600 (Fri, 28 Nov 2008) | 1 line
fix spelling in comment
........
r67431 | benjamin.peterson | 2008-11-28 17:14:08 -0600 (Fri, 28 Nov 2008) | 1 line
add a scripts directory; move things to it
........
r67433 | benjamin.peterson | 2008-11-28 17:18:48 -0600 (Fri, 28 Nov 2008) | 1 line
run svneol.py
........
r67435 | benjamin.peterson | 2008-11-28 17:25:03 -0600 (Fri, 28 Nov 2008) | 1 line
rename pre/post_order_mapping to pre/post_order_heads
........
r67630 | alexandre.vassalotti | 2008-12-06 21:51:56 -0600 (Sat, 06 Dec 2008) | 2 lines
Fix typo in the urllib2.HTTPDigestAuthHandler fixer.
........
r67652 | armin.ronacher | 2008-12-07 15:39:43 -0600 (Sun, 07 Dec 2008) | 5 lines
Added a fixer that cleans up a tuple argument to isinstance after the tokens
in it were fixed. This is mainly used to remove double occurrences of
tokens as a leftover of the long -> int / unicode -> str conversion.
........
r67656 | armin.ronacher | 2008-12-07 16:54:16 -0600 (Sun, 07 Dec 2008) | 3 lines
Added missing copyright fo 2to3 fix_isinstance.
........
r67657 | armin.ronacher | 2008-12-07 18:29:35 -0600 (Sun, 07 Dec 2008) | 3 lines
2to3: intern and reduce fixes now add the imports if missing. Because that is a common task the fixer_util module now has a function "touch_import" that adds imports if missing.
........
r67674 | benjamin.peterson | 2008-12-08 19:58:11 -0600 (Mon, 08 Dec 2008) | 1 line
copy permission bits when making backup files #4602
........
r67675 | benjamin.peterson | 2008-12-08 19:59:11 -0600 (Mon, 08 Dec 2008) | 1 line
add forgotten import
........
r67678 | benjamin.peterson | 2008-12-08 20:08:30 -0600 (Mon, 08 Dec 2008) | 1 line
fix #4602 for real
........
r67679 | armin.ronacher | 2008-12-09 00:54:03 -0600 (Tue, 09 Dec 2008) | 3 lines
Removed redudant code from the 2to3 long fixer. This fixes #4590.
........
r67705 | benjamin.peterson | 2008-12-11 13:04:08 -0600 (Thu, 11 Dec 2008) | 1 line
put trailers after a range call after the list()
........
r67706 | benjamin.peterson | 2008-12-11 13:17:57 -0600 (Thu, 11 Dec 2008) | 1 line
add html related modules to the fix_imports mapping
........
r67716 | benjamin.peterson | 2008-12-11 22:16:47 -0600 (Thu, 11 Dec 2008) | 1 line
consolidate tests
........
r67723 | benjamin.peterson | 2008-12-12 19:49:31 -0600 (Fri, 12 Dec 2008) | 1 line
fix name
........
r67765 | benjamin.peterson | 2008-12-14 14:05:05 -0600 (Sun, 14 Dec 2008) | 1 line
run fix_isinstance after fix_long and fix_unicode
........
r67766 | benjamin.peterson | 2008-12-14 14:13:05 -0600 (Sun, 14 Dec 2008) | 1 line
use run_order instead of order
........
r67767 | benjamin.peterson | 2008-12-14 14:28:12 -0600 (Sun, 14 Dec 2008) | 1 line
don't retain parenthesis if there is only one item left
........
r67768 | benjamin.peterson | 2008-12-14 14:32:30 -0600 (Sun, 14 Dec 2008) | 1 line
use insert_child()
........
r67769 | benjamin.peterson | 2008-12-14 14:59:10 -0600 (Sun, 14 Dec 2008) | 1 line
parenthesize doesn't belong in pygram or FixerBase
........
r67770 | alexandre.vassalotti | 2008-12-14 15:15:36 -0600 (Sun, 14 Dec 2008) | 2 lines
Fix typo: html.paser -> html.parser.
........
r67771 | benjamin.peterson | 2008-12-14 15:22:09 -0600 (Sun, 14 Dec 2008) | 1 line
altering .children needs to call changed()
........
r67774 | benjamin.peterson | 2008-12-14 15:55:38 -0600 (Sun, 14 Dec 2008) | 1 line
employ an evil hack to fix multiple names in the same import statement
........
r67776 | benjamin.peterson | 2008-12-14 16:22:38 -0600 (Sun, 14 Dec 2008) | 1 line
make a common mixin class for Test_imports and friends
........
r67778 | alexandre.vassalotti | 2008-12-14 17:48:20 -0600 (Sun, 14 Dec 2008) | 2 lines
Make fix_imports refactor multiple imports as.
........
................
2008-12-15 23:57:54 -04:00
|
|
|
def test_call_with_lambda(self):
|
|
|
|
b = "reduce(lambda x, y: x + y, seq)"
|
|
|
|
a = "from functools import reduce\nreduce(lambda x, y: x + y, seq)"
|
|
|
|
self.check(b, a)
|
|
|
|
|
|
|
|
def test_unchanged(self):
|
|
|
|
s = "reduce(a)"
|
|
|
|
self.unchanged(s)
|
|
|
|
|
|
|
|
s = "reduce(a, b=42)"
|
|
|
|
self.unchanged(s)
|
|
|
|
|
|
|
|
s = "reduce(a, b, c, d)"
|
|
|
|
self.unchanged(s)
|
|
|
|
|
|
|
|
s = "reduce(**c)"
|
|
|
|
self.unchanged(s)
|
|
|
|
|
|
|
|
s = "reduce()"
|
|
|
|
self.unchanged(s)
|
|
|
|
|
2008-03-19 02:04:44 -03:00
|
|
|
class Test_print(FixerTestCase):
|
|
|
|
fixer = "print"
|
|
|
|
|
|
|
|
def test_prefix_preservation(self):
|
|
|
|
b = """print 1, 1+1, 1+1+1"""
|
|
|
|
a = """print(1, 1+1, 1+1+1)"""
|
|
|
|
self.check(b, a)
|
|
|
|
|
|
|
|
def test_idempotency(self):
|
|
|
|
s = """print()"""
|
|
|
|
self.unchanged(s)
|
|
|
|
|
|
|
|
s = """print('')"""
|
|
|
|
self.unchanged(s)
|
|
|
|
|
|
|
|
def test_idempotency_print_as_function(self):
|
2009-07-21 09:55:57 -03:00
|
|
|
self.refactor.driver.grammar = pygram.python_grammar_no_print_statement
|
|
|
|
s = """print(1, 1+1, 1+1+1)"""
|
|
|
|
self.unchanged(s)
|
2008-03-19 02:04:44 -03:00
|
|
|
|
2009-07-21 09:55:57 -03:00
|
|
|
s = """print()"""
|
|
|
|
self.unchanged(s)
|
2008-03-19 02:04:44 -03:00
|
|
|
|
2009-07-21 09:55:57 -03:00
|
|
|
s = """print('')"""
|
|
|
|
self.unchanged(s)
|
2008-03-19 02:04:44 -03:00
|
|
|
|
|
|
|
def test_1(self):
|
|
|
|
b = """print 1, 1+1, 1+1+1"""
|
|
|
|
a = """print(1, 1+1, 1+1+1)"""
|
|
|
|
self.check(b, a)
|
|
|
|
|
|
|
|
def test_2(self):
|
|
|
|
b = """print 1, 2"""
|
|
|
|
a = """print(1, 2)"""
|
|
|
|
self.check(b, a)
|
|
|
|
|
|
|
|
def test_3(self):
|
|
|
|
b = """print"""
|
|
|
|
a = """print()"""
|
|
|
|
self.check(b, a)
|
|
|
|
|
2008-09-13 15:37:09 -03:00
|
|
|
def test_4(self):
|
|
|
|
# from bug 3000
|
|
|
|
b = """print whatever; print"""
|
|
|
|
a = """print(whatever); print()"""
|
|
|
|
self.check(b, a)
|
|
|
|
|
|
|
|
def test_5(self):
|
|
|
|
b = """print; print whatever;"""
|
|
|
|
a = """print(); print(whatever);"""
|
Merged revisions 73370 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk
................
r73370 | benjamin.peterson | 2009-06-11 17:06:46 -0500 (Thu, 11 Jun 2009) | 105 lines
Merged revisions 72523,72950-72951,72994,73003,73033,73036-73040,73091-73093,73096,73179-73181,73192,73231,73244,73255-73256,73365 via svnmerge from
svn+ssh://pythondev@svn.python.org/sandbox/trunk/2to3/lib2to3
........
r72523 | benjamin.peterson | 2009-05-09 14:42:26 -0500 (Sat, 09 May 2009) | 1 line
remove parenthesis
........
r72950 | benjamin.peterson | 2009-05-26 18:19:45 -0500 (Tue, 26 May 2009) | 1 line
remove unused imports
........
r72951 | benjamin.peterson | 2009-05-26 18:27:00 -0500 (Tue, 26 May 2009) | 1 line
this is no longer executable
........
r72994 | benjamin.peterson | 2009-05-28 15:32:54 -0500 (Thu, 28 May 2009) | 1 line
fix test_all_fixers on Windows #6134
........
r73003 | benjamin.peterson | 2009-05-28 21:57:28 -0500 (Thu, 28 May 2009) | 4 lines
make 2to3 test utilities easier to use with other applications (3to2)
Patch by Joe Amenta
........
r73033 | benjamin.peterson | 2009-05-29 16:58:32 -0500 (Fri, 29 May 2009) | 1 line
update grammar for multi with statement
........
r73036 | benjamin.peterson | 2009-05-29 17:33:20 -0500 (Fri, 29 May 2009) | 1 line
simplify fix_unicode
........
r73037 | benjamin.peterson | 2009-05-29 17:53:03 -0500 (Fri, 29 May 2009) | 1 line
add custom error for pattern syntax errors
........
r73038 | benjamin.peterson | 2009-05-29 17:55:00 -0500 (Fri, 29 May 2009) | 1 line
complain if details are attached to a token
........
r73039 | benjamin.peterson | 2009-05-29 18:00:28 -0500 (Fri, 29 May 2009) | 1 line
add a test for whitespace
........
r73040 | benjamin.peterson | 2009-05-29 18:01:17 -0500 (Fri, 29 May 2009) | 1 line
a fix for emacs highlighting
........
r73091 | benjamin.peterson | 2009-05-31 20:55:25 -0500 (Sun, 31 May 2009) | 1 line
deprecate set_prefix() and get_prefix() in favor of a prefix property
........
r73092 | benjamin.peterson | 2009-05-31 21:00:51 -0500 (Sun, 31 May 2009) | 1 line
change hideous java naming scheme
........
r73093 | benjamin.peterson | 2009-05-31 21:01:39 -0500 (Sun, 31 May 2009) | 1 line
remove dated comment
........
r73096 | benjamin.peterson | 2009-05-31 21:40:53 -0500 (Sun, 31 May 2009) | 1 line
group tests
........
r73179 | benjamin.peterson | 2009-06-03 13:09:53 -0500 (Wed, 03 Jun 2009) | 1 line
handle the case where there's multiple trailers #6185
........
r73180 | benjamin.peterson | 2009-06-03 13:18:05 -0500 (Wed, 03 Jun 2009) | 1 line
scrap __main__ section
........
r73181 | benjamin.peterson | 2009-06-03 13:24:48 -0500 (Wed, 03 Jun 2009) | 1 line
remove shebang lines and __main__ sections
........
r73192 | benjamin.peterson | 2009-06-03 19:16:30 -0500 (Wed, 03 Jun 2009) | 4 lines
actually test something here
Thanks to Joe Amenta for noticing.y
........
r73231 | benjamin.peterson | 2009-06-04 13:38:50 -0500 (Thu, 04 Jun 2009) | 1 line
remove unused variable
........
r73244 | benjamin.peterson | 2009-06-05 08:39:25 -0500 (Fri, 05 Jun 2009) | 1 line
allow fixers to give different options in setUp
........
r73255 | benjamin.peterson | 2009-06-06 11:23:46 -0500 (Sat, 06 Jun 2009) | 1 line
fix the except fixer on one line suites #6222
........
r73256 | benjamin.peterson | 2009-06-06 11:27:40 -0500 (Sat, 06 Jun 2009) | 1 line
test one-line else and finally clauses
........
r73365 | benjamin.peterson | 2009-06-11 17:01:32 -0500 (Thu, 11 Jun 2009) | 1 line
normalize whitespace
........
................
2009-06-11 20:47:38 -03:00
|
|
|
self.check(b, a)
|
2008-09-13 15:37:09 -03:00
|
|
|
|
2008-03-19 02:04:44 -03:00
|
|
|
def test_tuple(self):
|
|
|
|
b = """print (a, b, c)"""
|
|
|
|
a = """print((a, b, c))"""
|
|
|
|
self.check(b, a)
|
|
|
|
|
|
|
|
# trailing commas
|
|
|
|
|
|
|
|
def test_trailing_comma_1(self):
|
|
|
|
b = """print 1, 2, 3,"""
|
|
|
|
a = """print(1, 2, 3, end=' ')"""
|
|
|
|
self.check(b, a)
|
|
|
|
|
|
|
|
def test_trailing_comma_2(self):
|
|
|
|
b = """print 1, 2,"""
|
|
|
|
a = """print(1, 2, end=' ')"""
|
|
|
|
self.check(b, a)
|
|
|
|
|
|
|
|
def test_trailing_comma_3(self):
|
|
|
|
b = """print 1,"""
|
|
|
|
a = """print(1, end=' ')"""
|
|
|
|
self.check(b, a)
|
|
|
|
|
|
|
|
# >> stuff
|
|
|
|
|
|
|
|
def test_vargs_without_trailing_comma(self):
|
|
|
|
b = """print >>sys.stderr, 1, 2, 3"""
|
|
|
|
a = """print(1, 2, 3, file=sys.stderr)"""
|
|
|
|
self.check(b, a)
|
|
|
|
|
|
|
|
def test_with_trailing_comma(self):
|
|
|
|
b = """print >>sys.stderr, 1, 2,"""
|
|
|
|
a = """print(1, 2, end=' ', file=sys.stderr)"""
|
|
|
|
self.check(b, a)
|
|
|
|
|
|
|
|
def test_no_trailing_comma(self):
|
|
|
|
b = """print >>sys.stderr, 1+1"""
|
|
|
|
a = """print(1+1, file=sys.stderr)"""
|
|
|
|
self.check(b, a)
|
|
|
|
|
|
|
|
def test_spaces_before_file(self):
|
|
|
|
b = """print >> sys.stderr"""
|
|
|
|
a = """print(file=sys.stderr)"""
|
|
|
|
self.check(b, a)
|
|
|
|
|
Merged revisions 61724-61725 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk
................
r61724 | martin.v.loewis | 2008-03-22 01:01:12 +0100 (Sa, 22 Mär 2008) | 49 lines
Merged revisions 61602-61723 via svnmerge from
svn+ssh://pythondev@svn.python.org/sandbox/trunk/2to3/lib2to3
........
r61626 | david.wolever | 2008-03-19 17:19:16 +0100 (Mi, 19 Mär 2008) | 1 line
Added fixer for implicit local imports. See #2414.
........
r61628 | david.wolever | 2008-03-19 17:57:43 +0100 (Mi, 19 Mär 2008) | 1 line
Added a class for tests which should not run if a particular import is found.
........
r61629 | collin.winter | 2008-03-19 17:58:19 +0100 (Mi, 19 Mär 2008) | 1 line
Two more relative import fixes in pgen2.
........
r61635 | david.wolever | 2008-03-19 20:16:03 +0100 (Mi, 19 Mär 2008) | 1 line
Fixed print fixer so it will do the Right Thing when it encounters __future__.print_function. 2to3 gets upset, though, so the tests have been commented out.
........
r61637 | david.wolever | 2008-03-19 21:37:17 +0100 (Mi, 19 Mär 2008) | 3 lines
Added a fixer for itertools imports (from itertools import imap, ifilterfalse --> from itertools import filterfalse)
........
r61645 | david.wolever | 2008-03-19 23:22:35 +0100 (Mi, 19 Mär 2008) | 1 line
SVN is happier when you add the files you create... -_-'
........
r61654 | david.wolever | 2008-03-20 01:09:56 +0100 (Do, 20 Mär 2008) | 1 line
Added an explicit sort order to fixers -- fixes problems like #2427
........
r61664 | david.wolever | 2008-03-20 04:32:40 +0100 (Do, 20 Mär 2008) | 3 lines
Fixes #2428 -- comments are no longer eatten by __future__ fixer.
........
r61673 | david.wolever | 2008-03-20 17:22:40 +0100 (Do, 20 Mär 2008) | 1 line
Added 2to3 node pretty-printer
........
r61679 | david.wolever | 2008-03-20 20:50:42 +0100 (Do, 20 Mär 2008) | 1 line
Made node printing a little bit prettier
........
r61723 | martin.v.loewis | 2008-03-22 00:59:27 +0100 (Sa, 22 Mär 2008) | 2 lines
Fix whitespace.
........
................
r61725 | martin.v.loewis | 2008-03-22 01:02:41 +0100 (Sa, 22 Mär 2008) | 2 lines
Install lib2to3.
................
2008-03-21 21:07:09 -03:00
|
|
|
def test_with_future_print_function(self):
|
2009-07-21 09:55:57 -03:00
|
|
|
s = "from __future__ import print_function\n" \
|
|
|
|
"print('Hai!', end=' ')"
|
|
|
|
self.unchanged(s)
|
Merged revisions 61724-61725 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk
................
r61724 | martin.v.loewis | 2008-03-22 01:01:12 +0100 (Sa, 22 Mär 2008) | 49 lines
Merged revisions 61602-61723 via svnmerge from
svn+ssh://pythondev@svn.python.org/sandbox/trunk/2to3/lib2to3
........
r61626 | david.wolever | 2008-03-19 17:19:16 +0100 (Mi, 19 Mär 2008) | 1 line
Added fixer for implicit local imports. See #2414.
........
r61628 | david.wolever | 2008-03-19 17:57:43 +0100 (Mi, 19 Mär 2008) | 1 line
Added a class for tests which should not run if a particular import is found.
........
r61629 | collin.winter | 2008-03-19 17:58:19 +0100 (Mi, 19 Mär 2008) | 1 line
Two more relative import fixes in pgen2.
........
r61635 | david.wolever | 2008-03-19 20:16:03 +0100 (Mi, 19 Mär 2008) | 1 line
Fixed print fixer so it will do the Right Thing when it encounters __future__.print_function. 2to3 gets upset, though, so the tests have been commented out.
........
r61637 | david.wolever | 2008-03-19 21:37:17 +0100 (Mi, 19 Mär 2008) | 3 lines
Added a fixer for itertools imports (from itertools import imap, ifilterfalse --> from itertools import filterfalse)
........
r61645 | david.wolever | 2008-03-19 23:22:35 +0100 (Mi, 19 Mär 2008) | 1 line
SVN is happier when you add the files you create... -_-'
........
r61654 | david.wolever | 2008-03-20 01:09:56 +0100 (Do, 20 Mär 2008) | 1 line
Added an explicit sort order to fixers -- fixes problems like #2427
........
r61664 | david.wolever | 2008-03-20 04:32:40 +0100 (Do, 20 Mär 2008) | 3 lines
Fixes #2428 -- comments are no longer eatten by __future__ fixer.
........
r61673 | david.wolever | 2008-03-20 17:22:40 +0100 (Do, 20 Mär 2008) | 1 line
Added 2to3 node pretty-printer
........
r61679 | david.wolever | 2008-03-20 20:50:42 +0100 (Do, 20 Mär 2008) | 1 line
Made node printing a little bit prettier
........
r61723 | martin.v.loewis | 2008-03-22 00:59:27 +0100 (Sa, 22 Mär 2008) | 2 lines
Fix whitespace.
........
................
r61725 | martin.v.loewis | 2008-03-22 01:02:41 +0100 (Sa, 22 Mär 2008) | 2 lines
Install lib2to3.
................
2008-03-21 21:07:09 -03:00
|
|
|
|
2009-07-21 09:55:57 -03:00
|
|
|
b = "print 'Hello, world!'"
|
|
|
|
a = "print('Hello, world!')"
|
|
|
|
self.check(b, a)
|
Merged revisions 61724-61725 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk
................
r61724 | martin.v.loewis | 2008-03-22 01:01:12 +0100 (Sa, 22 Mär 2008) | 49 lines
Merged revisions 61602-61723 via svnmerge from
svn+ssh://pythondev@svn.python.org/sandbox/trunk/2to3/lib2to3
........
r61626 | david.wolever | 2008-03-19 17:19:16 +0100 (Mi, 19 Mär 2008) | 1 line
Added fixer for implicit local imports. See #2414.
........
r61628 | david.wolever | 2008-03-19 17:57:43 +0100 (Mi, 19 Mär 2008) | 1 line
Added a class for tests which should not run if a particular import is found.
........
r61629 | collin.winter | 2008-03-19 17:58:19 +0100 (Mi, 19 Mär 2008) | 1 line
Two more relative import fixes in pgen2.
........
r61635 | david.wolever | 2008-03-19 20:16:03 +0100 (Mi, 19 Mär 2008) | 1 line
Fixed print fixer so it will do the Right Thing when it encounters __future__.print_function. 2to3 gets upset, though, so the tests have been commented out.
........
r61637 | david.wolever | 2008-03-19 21:37:17 +0100 (Mi, 19 Mär 2008) | 3 lines
Added a fixer for itertools imports (from itertools import imap, ifilterfalse --> from itertools import filterfalse)
........
r61645 | david.wolever | 2008-03-19 23:22:35 +0100 (Mi, 19 Mär 2008) | 1 line
SVN is happier when you add the files you create... -_-'
........
r61654 | david.wolever | 2008-03-20 01:09:56 +0100 (Do, 20 Mär 2008) | 1 line
Added an explicit sort order to fixers -- fixes problems like #2427
........
r61664 | david.wolever | 2008-03-20 04:32:40 +0100 (Do, 20 Mär 2008) | 3 lines
Fixes #2428 -- comments are no longer eatten by __future__ fixer.
........
r61673 | david.wolever | 2008-03-20 17:22:40 +0100 (Do, 20 Mär 2008) | 1 line
Added 2to3 node pretty-printer
........
r61679 | david.wolever | 2008-03-20 20:50:42 +0100 (Do, 20 Mär 2008) | 1 line
Made node printing a little bit prettier
........
r61723 | martin.v.loewis | 2008-03-22 00:59:27 +0100 (Sa, 22 Mär 2008) | 2 lines
Fix whitespace.
........
................
r61725 | martin.v.loewis | 2008-03-22 01:02:41 +0100 (Sa, 22 Mär 2008) | 2 lines
Install lib2to3.
................
2008-03-21 21:07:09 -03:00
|
|
|
|
2008-03-19 02:04:44 -03:00
|
|
|
|
|
|
|
class Test_exec(FixerTestCase):
|
|
|
|
fixer = "exec"
|
|
|
|
|
|
|
|
def test_prefix_preservation(self):
|
|
|
|
b = """ exec code in ns1, ns2"""
|
|
|
|
a = """ exec(code, ns1, ns2)"""
|
|
|
|
self.check(b, a)
|
|
|
|
|
|
|
|
def test_basic(self):
|
|
|
|
b = """exec code"""
|
|
|
|
a = """exec(code)"""
|
|
|
|
self.check(b, a)
|
|
|
|
|
|
|
|
def test_with_globals(self):
|
|
|
|
b = """exec code in ns"""
|
|
|
|
a = """exec(code, ns)"""
|
|
|
|
self.check(b, a)
|
|
|
|
|
|
|
|
def test_with_globals_locals(self):
|
|
|
|
b = """exec code in ns1, ns2"""
|
|
|
|
a = """exec(code, ns1, ns2)"""
|
|
|
|
self.check(b, a)
|
|
|
|
|
|
|
|
def test_complex_1(self):
|
|
|
|
b = """exec (a.b()) in ns"""
|
|
|
|
a = """exec((a.b()), ns)"""
|
|
|
|
self.check(b, a)
|
|
|
|
|
|
|
|
def test_complex_2(self):
|
|
|
|
b = """exec a.b() + c in ns"""
|
|
|
|
a = """exec(a.b() + c, ns)"""
|
|
|
|
self.check(b, a)
|
|
|
|
|
|
|
|
# These should not be touched
|
|
|
|
|
|
|
|
def test_unchanged_1(self):
|
|
|
|
s = """exec(code)"""
|
|
|
|
self.unchanged(s)
|
|
|
|
|
|
|
|
def test_unchanged_2(self):
|
|
|
|
s = """exec (code)"""
|
|
|
|
self.unchanged(s)
|
|
|
|
|
|
|
|
def test_unchanged_3(self):
|
|
|
|
s = """exec(code, ns)"""
|
|
|
|
self.unchanged(s)
|
|
|
|
|
|
|
|
def test_unchanged_4(self):
|
|
|
|
s = """exec(code, ns1, ns2)"""
|
|
|
|
self.unchanged(s)
|
|
|
|
|
|
|
|
class Test_repr(FixerTestCase):
|
|
|
|
fixer = "repr"
|
|
|
|
|
|
|
|
def test_prefix_preservation(self):
|
|
|
|
b = """x = `1 + 2`"""
|
|
|
|
a = """x = repr(1 + 2)"""
|
|
|
|
self.check(b, a)
|
|
|
|
|
|
|
|
def test_simple_1(self):
|
|
|
|
b = """x = `1 + 2`"""
|
|
|
|
a = """x = repr(1 + 2)"""
|
|
|
|
self.check(b, a)
|
|
|
|
|
|
|
|
def test_simple_2(self):
|
|
|
|
b = """y = `x`"""
|
|
|
|
a = """y = repr(x)"""
|
|
|
|
self.check(b, a)
|
|
|
|
|
|
|
|
def test_complex(self):
|
|
|
|
b = """z = `y`.__repr__()"""
|
|
|
|
a = """z = repr(y).__repr__()"""
|
|
|
|
self.check(b, a)
|
|
|
|
|
|
|
|
def test_tuple(self):
|
|
|
|
b = """x = `1, 2, 3`"""
|
|
|
|
a = """x = repr((1, 2, 3))"""
|
|
|
|
self.check(b, a)
|
|
|
|
|
|
|
|
def test_nested(self):
|
|
|
|
b = """x = `1 + `2``"""
|
|
|
|
a = """x = repr(1 + repr(2))"""
|
|
|
|
self.check(b, a)
|
|
|
|
|
|
|
|
def test_nested_tuples(self):
|
|
|
|
b = """x = `1, 2 + `3, 4``"""
|
|
|
|
a = """x = repr((1, 2 + repr((3, 4))))"""
|
|
|
|
self.check(b, a)
|
|
|
|
|
|
|
|
class Test_except(FixerTestCase):
|
|
|
|
fixer = "except"
|
|
|
|
|
|
|
|
def test_prefix_preservation(self):
|
|
|
|
b = """
|
|
|
|
try:
|
|
|
|
pass
|
|
|
|
except (RuntimeError, ImportError), e:
|
|
|
|
pass"""
|
|
|
|
a = """
|
|
|
|
try:
|
|
|
|
pass
|
|
|
|
except (RuntimeError, ImportError) as e:
|
|
|
|
pass"""
|
|
|
|
self.check(b, a)
|
|
|
|
|
|
|
|
def test_simple(self):
|
|
|
|
b = """
|
|
|
|
try:
|
|
|
|
pass
|
|
|
|
except Foo, e:
|
|
|
|
pass"""
|
|
|
|
a = """
|
|
|
|
try:
|
|
|
|
pass
|
|
|
|
except Foo as e:
|
|
|
|
pass"""
|
|
|
|
self.check(b, a)
|
|
|
|
|
|
|
|
def test_simple_no_space_before_target(self):
|
|
|
|
b = """
|
|
|
|
try:
|
|
|
|
pass
|
|
|
|
except Foo,e:
|
|
|
|
pass"""
|
|
|
|
a = """
|
|
|
|
try:
|
|
|
|
pass
|
|
|
|
except Foo as e:
|
|
|
|
pass"""
|
|
|
|
self.check(b, a)
|
|
|
|
|
|
|
|
def test_tuple_unpack(self):
|
|
|
|
b = """
|
|
|
|
def foo():
|
|
|
|
try:
|
|
|
|
pass
|
|
|
|
except Exception, (f, e):
|
|
|
|
pass
|
|
|
|
except ImportError, e:
|
|
|
|
pass"""
|
|
|
|
|
|
|
|
a = """
|
|
|
|
def foo():
|
|
|
|
try:
|
|
|
|
pass
|
|
|
|
except Exception as xxx_todo_changeme:
|
|
|
|
(f, e) = xxx_todo_changeme.args
|
|
|
|
pass
|
|
|
|
except ImportError as e:
|
|
|
|
pass"""
|
|
|
|
self.check(b, a)
|
|
|
|
|
|
|
|
def test_multi_class(self):
|
|
|
|
b = """
|
|
|
|
try:
|
|
|
|
pass
|
|
|
|
except (RuntimeError, ImportError), e:
|
|
|
|
pass"""
|
|
|
|
|
|
|
|
a = """
|
|
|
|
try:
|
|
|
|
pass
|
|
|
|
except (RuntimeError, ImportError) as e:
|
|
|
|
pass"""
|
|
|
|
self.check(b, a)
|
|
|
|
|
|
|
|
def test_list_unpack(self):
|
|
|
|
b = """
|
|
|
|
try:
|
|
|
|
pass
|
|
|
|
except Exception, [a, b]:
|
|
|
|
pass"""
|
|
|
|
|
|
|
|
a = """
|
|
|
|
try:
|
|
|
|
pass
|
|
|
|
except Exception as xxx_todo_changeme:
|
|
|
|
[a, b] = xxx_todo_changeme.args
|
|
|
|
pass"""
|
|
|
|
self.check(b, a)
|
|
|
|
|
|
|
|
def test_weird_target_1(self):
|
|
|
|
b = """
|
|
|
|
try:
|
|
|
|
pass
|
|
|
|
except Exception, d[5]:
|
|
|
|
pass"""
|
|
|
|
|
|
|
|
a = """
|
|
|
|
try:
|
|
|
|
pass
|
|
|
|
except Exception as xxx_todo_changeme:
|
|
|
|
d[5] = xxx_todo_changeme
|
|
|
|
pass"""
|
|
|
|
self.check(b, a)
|
|
|
|
|
|
|
|
def test_weird_target_2(self):
|
|
|
|
b = """
|
|
|
|
try:
|
|
|
|
pass
|
|
|
|
except Exception, a.foo:
|
|
|
|
pass"""
|
|
|
|
|
|
|
|
a = """
|
|
|
|
try:
|
|
|
|
pass
|
|
|
|
except Exception as xxx_todo_changeme:
|
|
|
|
a.foo = xxx_todo_changeme
|
|
|
|
pass"""
|
|
|
|
self.check(b, a)
|
|
|
|
|
|
|
|
def test_weird_target_3(self):
|
|
|
|
b = """
|
|
|
|
try:
|
|
|
|
pass
|
|
|
|
except Exception, a().foo:
|
|
|
|
pass"""
|
|
|
|
|
|
|
|
a = """
|
|
|
|
try:
|
|
|
|
pass
|
|
|
|
except Exception as xxx_todo_changeme:
|
|
|
|
a().foo = xxx_todo_changeme
|
|
|
|
pass"""
|
|
|
|
self.check(b, a)
|
|
|
|
|
2008-03-28 02:29:57 -03:00
|
|
|
def test_bare_except(self):
|
|
|
|
b = """
|
|
|
|
try:
|
|
|
|
pass
|
|
|
|
except Exception, a:
|
|
|
|
pass
|
|
|
|
except:
|
|
|
|
pass"""
|
|
|
|
|
|
|
|
a = """
|
|
|
|
try:
|
|
|
|
pass
|
|
|
|
except Exception as a:
|
|
|
|
pass
|
|
|
|
except:
|
|
|
|
pass"""
|
|
|
|
self.check(b, a)
|
|
|
|
|
|
|
|
def test_bare_except_and_else_finally(self):
|
|
|
|
b = """
|
|
|
|
try:
|
|
|
|
pass
|
|
|
|
except Exception, a:
|
|
|
|
pass
|
|
|
|
except:
|
|
|
|
pass
|
|
|
|
else:
|
|
|
|
pass
|
|
|
|
finally:
|
|
|
|
pass"""
|
|
|
|
|
|
|
|
a = """
|
|
|
|
try:
|
|
|
|
pass
|
|
|
|
except Exception as a:
|
|
|
|
pass
|
|
|
|
except:
|
|
|
|
pass
|
|
|
|
else:
|
|
|
|
pass
|
|
|
|
finally:
|
|
|
|
pass"""
|
|
|
|
self.check(b, a)
|
|
|
|
|
|
|
|
def test_multi_fixed_excepts_before_bare_except(self):
|
|
|
|
b = """
|
|
|
|
try:
|
|
|
|
pass
|
|
|
|
except TypeError, b:
|
|
|
|
pass
|
|
|
|
except Exception, a:
|
|
|
|
pass
|
|
|
|
except:
|
|
|
|
pass"""
|
|
|
|
|
|
|
|
a = """
|
|
|
|
try:
|
|
|
|
pass
|
|
|
|
except TypeError as b:
|
|
|
|
pass
|
|
|
|
except Exception as a:
|
|
|
|
pass
|
|
|
|
except:
|
|
|
|
pass"""
|
|
|
|
self.check(b, a)
|
|
|
|
|
Merged revisions 73370 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk
................
r73370 | benjamin.peterson | 2009-06-11 17:06:46 -0500 (Thu, 11 Jun 2009) | 105 lines
Merged revisions 72523,72950-72951,72994,73003,73033,73036-73040,73091-73093,73096,73179-73181,73192,73231,73244,73255-73256,73365 via svnmerge from
svn+ssh://pythondev@svn.python.org/sandbox/trunk/2to3/lib2to3
........
r72523 | benjamin.peterson | 2009-05-09 14:42:26 -0500 (Sat, 09 May 2009) | 1 line
remove parenthesis
........
r72950 | benjamin.peterson | 2009-05-26 18:19:45 -0500 (Tue, 26 May 2009) | 1 line
remove unused imports
........
r72951 | benjamin.peterson | 2009-05-26 18:27:00 -0500 (Tue, 26 May 2009) | 1 line
this is no longer executable
........
r72994 | benjamin.peterson | 2009-05-28 15:32:54 -0500 (Thu, 28 May 2009) | 1 line
fix test_all_fixers on Windows #6134
........
r73003 | benjamin.peterson | 2009-05-28 21:57:28 -0500 (Thu, 28 May 2009) | 4 lines
make 2to3 test utilities easier to use with other applications (3to2)
Patch by Joe Amenta
........
r73033 | benjamin.peterson | 2009-05-29 16:58:32 -0500 (Fri, 29 May 2009) | 1 line
update grammar for multi with statement
........
r73036 | benjamin.peterson | 2009-05-29 17:33:20 -0500 (Fri, 29 May 2009) | 1 line
simplify fix_unicode
........
r73037 | benjamin.peterson | 2009-05-29 17:53:03 -0500 (Fri, 29 May 2009) | 1 line
add custom error for pattern syntax errors
........
r73038 | benjamin.peterson | 2009-05-29 17:55:00 -0500 (Fri, 29 May 2009) | 1 line
complain if details are attached to a token
........
r73039 | benjamin.peterson | 2009-05-29 18:00:28 -0500 (Fri, 29 May 2009) | 1 line
add a test for whitespace
........
r73040 | benjamin.peterson | 2009-05-29 18:01:17 -0500 (Fri, 29 May 2009) | 1 line
a fix for emacs highlighting
........
r73091 | benjamin.peterson | 2009-05-31 20:55:25 -0500 (Sun, 31 May 2009) | 1 line
deprecate set_prefix() and get_prefix() in favor of a prefix property
........
r73092 | benjamin.peterson | 2009-05-31 21:00:51 -0500 (Sun, 31 May 2009) | 1 line
change hideous java naming scheme
........
r73093 | benjamin.peterson | 2009-05-31 21:01:39 -0500 (Sun, 31 May 2009) | 1 line
remove dated comment
........
r73096 | benjamin.peterson | 2009-05-31 21:40:53 -0500 (Sun, 31 May 2009) | 1 line
group tests
........
r73179 | benjamin.peterson | 2009-06-03 13:09:53 -0500 (Wed, 03 Jun 2009) | 1 line
handle the case where there's multiple trailers #6185
........
r73180 | benjamin.peterson | 2009-06-03 13:18:05 -0500 (Wed, 03 Jun 2009) | 1 line
scrap __main__ section
........
r73181 | benjamin.peterson | 2009-06-03 13:24:48 -0500 (Wed, 03 Jun 2009) | 1 line
remove shebang lines and __main__ sections
........
r73192 | benjamin.peterson | 2009-06-03 19:16:30 -0500 (Wed, 03 Jun 2009) | 4 lines
actually test something here
Thanks to Joe Amenta for noticing.y
........
r73231 | benjamin.peterson | 2009-06-04 13:38:50 -0500 (Thu, 04 Jun 2009) | 1 line
remove unused variable
........
r73244 | benjamin.peterson | 2009-06-05 08:39:25 -0500 (Fri, 05 Jun 2009) | 1 line
allow fixers to give different options in setUp
........
r73255 | benjamin.peterson | 2009-06-06 11:23:46 -0500 (Sat, 06 Jun 2009) | 1 line
fix the except fixer on one line suites #6222
........
r73256 | benjamin.peterson | 2009-06-06 11:27:40 -0500 (Sat, 06 Jun 2009) | 1 line
test one-line else and finally clauses
........
r73365 | benjamin.peterson | 2009-06-11 17:01:32 -0500 (Thu, 11 Jun 2009) | 1 line
normalize whitespace
........
................
2009-06-11 20:47:38 -03:00
|
|
|
def test_one_line_suites(self):
|
|
|
|
b = """
|
|
|
|
try: raise TypeError
|
|
|
|
except TypeError, e:
|
|
|
|
pass
|
|
|
|
"""
|
|
|
|
a = """
|
|
|
|
try: raise TypeError
|
|
|
|
except TypeError as e:
|
|
|
|
pass
|
|
|
|
"""
|
|
|
|
self.check(b, a)
|
|
|
|
b = """
|
|
|
|
try:
|
|
|
|
raise TypeError
|
|
|
|
except TypeError, e: pass
|
|
|
|
"""
|
|
|
|
a = """
|
|
|
|
try:
|
|
|
|
raise TypeError
|
|
|
|
except TypeError as e: pass
|
|
|
|
"""
|
|
|
|
self.check(b, a)
|
|
|
|
b = """
|
|
|
|
try: raise TypeError
|
|
|
|
except TypeError, e: pass
|
|
|
|
"""
|
|
|
|
a = """
|
|
|
|
try: raise TypeError
|
|
|
|
except TypeError as e: pass
|
|
|
|
"""
|
|
|
|
self.check(b, a)
|
|
|
|
b = """
|
|
|
|
try: raise TypeError
|
|
|
|
except TypeError, e: pass
|
|
|
|
else: function()
|
|
|
|
finally: done()
|
|
|
|
"""
|
|
|
|
a = """
|
|
|
|
try: raise TypeError
|
|
|
|
except TypeError as e: pass
|
|
|
|
else: function()
|
|
|
|
finally: done()
|
|
|
|
"""
|
|
|
|
self.check(b, a)
|
|
|
|
|
2008-03-19 02:04:44 -03:00
|
|
|
# These should not be touched:
|
|
|
|
|
|
|
|
def test_unchanged_1(self):
|
|
|
|
s = """
|
|
|
|
try:
|
|
|
|
pass
|
|
|
|
except:
|
|
|
|
pass"""
|
|
|
|
self.unchanged(s)
|
|
|
|
|
|
|
|
def test_unchanged_2(self):
|
|
|
|
s = """
|
|
|
|
try:
|
|
|
|
pass
|
|
|
|
except Exception:
|
|
|
|
pass"""
|
|
|
|
self.unchanged(s)
|
|
|
|
|
|
|
|
def test_unchanged_3(self):
|
|
|
|
s = """
|
|
|
|
try:
|
|
|
|
pass
|
|
|
|
except (Exception, SystemExit):
|
|
|
|
pass"""
|
|
|
|
self.unchanged(s)
|
|
|
|
|
|
|
|
class Test_raise(FixerTestCase):
|
|
|
|
fixer = "raise"
|
|
|
|
|
|
|
|
def test_basic(self):
|
|
|
|
b = """raise Exception, 5"""
|
|
|
|
a = """raise Exception(5)"""
|
|
|
|
self.check(b, a)
|
|
|
|
|
|
|
|
def test_prefix_preservation(self):
|
|
|
|
b = """raise Exception,5"""
|
|
|
|
a = """raise Exception(5)"""
|
|
|
|
self.check(b, a)
|
|
|
|
|
|
|
|
b = """raise Exception, 5"""
|
|
|
|
a = """raise Exception(5)"""
|
|
|
|
self.check(b, a)
|
|
|
|
|
|
|
|
def test_with_comments(self):
|
|
|
|
b = """raise Exception, 5 # foo"""
|
|
|
|
a = """raise Exception(5) # foo"""
|
|
|
|
self.check(b, a)
|
|
|
|
|
|
|
|
b = """raise E, (5, 6) % (a, b) # foo"""
|
|
|
|
a = """raise E((5, 6) % (a, b)) # foo"""
|
|
|
|
self.check(b, a)
|
|
|
|
|
|
|
|
b = """def foo():
|
|
|
|
raise Exception, 5, 6 # foo"""
|
|
|
|
a = """def foo():
|
|
|
|
raise Exception(5).with_traceback(6) # foo"""
|
|
|
|
self.check(b, a)
|
|
|
|
|
|
|
|
def test_tuple_value(self):
|
|
|
|
b = """raise Exception, (5, 6, 7)"""
|
|
|
|
a = """raise Exception(5, 6, 7)"""
|
|
|
|
self.check(b, a)
|
|
|
|
|
|
|
|
def test_tuple_detection(self):
|
|
|
|
b = """raise E, (5, 6) % (a, b)"""
|
|
|
|
a = """raise E((5, 6) % (a, b))"""
|
|
|
|
self.check(b, a)
|
|
|
|
|
|
|
|
def test_tuple_exc_1(self):
|
|
|
|
b = """raise (((E1, E2), E3), E4), V"""
|
|
|
|
a = """raise E1(V)"""
|
|
|
|
self.check(b, a)
|
|
|
|
|
|
|
|
def test_tuple_exc_2(self):
|
|
|
|
b = """raise (E1, (E2, E3), E4), V"""
|
|
|
|
a = """raise E1(V)"""
|
|
|
|
self.check(b, a)
|
|
|
|
|
|
|
|
# These should produce a warning
|
|
|
|
|
|
|
|
def test_string_exc(self):
|
|
|
|
s = """raise 'foo'"""
|
|
|
|
self.warns_unchanged(s, "Python 3 does not support string exceptions")
|
|
|
|
|
|
|
|
def test_string_exc_val(self):
|
|
|
|
s = """raise "foo", 5"""
|
|
|
|
self.warns_unchanged(s, "Python 3 does not support string exceptions")
|
|
|
|
|
|
|
|
def test_string_exc_val_tb(self):
|
|
|
|
s = """raise "foo", 5, 6"""
|
|
|
|
self.warns_unchanged(s, "Python 3 does not support string exceptions")
|
|
|
|
|
|
|
|
# These should result in traceback-assignment
|
|
|
|
|
|
|
|
def test_tb_1(self):
|
|
|
|
b = """def foo():
|
|
|
|
raise Exception, 5, 6"""
|
|
|
|
a = """def foo():
|
|
|
|
raise Exception(5).with_traceback(6)"""
|
|
|
|
self.check(b, a)
|
|
|
|
|
|
|
|
def test_tb_2(self):
|
|
|
|
b = """def foo():
|
|
|
|
a = 5
|
|
|
|
raise Exception, 5, 6
|
|
|
|
b = 6"""
|
|
|
|
a = """def foo():
|
|
|
|
a = 5
|
|
|
|
raise Exception(5).with_traceback(6)
|
|
|
|
b = 6"""
|
|
|
|
self.check(b, a)
|
|
|
|
|
|
|
|
def test_tb_3(self):
|
|
|
|
b = """def foo():
|
|
|
|
raise Exception,5,6"""
|
|
|
|
a = """def foo():
|
|
|
|
raise Exception(5).with_traceback(6)"""
|
|
|
|
self.check(b, a)
|
|
|
|
|
|
|
|
def test_tb_4(self):
|
|
|
|
b = """def foo():
|
|
|
|
a = 5
|
|
|
|
raise Exception,5,6
|
|
|
|
b = 6"""
|
|
|
|
a = """def foo():
|
|
|
|
a = 5
|
|
|
|
raise Exception(5).with_traceback(6)
|
|
|
|
b = 6"""
|
|
|
|
self.check(b, a)
|
|
|
|
|
|
|
|
def test_tb_5(self):
|
|
|
|
b = """def foo():
|
|
|
|
raise Exception, (5, 6, 7), 6"""
|
|
|
|
a = """def foo():
|
|
|
|
raise Exception(5, 6, 7).with_traceback(6)"""
|
|
|
|
self.check(b, a)
|
|
|
|
|
|
|
|
def test_tb_6(self):
|
|
|
|
b = """def foo():
|
|
|
|
a = 5
|
|
|
|
raise Exception, (5, 6, 7), 6
|
|
|
|
b = 6"""
|
|
|
|
a = """def foo():
|
|
|
|
a = 5
|
|
|
|
raise Exception(5, 6, 7).with_traceback(6)
|
|
|
|
b = 6"""
|
|
|
|
self.check(b, a)
|
|
|
|
|
|
|
|
class Test_throw(FixerTestCase):
|
|
|
|
fixer = "throw"
|
|
|
|
|
|
|
|
def test_1(self):
|
|
|
|
b = """g.throw(Exception, 5)"""
|
|
|
|
a = """g.throw(Exception(5))"""
|
|
|
|
self.check(b, a)
|
|
|
|
|
|
|
|
def test_2(self):
|
|
|
|
b = """g.throw(Exception,5)"""
|
|
|
|
a = """g.throw(Exception(5))"""
|
|
|
|
self.check(b, a)
|
|
|
|
|
|
|
|
def test_3(self):
|
|
|
|
b = """g.throw(Exception, (5, 6, 7))"""
|
|
|
|
a = """g.throw(Exception(5, 6, 7))"""
|
|
|
|
self.check(b, a)
|
|
|
|
|
|
|
|
def test_4(self):
|
|
|
|
b = """5 + g.throw(Exception, 5)"""
|
|
|
|
a = """5 + g.throw(Exception(5))"""
|
|
|
|
self.check(b, a)
|
|
|
|
|
|
|
|
# These should produce warnings
|
|
|
|
|
|
|
|
def test_warn_1(self):
|
|
|
|
s = """g.throw("foo")"""
|
|
|
|
self.warns_unchanged(s, "Python 3 does not support string exceptions")
|
|
|
|
|
|
|
|
def test_warn_2(self):
|
|
|
|
s = """g.throw("foo", 5)"""
|
|
|
|
self.warns_unchanged(s, "Python 3 does not support string exceptions")
|
|
|
|
|
|
|
|
def test_warn_3(self):
|
|
|
|
s = """g.throw("foo", 5, 6)"""
|
|
|
|
self.warns_unchanged(s, "Python 3 does not support string exceptions")
|
|
|
|
|
|
|
|
# These should not be touched
|
|
|
|
|
|
|
|
def test_untouched_1(self):
|
|
|
|
s = """g.throw(Exception)"""
|
|
|
|
self.unchanged(s)
|
|
|
|
|
|
|
|
def test_untouched_2(self):
|
|
|
|
s = """g.throw(Exception(5, 6))"""
|
|
|
|
self.unchanged(s)
|
|
|
|
|
|
|
|
def test_untouched_3(self):
|
|
|
|
s = """5 + g.throw(Exception(5, 6))"""
|
|
|
|
self.unchanged(s)
|
|
|
|
|
|
|
|
# These should result in traceback-assignment
|
|
|
|
|
|
|
|
def test_tb_1(self):
|
|
|
|
b = """def foo():
|
|
|
|
g.throw(Exception, 5, 6)"""
|
|
|
|
a = """def foo():
|
|
|
|
g.throw(Exception(5).with_traceback(6))"""
|
|
|
|
self.check(b, a)
|
|
|
|
|
|
|
|
def test_tb_2(self):
|
|
|
|
b = """def foo():
|
|
|
|
a = 5
|
|
|
|
g.throw(Exception, 5, 6)
|
|
|
|
b = 6"""
|
|
|
|
a = """def foo():
|
|
|
|
a = 5
|
|
|
|
g.throw(Exception(5).with_traceback(6))
|
|
|
|
b = 6"""
|
|
|
|
self.check(b, a)
|
|
|
|
|
|
|
|
def test_tb_3(self):
|
|
|
|
b = """def foo():
|
|
|
|
g.throw(Exception,5,6)"""
|
|
|
|
a = """def foo():
|
|
|
|
g.throw(Exception(5).with_traceback(6))"""
|
|
|
|
self.check(b, a)
|
|
|
|
|
|
|
|
def test_tb_4(self):
|
|
|
|
b = """def foo():
|
|
|
|
a = 5
|
|
|
|
g.throw(Exception,5,6)
|
|
|
|
b = 6"""
|
|
|
|
a = """def foo():
|
|
|
|
a = 5
|
|
|
|
g.throw(Exception(5).with_traceback(6))
|
|
|
|
b = 6"""
|
|
|
|
self.check(b, a)
|
|
|
|
|
|
|
|
def test_tb_5(self):
|
|
|
|
b = """def foo():
|
|
|
|
g.throw(Exception, (5, 6, 7), 6)"""
|
|
|
|
a = """def foo():
|
|
|
|
g.throw(Exception(5, 6, 7).with_traceback(6))"""
|
|
|
|
self.check(b, a)
|
|
|
|
|
|
|
|
def test_tb_6(self):
|
|
|
|
b = """def foo():
|
|
|
|
a = 5
|
|
|
|
g.throw(Exception, (5, 6, 7), 6)
|
|
|
|
b = 6"""
|
|
|
|
a = """def foo():
|
|
|
|
a = 5
|
|
|
|
g.throw(Exception(5, 6, 7).with_traceback(6))
|
|
|
|
b = 6"""
|
|
|
|
self.check(b, a)
|
|
|
|
|
|
|
|
def test_tb_7(self):
|
|
|
|
b = """def foo():
|
|
|
|
a + g.throw(Exception, 5, 6)"""
|
|
|
|
a = """def foo():
|
|
|
|
a + g.throw(Exception(5).with_traceback(6))"""
|
|
|
|
self.check(b, a)
|
|
|
|
|
|
|
|
def test_tb_8(self):
|
|
|
|
b = """def foo():
|
|
|
|
a = 5
|
|
|
|
a + g.throw(Exception, 5, 6)
|
|
|
|
b = 6"""
|
|
|
|
a = """def foo():
|
|
|
|
a = 5
|
|
|
|
a + g.throw(Exception(5).with_traceback(6))
|
|
|
|
b = 6"""
|
|
|
|
self.check(b, a)
|
|
|
|
|
|
|
|
class Test_long(FixerTestCase):
|
|
|
|
fixer = "long"
|
|
|
|
|
|
|
|
def test_1(self):
|
|
|
|
b = """x = long(x)"""
|
|
|
|
a = """x = int(x)"""
|
|
|
|
self.check(b, a)
|
|
|
|
|
|
|
|
def test_2(self):
|
|
|
|
b = """y = isinstance(x, long)"""
|
|
|
|
a = """y = isinstance(x, int)"""
|
|
|
|
self.check(b, a)
|
|
|
|
|
|
|
|
def test_3(self):
|
|
|
|
b = """z = type(x) in (int, long)"""
|
|
|
|
a = """z = type(x) in (int, int)"""
|
|
|
|
self.check(b, a)
|
|
|
|
|
Merged revisions 68197 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk
................
r68197 | benjamin.peterson | 2009-01-03 10:34:02 -0600 (Sat, 03 Jan 2009) | 55 lines
Merged revisions 67900-67901,67919,67928,67984,67991-67993,68106-68108,68110 via svnmerge from
svn+ssh://pythondev@svn.python.org/sandbox/trunk/2to3/lib2to3
........
r67900 | benjamin.peterson | 2008-12-22 14:02:45 -0600 (Mon, 22 Dec 2008) | 4 lines
fix_execfile: wrap the open(fn).read() call in compile(), so the filename is preserved
also add unittests for the fixer
........
r67901 | benjamin.peterson | 2008-12-22 14:09:55 -0600 (Mon, 22 Dec 2008) | 1 line
remove unused import
........
r67919 | benjamin.peterson | 2008-12-23 13:12:22 -0600 (Tue, 23 Dec 2008) | 1 line
copy permission bits from the backup to the original
........
r67928 | benjamin.peterson | 2008-12-26 20:49:30 -0600 (Fri, 26 Dec 2008) | 1 line
don't be so idiot about multiple local imports in fix_import; still won't handle absolute and local imports on the same line
........
r67984 | benjamin.peterson | 2008-12-28 09:55:16 -0600 (Sun, 28 Dec 2008) | 1 line
don't need loop
........
r67991 | benjamin.peterson | 2008-12-28 14:30:26 -0600 (Sun, 28 Dec 2008) | 1 line
actually call finish_tree()
........
r67992 | benjamin.peterson | 2008-12-28 14:34:47 -0600 (Sun, 28 Dec 2008) | 1 line
remove useless test
........
r67993 | benjamin.peterson | 2008-12-28 15:04:32 -0600 (Sun, 28 Dec 2008) | 1 line
update pyk3's test grammar
........
r68106 | benjamin.peterson | 2008-12-31 11:53:58 -0600 (Wed, 31 Dec 2008) | 1 line
#2734 don't convert every instance of long (eg if it's an attribute)
........
r68107 | benjamin.peterson | 2008-12-31 11:55:10 -0600 (Wed, 31 Dec 2008) | 1 line
add another test
........
r68108 | benjamin.peterson | 2008-12-31 12:00:12 -0600 (Wed, 31 Dec 2008) | 1 line
don't change long even if it's the only argument name
........
r68110 | benjamin.peterson | 2008-12-31 14:13:26 -0600 (Wed, 31 Dec 2008) | 1 line
remove unused import
........
................
2009-01-03 12:53:14 -04:00
|
|
|
def test_unchanged(self):
|
|
|
|
s = """long = True"""
|
|
|
|
self.unchanged(s)
|
|
|
|
|
|
|
|
s = """s.long = True"""
|
|
|
|
self.unchanged(s)
|
|
|
|
|
|
|
|
s = """def long(): pass"""
|
|
|
|
self.unchanged(s)
|
|
|
|
|
|
|
|
s = """class long(): pass"""
|
|
|
|
self.unchanged(s)
|
|
|
|
|
|
|
|
s = """def f(long): pass"""
|
|
|
|
self.unchanged(s)
|
|
|
|
|
|
|
|
s = """def f(g, long): pass"""
|
|
|
|
self.unchanged(s)
|
|
|
|
|
|
|
|
s = """def f(x, long=True): pass"""
|
|
|
|
self.unchanged(s)
|
|
|
|
|
Merged revisions 67806 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk
................
r67806 | benjamin.peterson | 2008-12-15 21:35:28 -0600 (Mon, 15 Dec 2008) | 111 lines
Merged revisions 67427,67431,67433,67435,67630,67652,67656-67657,67674-67675,67678-67679,67705-67706,67716,67723,67765-67771,67774,67776,67778 via svnmerge from
svn+ssh://pythondev@svn.python.org/sandbox/trunk/2to3/lib2to3
........
r67427 | benjamin.peterson | 2008-11-28 16:07:41 -0600 (Fri, 28 Nov 2008) | 1 line
fix spelling in comment
........
r67431 | benjamin.peterson | 2008-11-28 17:14:08 -0600 (Fri, 28 Nov 2008) | 1 line
add a scripts directory; move things to it
........
r67433 | benjamin.peterson | 2008-11-28 17:18:48 -0600 (Fri, 28 Nov 2008) | 1 line
run svneol.py
........
r67435 | benjamin.peterson | 2008-11-28 17:25:03 -0600 (Fri, 28 Nov 2008) | 1 line
rename pre/post_order_mapping to pre/post_order_heads
........
r67630 | alexandre.vassalotti | 2008-12-06 21:51:56 -0600 (Sat, 06 Dec 2008) | 2 lines
Fix typo in the urllib2.HTTPDigestAuthHandler fixer.
........
r67652 | armin.ronacher | 2008-12-07 15:39:43 -0600 (Sun, 07 Dec 2008) | 5 lines
Added a fixer that cleans up a tuple argument to isinstance after the tokens
in it were fixed. This is mainly used to remove double occurrences of
tokens as a leftover of the long -> int / unicode -> str conversion.
........
r67656 | armin.ronacher | 2008-12-07 16:54:16 -0600 (Sun, 07 Dec 2008) | 3 lines
Added missing copyright fo 2to3 fix_isinstance.
........
r67657 | armin.ronacher | 2008-12-07 18:29:35 -0600 (Sun, 07 Dec 2008) | 3 lines
2to3: intern and reduce fixes now add the imports if missing. Because that is a common task the fixer_util module now has a function "touch_import" that adds imports if missing.
........
r67674 | benjamin.peterson | 2008-12-08 19:58:11 -0600 (Mon, 08 Dec 2008) | 1 line
copy permission bits when making backup files #4602
........
r67675 | benjamin.peterson | 2008-12-08 19:59:11 -0600 (Mon, 08 Dec 2008) | 1 line
add forgotten import
........
r67678 | benjamin.peterson | 2008-12-08 20:08:30 -0600 (Mon, 08 Dec 2008) | 1 line
fix #4602 for real
........
r67679 | armin.ronacher | 2008-12-09 00:54:03 -0600 (Tue, 09 Dec 2008) | 3 lines
Removed redudant code from the 2to3 long fixer. This fixes #4590.
........
r67705 | benjamin.peterson | 2008-12-11 13:04:08 -0600 (Thu, 11 Dec 2008) | 1 line
put trailers after a range call after the list()
........
r67706 | benjamin.peterson | 2008-12-11 13:17:57 -0600 (Thu, 11 Dec 2008) | 1 line
add html related modules to the fix_imports mapping
........
r67716 | benjamin.peterson | 2008-12-11 22:16:47 -0600 (Thu, 11 Dec 2008) | 1 line
consolidate tests
........
r67723 | benjamin.peterson | 2008-12-12 19:49:31 -0600 (Fri, 12 Dec 2008) | 1 line
fix name
........
r67765 | benjamin.peterson | 2008-12-14 14:05:05 -0600 (Sun, 14 Dec 2008) | 1 line
run fix_isinstance after fix_long and fix_unicode
........
r67766 | benjamin.peterson | 2008-12-14 14:13:05 -0600 (Sun, 14 Dec 2008) | 1 line
use run_order instead of order
........
r67767 | benjamin.peterson | 2008-12-14 14:28:12 -0600 (Sun, 14 Dec 2008) | 1 line
don't retain parenthesis if there is only one item left
........
r67768 | benjamin.peterson | 2008-12-14 14:32:30 -0600 (Sun, 14 Dec 2008) | 1 line
use insert_child()
........
r67769 | benjamin.peterson | 2008-12-14 14:59:10 -0600 (Sun, 14 Dec 2008) | 1 line
parenthesize doesn't belong in pygram or FixerBase
........
r67770 | alexandre.vassalotti | 2008-12-14 15:15:36 -0600 (Sun, 14 Dec 2008) | 2 lines
Fix typo: html.paser -> html.parser.
........
r67771 | benjamin.peterson | 2008-12-14 15:22:09 -0600 (Sun, 14 Dec 2008) | 1 line
altering .children needs to call changed()
........
r67774 | benjamin.peterson | 2008-12-14 15:55:38 -0600 (Sun, 14 Dec 2008) | 1 line
employ an evil hack to fix multiple names in the same import statement
........
r67776 | benjamin.peterson | 2008-12-14 16:22:38 -0600 (Sun, 14 Dec 2008) | 1 line
make a common mixin class for Test_imports and friends
........
r67778 | alexandre.vassalotti | 2008-12-14 17:48:20 -0600 (Sun, 14 Dec 2008) | 2 lines
Make fix_imports refactor multiple imports as.
........
................
2008-12-15 23:57:54 -04:00
|
|
|
def test_prefix_preservation(self):
|
|
|
|
b = """x = long( x )"""
|
|
|
|
a = """x = int( x )"""
|
2008-03-19 02:04:44 -03:00
|
|
|
self.check(b, a)
|
|
|
|
|
Merged revisions 68197 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk
................
r68197 | benjamin.peterson | 2009-01-03 10:34:02 -0600 (Sat, 03 Jan 2009) | 55 lines
Merged revisions 67900-67901,67919,67928,67984,67991-67993,68106-68108,68110 via svnmerge from
svn+ssh://pythondev@svn.python.org/sandbox/trunk/2to3/lib2to3
........
r67900 | benjamin.peterson | 2008-12-22 14:02:45 -0600 (Mon, 22 Dec 2008) | 4 lines
fix_execfile: wrap the open(fn).read() call in compile(), so the filename is preserved
also add unittests for the fixer
........
r67901 | benjamin.peterson | 2008-12-22 14:09:55 -0600 (Mon, 22 Dec 2008) | 1 line
remove unused import
........
r67919 | benjamin.peterson | 2008-12-23 13:12:22 -0600 (Tue, 23 Dec 2008) | 1 line
copy permission bits from the backup to the original
........
r67928 | benjamin.peterson | 2008-12-26 20:49:30 -0600 (Fri, 26 Dec 2008) | 1 line
don't be so idiot about multiple local imports in fix_import; still won't handle absolute and local imports on the same line
........
r67984 | benjamin.peterson | 2008-12-28 09:55:16 -0600 (Sun, 28 Dec 2008) | 1 line
don't need loop
........
r67991 | benjamin.peterson | 2008-12-28 14:30:26 -0600 (Sun, 28 Dec 2008) | 1 line
actually call finish_tree()
........
r67992 | benjamin.peterson | 2008-12-28 14:34:47 -0600 (Sun, 28 Dec 2008) | 1 line
remove useless test
........
r67993 | benjamin.peterson | 2008-12-28 15:04:32 -0600 (Sun, 28 Dec 2008) | 1 line
update pyk3's test grammar
........
r68106 | benjamin.peterson | 2008-12-31 11:53:58 -0600 (Wed, 31 Dec 2008) | 1 line
#2734 don't convert every instance of long (eg if it's an attribute)
........
r68107 | benjamin.peterson | 2008-12-31 11:55:10 -0600 (Wed, 31 Dec 2008) | 1 line
add another test
........
r68108 | benjamin.peterson | 2008-12-31 12:00:12 -0600 (Wed, 31 Dec 2008) | 1 line
don't change long even if it's the only argument name
........
r68110 | benjamin.peterson | 2008-12-31 14:13:26 -0600 (Wed, 31 Dec 2008) | 1 line
remove unused import
........
................
2009-01-03 12:53:14 -04:00
|
|
|
|
|
|
|
class Test_execfile(FixerTestCase):
|
|
|
|
fixer = "execfile"
|
|
|
|
|
|
|
|
def test_conversion(self):
|
|
|
|
b = """execfile("fn")"""
|
|
|
|
a = """exec(compile(open("fn").read(), "fn", 'exec'))"""
|
|
|
|
self.check(b, a)
|
|
|
|
|
|
|
|
b = """execfile("fn", glob)"""
|
|
|
|
a = """exec(compile(open("fn").read(), "fn", 'exec'), glob)"""
|
|
|
|
self.check(b, a)
|
|
|
|
|
|
|
|
b = """execfile("fn", glob, loc)"""
|
|
|
|
a = """exec(compile(open("fn").read(), "fn", 'exec'), glob, loc)"""
|
|
|
|
self.check(b, a)
|
|
|
|
|
|
|
|
b = """execfile("fn", globals=glob)"""
|
|
|
|
a = """exec(compile(open("fn").read(), "fn", 'exec'), globals=glob)"""
|
|
|
|
self.check(b, a)
|
|
|
|
|
|
|
|
b = """execfile("fn", locals=loc)"""
|
|
|
|
a = """exec(compile(open("fn").read(), "fn", 'exec'), locals=loc)"""
|
|
|
|
self.check(b, a)
|
|
|
|
|
|
|
|
b = """execfile("fn", globals=glob, locals=loc)"""
|
|
|
|
a = """exec(compile(open("fn").read(), "fn", 'exec'), globals=glob, locals=loc)"""
|
|
|
|
self.check(b, a)
|
|
|
|
|
|
|
|
def test_spacing(self):
|
|
|
|
b = """execfile( "fn" )"""
|
|
|
|
a = """exec(compile(open( "fn" ).read(), "fn", 'exec'))"""
|
|
|
|
self.check(b, a)
|
|
|
|
|
|
|
|
b = """execfile("fn", globals = glob)"""
|
|
|
|
a = """exec(compile(open("fn").read(), "fn", 'exec'), globals = glob)"""
|
|
|
|
self.check(b, a)
|
|
|
|
|
|
|
|
|
Merged revisions 67806 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk
................
r67806 | benjamin.peterson | 2008-12-15 21:35:28 -0600 (Mon, 15 Dec 2008) | 111 lines
Merged revisions 67427,67431,67433,67435,67630,67652,67656-67657,67674-67675,67678-67679,67705-67706,67716,67723,67765-67771,67774,67776,67778 via svnmerge from
svn+ssh://pythondev@svn.python.org/sandbox/trunk/2to3/lib2to3
........
r67427 | benjamin.peterson | 2008-11-28 16:07:41 -0600 (Fri, 28 Nov 2008) | 1 line
fix spelling in comment
........
r67431 | benjamin.peterson | 2008-11-28 17:14:08 -0600 (Fri, 28 Nov 2008) | 1 line
add a scripts directory; move things to it
........
r67433 | benjamin.peterson | 2008-11-28 17:18:48 -0600 (Fri, 28 Nov 2008) | 1 line
run svneol.py
........
r67435 | benjamin.peterson | 2008-11-28 17:25:03 -0600 (Fri, 28 Nov 2008) | 1 line
rename pre/post_order_mapping to pre/post_order_heads
........
r67630 | alexandre.vassalotti | 2008-12-06 21:51:56 -0600 (Sat, 06 Dec 2008) | 2 lines
Fix typo in the urllib2.HTTPDigestAuthHandler fixer.
........
r67652 | armin.ronacher | 2008-12-07 15:39:43 -0600 (Sun, 07 Dec 2008) | 5 lines
Added a fixer that cleans up a tuple argument to isinstance after the tokens
in it were fixed. This is mainly used to remove double occurrences of
tokens as a leftover of the long -> int / unicode -> str conversion.
........
r67656 | armin.ronacher | 2008-12-07 16:54:16 -0600 (Sun, 07 Dec 2008) | 3 lines
Added missing copyright fo 2to3 fix_isinstance.
........
r67657 | armin.ronacher | 2008-12-07 18:29:35 -0600 (Sun, 07 Dec 2008) | 3 lines
2to3: intern and reduce fixes now add the imports if missing. Because that is a common task the fixer_util module now has a function "touch_import" that adds imports if missing.
........
r67674 | benjamin.peterson | 2008-12-08 19:58:11 -0600 (Mon, 08 Dec 2008) | 1 line
copy permission bits when making backup files #4602
........
r67675 | benjamin.peterson | 2008-12-08 19:59:11 -0600 (Mon, 08 Dec 2008) | 1 line
add forgotten import
........
r67678 | benjamin.peterson | 2008-12-08 20:08:30 -0600 (Mon, 08 Dec 2008) | 1 line
fix #4602 for real
........
r67679 | armin.ronacher | 2008-12-09 00:54:03 -0600 (Tue, 09 Dec 2008) | 3 lines
Removed redudant code from the 2to3 long fixer. This fixes #4590.
........
r67705 | benjamin.peterson | 2008-12-11 13:04:08 -0600 (Thu, 11 Dec 2008) | 1 line
put trailers after a range call after the list()
........
r67706 | benjamin.peterson | 2008-12-11 13:17:57 -0600 (Thu, 11 Dec 2008) | 1 line
add html related modules to the fix_imports mapping
........
r67716 | benjamin.peterson | 2008-12-11 22:16:47 -0600 (Thu, 11 Dec 2008) | 1 line
consolidate tests
........
r67723 | benjamin.peterson | 2008-12-12 19:49:31 -0600 (Fri, 12 Dec 2008) | 1 line
fix name
........
r67765 | benjamin.peterson | 2008-12-14 14:05:05 -0600 (Sun, 14 Dec 2008) | 1 line
run fix_isinstance after fix_long and fix_unicode
........
r67766 | benjamin.peterson | 2008-12-14 14:13:05 -0600 (Sun, 14 Dec 2008) | 1 line
use run_order instead of order
........
r67767 | benjamin.peterson | 2008-12-14 14:28:12 -0600 (Sun, 14 Dec 2008) | 1 line
don't retain parenthesis if there is only one item left
........
r67768 | benjamin.peterson | 2008-12-14 14:32:30 -0600 (Sun, 14 Dec 2008) | 1 line
use insert_child()
........
r67769 | benjamin.peterson | 2008-12-14 14:59:10 -0600 (Sun, 14 Dec 2008) | 1 line
parenthesize doesn't belong in pygram or FixerBase
........
r67770 | alexandre.vassalotti | 2008-12-14 15:15:36 -0600 (Sun, 14 Dec 2008) | 2 lines
Fix typo: html.paser -> html.parser.
........
r67771 | benjamin.peterson | 2008-12-14 15:22:09 -0600 (Sun, 14 Dec 2008) | 1 line
altering .children needs to call changed()
........
r67774 | benjamin.peterson | 2008-12-14 15:55:38 -0600 (Sun, 14 Dec 2008) | 1 line
employ an evil hack to fix multiple names in the same import statement
........
r67776 | benjamin.peterson | 2008-12-14 16:22:38 -0600 (Sun, 14 Dec 2008) | 1 line
make a common mixin class for Test_imports and friends
........
r67778 | alexandre.vassalotti | 2008-12-14 17:48:20 -0600 (Sun, 14 Dec 2008) | 2 lines
Make fix_imports refactor multiple imports as.
........
................
2008-12-15 23:57:54 -04:00
|
|
|
class Test_isinstance(FixerTestCase):
|
|
|
|
fixer = "isinstance"
|
|
|
|
|
|
|
|
def test_remove_multiple_items(self):
|
|
|
|
b = """isinstance(x, (int, int, int))"""
|
|
|
|
a = """isinstance(x, int)"""
|
2008-03-19 02:04:44 -03:00
|
|
|
self.check(b, a)
|
|
|
|
|
Merged revisions 67806 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk
................
r67806 | benjamin.peterson | 2008-12-15 21:35:28 -0600 (Mon, 15 Dec 2008) | 111 lines
Merged revisions 67427,67431,67433,67435,67630,67652,67656-67657,67674-67675,67678-67679,67705-67706,67716,67723,67765-67771,67774,67776,67778 via svnmerge from
svn+ssh://pythondev@svn.python.org/sandbox/trunk/2to3/lib2to3
........
r67427 | benjamin.peterson | 2008-11-28 16:07:41 -0600 (Fri, 28 Nov 2008) | 1 line
fix spelling in comment
........
r67431 | benjamin.peterson | 2008-11-28 17:14:08 -0600 (Fri, 28 Nov 2008) | 1 line
add a scripts directory; move things to it
........
r67433 | benjamin.peterson | 2008-11-28 17:18:48 -0600 (Fri, 28 Nov 2008) | 1 line
run svneol.py
........
r67435 | benjamin.peterson | 2008-11-28 17:25:03 -0600 (Fri, 28 Nov 2008) | 1 line
rename pre/post_order_mapping to pre/post_order_heads
........
r67630 | alexandre.vassalotti | 2008-12-06 21:51:56 -0600 (Sat, 06 Dec 2008) | 2 lines
Fix typo in the urllib2.HTTPDigestAuthHandler fixer.
........
r67652 | armin.ronacher | 2008-12-07 15:39:43 -0600 (Sun, 07 Dec 2008) | 5 lines
Added a fixer that cleans up a tuple argument to isinstance after the tokens
in it were fixed. This is mainly used to remove double occurrences of
tokens as a leftover of the long -> int / unicode -> str conversion.
........
r67656 | armin.ronacher | 2008-12-07 16:54:16 -0600 (Sun, 07 Dec 2008) | 3 lines
Added missing copyright fo 2to3 fix_isinstance.
........
r67657 | armin.ronacher | 2008-12-07 18:29:35 -0600 (Sun, 07 Dec 2008) | 3 lines
2to3: intern and reduce fixes now add the imports if missing. Because that is a common task the fixer_util module now has a function "touch_import" that adds imports if missing.
........
r67674 | benjamin.peterson | 2008-12-08 19:58:11 -0600 (Mon, 08 Dec 2008) | 1 line
copy permission bits when making backup files #4602
........
r67675 | benjamin.peterson | 2008-12-08 19:59:11 -0600 (Mon, 08 Dec 2008) | 1 line
add forgotten import
........
r67678 | benjamin.peterson | 2008-12-08 20:08:30 -0600 (Mon, 08 Dec 2008) | 1 line
fix #4602 for real
........
r67679 | armin.ronacher | 2008-12-09 00:54:03 -0600 (Tue, 09 Dec 2008) | 3 lines
Removed redudant code from the 2to3 long fixer. This fixes #4590.
........
r67705 | benjamin.peterson | 2008-12-11 13:04:08 -0600 (Thu, 11 Dec 2008) | 1 line
put trailers after a range call after the list()
........
r67706 | benjamin.peterson | 2008-12-11 13:17:57 -0600 (Thu, 11 Dec 2008) | 1 line
add html related modules to the fix_imports mapping
........
r67716 | benjamin.peterson | 2008-12-11 22:16:47 -0600 (Thu, 11 Dec 2008) | 1 line
consolidate tests
........
r67723 | benjamin.peterson | 2008-12-12 19:49:31 -0600 (Fri, 12 Dec 2008) | 1 line
fix name
........
r67765 | benjamin.peterson | 2008-12-14 14:05:05 -0600 (Sun, 14 Dec 2008) | 1 line
run fix_isinstance after fix_long and fix_unicode
........
r67766 | benjamin.peterson | 2008-12-14 14:13:05 -0600 (Sun, 14 Dec 2008) | 1 line
use run_order instead of order
........
r67767 | benjamin.peterson | 2008-12-14 14:28:12 -0600 (Sun, 14 Dec 2008) | 1 line
don't retain parenthesis if there is only one item left
........
r67768 | benjamin.peterson | 2008-12-14 14:32:30 -0600 (Sun, 14 Dec 2008) | 1 line
use insert_child()
........
r67769 | benjamin.peterson | 2008-12-14 14:59:10 -0600 (Sun, 14 Dec 2008) | 1 line
parenthesize doesn't belong in pygram or FixerBase
........
r67770 | alexandre.vassalotti | 2008-12-14 15:15:36 -0600 (Sun, 14 Dec 2008) | 2 lines
Fix typo: html.paser -> html.parser.
........
r67771 | benjamin.peterson | 2008-12-14 15:22:09 -0600 (Sun, 14 Dec 2008) | 1 line
altering .children needs to call changed()
........
r67774 | benjamin.peterson | 2008-12-14 15:55:38 -0600 (Sun, 14 Dec 2008) | 1 line
employ an evil hack to fix multiple names in the same import statement
........
r67776 | benjamin.peterson | 2008-12-14 16:22:38 -0600 (Sun, 14 Dec 2008) | 1 line
make a common mixin class for Test_imports and friends
........
r67778 | alexandre.vassalotti | 2008-12-14 17:48:20 -0600 (Sun, 14 Dec 2008) | 2 lines
Make fix_imports refactor multiple imports as.
........
................
2008-12-15 23:57:54 -04:00
|
|
|
b = """isinstance(x, (int, float, int, int, float))"""
|
|
|
|
a = """isinstance(x, (int, float))"""
|
|
|
|
self.check(b, a)
|
2008-03-19 02:04:44 -03:00
|
|
|
|
Merged revisions 67806 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk
................
r67806 | benjamin.peterson | 2008-12-15 21:35:28 -0600 (Mon, 15 Dec 2008) | 111 lines
Merged revisions 67427,67431,67433,67435,67630,67652,67656-67657,67674-67675,67678-67679,67705-67706,67716,67723,67765-67771,67774,67776,67778 via svnmerge from
svn+ssh://pythondev@svn.python.org/sandbox/trunk/2to3/lib2to3
........
r67427 | benjamin.peterson | 2008-11-28 16:07:41 -0600 (Fri, 28 Nov 2008) | 1 line
fix spelling in comment
........
r67431 | benjamin.peterson | 2008-11-28 17:14:08 -0600 (Fri, 28 Nov 2008) | 1 line
add a scripts directory; move things to it
........
r67433 | benjamin.peterson | 2008-11-28 17:18:48 -0600 (Fri, 28 Nov 2008) | 1 line
run svneol.py
........
r67435 | benjamin.peterson | 2008-11-28 17:25:03 -0600 (Fri, 28 Nov 2008) | 1 line
rename pre/post_order_mapping to pre/post_order_heads
........
r67630 | alexandre.vassalotti | 2008-12-06 21:51:56 -0600 (Sat, 06 Dec 2008) | 2 lines
Fix typo in the urllib2.HTTPDigestAuthHandler fixer.
........
r67652 | armin.ronacher | 2008-12-07 15:39:43 -0600 (Sun, 07 Dec 2008) | 5 lines
Added a fixer that cleans up a tuple argument to isinstance after the tokens
in it were fixed. This is mainly used to remove double occurrences of
tokens as a leftover of the long -> int / unicode -> str conversion.
........
r67656 | armin.ronacher | 2008-12-07 16:54:16 -0600 (Sun, 07 Dec 2008) | 3 lines
Added missing copyright fo 2to3 fix_isinstance.
........
r67657 | armin.ronacher | 2008-12-07 18:29:35 -0600 (Sun, 07 Dec 2008) | 3 lines
2to3: intern and reduce fixes now add the imports if missing. Because that is a common task the fixer_util module now has a function "touch_import" that adds imports if missing.
........
r67674 | benjamin.peterson | 2008-12-08 19:58:11 -0600 (Mon, 08 Dec 2008) | 1 line
copy permission bits when making backup files #4602
........
r67675 | benjamin.peterson | 2008-12-08 19:59:11 -0600 (Mon, 08 Dec 2008) | 1 line
add forgotten import
........
r67678 | benjamin.peterson | 2008-12-08 20:08:30 -0600 (Mon, 08 Dec 2008) | 1 line
fix #4602 for real
........
r67679 | armin.ronacher | 2008-12-09 00:54:03 -0600 (Tue, 09 Dec 2008) | 3 lines
Removed redudant code from the 2to3 long fixer. This fixes #4590.
........
r67705 | benjamin.peterson | 2008-12-11 13:04:08 -0600 (Thu, 11 Dec 2008) | 1 line
put trailers after a range call after the list()
........
r67706 | benjamin.peterson | 2008-12-11 13:17:57 -0600 (Thu, 11 Dec 2008) | 1 line
add html related modules to the fix_imports mapping
........
r67716 | benjamin.peterson | 2008-12-11 22:16:47 -0600 (Thu, 11 Dec 2008) | 1 line
consolidate tests
........
r67723 | benjamin.peterson | 2008-12-12 19:49:31 -0600 (Fri, 12 Dec 2008) | 1 line
fix name
........
r67765 | benjamin.peterson | 2008-12-14 14:05:05 -0600 (Sun, 14 Dec 2008) | 1 line
run fix_isinstance after fix_long and fix_unicode
........
r67766 | benjamin.peterson | 2008-12-14 14:13:05 -0600 (Sun, 14 Dec 2008) | 1 line
use run_order instead of order
........
r67767 | benjamin.peterson | 2008-12-14 14:28:12 -0600 (Sun, 14 Dec 2008) | 1 line
don't retain parenthesis if there is only one item left
........
r67768 | benjamin.peterson | 2008-12-14 14:32:30 -0600 (Sun, 14 Dec 2008) | 1 line
use insert_child()
........
r67769 | benjamin.peterson | 2008-12-14 14:59:10 -0600 (Sun, 14 Dec 2008) | 1 line
parenthesize doesn't belong in pygram or FixerBase
........
r67770 | alexandre.vassalotti | 2008-12-14 15:15:36 -0600 (Sun, 14 Dec 2008) | 2 lines
Fix typo: html.paser -> html.parser.
........
r67771 | benjamin.peterson | 2008-12-14 15:22:09 -0600 (Sun, 14 Dec 2008) | 1 line
altering .children needs to call changed()
........
r67774 | benjamin.peterson | 2008-12-14 15:55:38 -0600 (Sun, 14 Dec 2008) | 1 line
employ an evil hack to fix multiple names in the same import statement
........
r67776 | benjamin.peterson | 2008-12-14 16:22:38 -0600 (Sun, 14 Dec 2008) | 1 line
make a common mixin class for Test_imports and friends
........
r67778 | alexandre.vassalotti | 2008-12-14 17:48:20 -0600 (Sun, 14 Dec 2008) | 2 lines
Make fix_imports refactor multiple imports as.
........
................
2008-12-15 23:57:54 -04:00
|
|
|
b = """isinstance(x, (int, float, int, int, float, str))"""
|
|
|
|
a = """isinstance(x, (int, float, str))"""
|
|
|
|
self.check(b, a)
|
2008-03-19 02:04:44 -03:00
|
|
|
|
Merged revisions 67806 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk
................
r67806 | benjamin.peterson | 2008-12-15 21:35:28 -0600 (Mon, 15 Dec 2008) | 111 lines
Merged revisions 67427,67431,67433,67435,67630,67652,67656-67657,67674-67675,67678-67679,67705-67706,67716,67723,67765-67771,67774,67776,67778 via svnmerge from
svn+ssh://pythondev@svn.python.org/sandbox/trunk/2to3/lib2to3
........
r67427 | benjamin.peterson | 2008-11-28 16:07:41 -0600 (Fri, 28 Nov 2008) | 1 line
fix spelling in comment
........
r67431 | benjamin.peterson | 2008-11-28 17:14:08 -0600 (Fri, 28 Nov 2008) | 1 line
add a scripts directory; move things to it
........
r67433 | benjamin.peterson | 2008-11-28 17:18:48 -0600 (Fri, 28 Nov 2008) | 1 line
run svneol.py
........
r67435 | benjamin.peterson | 2008-11-28 17:25:03 -0600 (Fri, 28 Nov 2008) | 1 line
rename pre/post_order_mapping to pre/post_order_heads
........
r67630 | alexandre.vassalotti | 2008-12-06 21:51:56 -0600 (Sat, 06 Dec 2008) | 2 lines
Fix typo in the urllib2.HTTPDigestAuthHandler fixer.
........
r67652 | armin.ronacher | 2008-12-07 15:39:43 -0600 (Sun, 07 Dec 2008) | 5 lines
Added a fixer that cleans up a tuple argument to isinstance after the tokens
in it were fixed. This is mainly used to remove double occurrences of
tokens as a leftover of the long -> int / unicode -> str conversion.
........
r67656 | armin.ronacher | 2008-12-07 16:54:16 -0600 (Sun, 07 Dec 2008) | 3 lines
Added missing copyright fo 2to3 fix_isinstance.
........
r67657 | armin.ronacher | 2008-12-07 18:29:35 -0600 (Sun, 07 Dec 2008) | 3 lines
2to3: intern and reduce fixes now add the imports if missing. Because that is a common task the fixer_util module now has a function "touch_import" that adds imports if missing.
........
r67674 | benjamin.peterson | 2008-12-08 19:58:11 -0600 (Mon, 08 Dec 2008) | 1 line
copy permission bits when making backup files #4602
........
r67675 | benjamin.peterson | 2008-12-08 19:59:11 -0600 (Mon, 08 Dec 2008) | 1 line
add forgotten import
........
r67678 | benjamin.peterson | 2008-12-08 20:08:30 -0600 (Mon, 08 Dec 2008) | 1 line
fix #4602 for real
........
r67679 | armin.ronacher | 2008-12-09 00:54:03 -0600 (Tue, 09 Dec 2008) | 3 lines
Removed redudant code from the 2to3 long fixer. This fixes #4590.
........
r67705 | benjamin.peterson | 2008-12-11 13:04:08 -0600 (Thu, 11 Dec 2008) | 1 line
put trailers after a range call after the list()
........
r67706 | benjamin.peterson | 2008-12-11 13:17:57 -0600 (Thu, 11 Dec 2008) | 1 line
add html related modules to the fix_imports mapping
........
r67716 | benjamin.peterson | 2008-12-11 22:16:47 -0600 (Thu, 11 Dec 2008) | 1 line
consolidate tests
........
r67723 | benjamin.peterson | 2008-12-12 19:49:31 -0600 (Fri, 12 Dec 2008) | 1 line
fix name
........
r67765 | benjamin.peterson | 2008-12-14 14:05:05 -0600 (Sun, 14 Dec 2008) | 1 line
run fix_isinstance after fix_long and fix_unicode
........
r67766 | benjamin.peterson | 2008-12-14 14:13:05 -0600 (Sun, 14 Dec 2008) | 1 line
use run_order instead of order
........
r67767 | benjamin.peterson | 2008-12-14 14:28:12 -0600 (Sun, 14 Dec 2008) | 1 line
don't retain parenthesis if there is only one item left
........
r67768 | benjamin.peterson | 2008-12-14 14:32:30 -0600 (Sun, 14 Dec 2008) | 1 line
use insert_child()
........
r67769 | benjamin.peterson | 2008-12-14 14:59:10 -0600 (Sun, 14 Dec 2008) | 1 line
parenthesize doesn't belong in pygram or FixerBase
........
r67770 | alexandre.vassalotti | 2008-12-14 15:15:36 -0600 (Sun, 14 Dec 2008) | 2 lines
Fix typo: html.paser -> html.parser.
........
r67771 | benjamin.peterson | 2008-12-14 15:22:09 -0600 (Sun, 14 Dec 2008) | 1 line
altering .children needs to call changed()
........
r67774 | benjamin.peterson | 2008-12-14 15:55:38 -0600 (Sun, 14 Dec 2008) | 1 line
employ an evil hack to fix multiple names in the same import statement
........
r67776 | benjamin.peterson | 2008-12-14 16:22:38 -0600 (Sun, 14 Dec 2008) | 1 line
make a common mixin class for Test_imports and friends
........
r67778 | alexandre.vassalotti | 2008-12-14 17:48:20 -0600 (Sun, 14 Dec 2008) | 2 lines
Make fix_imports refactor multiple imports as.
........
................
2008-12-15 23:57:54 -04:00
|
|
|
b = """isinstance(foo() + bar(), (x(), y(), x(), int, int))"""
|
|
|
|
a = """isinstance(foo() + bar(), (x(), y(), x(), int))"""
|
|
|
|
self.check(b, a)
|
2008-03-19 02:04:44 -03:00
|
|
|
|
|
|
|
def test_prefix_preservation(self):
|
Merged revisions 67806 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk
................
r67806 | benjamin.peterson | 2008-12-15 21:35:28 -0600 (Mon, 15 Dec 2008) | 111 lines
Merged revisions 67427,67431,67433,67435,67630,67652,67656-67657,67674-67675,67678-67679,67705-67706,67716,67723,67765-67771,67774,67776,67778 via svnmerge from
svn+ssh://pythondev@svn.python.org/sandbox/trunk/2to3/lib2to3
........
r67427 | benjamin.peterson | 2008-11-28 16:07:41 -0600 (Fri, 28 Nov 2008) | 1 line
fix spelling in comment
........
r67431 | benjamin.peterson | 2008-11-28 17:14:08 -0600 (Fri, 28 Nov 2008) | 1 line
add a scripts directory; move things to it
........
r67433 | benjamin.peterson | 2008-11-28 17:18:48 -0600 (Fri, 28 Nov 2008) | 1 line
run svneol.py
........
r67435 | benjamin.peterson | 2008-11-28 17:25:03 -0600 (Fri, 28 Nov 2008) | 1 line
rename pre/post_order_mapping to pre/post_order_heads
........
r67630 | alexandre.vassalotti | 2008-12-06 21:51:56 -0600 (Sat, 06 Dec 2008) | 2 lines
Fix typo in the urllib2.HTTPDigestAuthHandler fixer.
........
r67652 | armin.ronacher | 2008-12-07 15:39:43 -0600 (Sun, 07 Dec 2008) | 5 lines
Added a fixer that cleans up a tuple argument to isinstance after the tokens
in it were fixed. This is mainly used to remove double occurrences of
tokens as a leftover of the long -> int / unicode -> str conversion.
........
r67656 | armin.ronacher | 2008-12-07 16:54:16 -0600 (Sun, 07 Dec 2008) | 3 lines
Added missing copyright fo 2to3 fix_isinstance.
........
r67657 | armin.ronacher | 2008-12-07 18:29:35 -0600 (Sun, 07 Dec 2008) | 3 lines
2to3: intern and reduce fixes now add the imports if missing. Because that is a common task the fixer_util module now has a function "touch_import" that adds imports if missing.
........
r67674 | benjamin.peterson | 2008-12-08 19:58:11 -0600 (Mon, 08 Dec 2008) | 1 line
copy permission bits when making backup files #4602
........
r67675 | benjamin.peterson | 2008-12-08 19:59:11 -0600 (Mon, 08 Dec 2008) | 1 line
add forgotten import
........
r67678 | benjamin.peterson | 2008-12-08 20:08:30 -0600 (Mon, 08 Dec 2008) | 1 line
fix #4602 for real
........
r67679 | armin.ronacher | 2008-12-09 00:54:03 -0600 (Tue, 09 Dec 2008) | 3 lines
Removed redudant code from the 2to3 long fixer. This fixes #4590.
........
r67705 | benjamin.peterson | 2008-12-11 13:04:08 -0600 (Thu, 11 Dec 2008) | 1 line
put trailers after a range call after the list()
........
r67706 | benjamin.peterson | 2008-12-11 13:17:57 -0600 (Thu, 11 Dec 2008) | 1 line
add html related modules to the fix_imports mapping
........
r67716 | benjamin.peterson | 2008-12-11 22:16:47 -0600 (Thu, 11 Dec 2008) | 1 line
consolidate tests
........
r67723 | benjamin.peterson | 2008-12-12 19:49:31 -0600 (Fri, 12 Dec 2008) | 1 line
fix name
........
r67765 | benjamin.peterson | 2008-12-14 14:05:05 -0600 (Sun, 14 Dec 2008) | 1 line
run fix_isinstance after fix_long and fix_unicode
........
r67766 | benjamin.peterson | 2008-12-14 14:13:05 -0600 (Sun, 14 Dec 2008) | 1 line
use run_order instead of order
........
r67767 | benjamin.peterson | 2008-12-14 14:28:12 -0600 (Sun, 14 Dec 2008) | 1 line
don't retain parenthesis if there is only one item left
........
r67768 | benjamin.peterson | 2008-12-14 14:32:30 -0600 (Sun, 14 Dec 2008) | 1 line
use insert_child()
........
r67769 | benjamin.peterson | 2008-12-14 14:59:10 -0600 (Sun, 14 Dec 2008) | 1 line
parenthesize doesn't belong in pygram or FixerBase
........
r67770 | alexandre.vassalotti | 2008-12-14 15:15:36 -0600 (Sun, 14 Dec 2008) | 2 lines
Fix typo: html.paser -> html.parser.
........
r67771 | benjamin.peterson | 2008-12-14 15:22:09 -0600 (Sun, 14 Dec 2008) | 1 line
altering .children needs to call changed()
........
r67774 | benjamin.peterson | 2008-12-14 15:55:38 -0600 (Sun, 14 Dec 2008) | 1 line
employ an evil hack to fix multiple names in the same import statement
........
r67776 | benjamin.peterson | 2008-12-14 16:22:38 -0600 (Sun, 14 Dec 2008) | 1 line
make a common mixin class for Test_imports and friends
........
r67778 | alexandre.vassalotti | 2008-12-14 17:48:20 -0600 (Sun, 14 Dec 2008) | 2 lines
Make fix_imports refactor multiple imports as.
........
................
2008-12-15 23:57:54 -04:00
|
|
|
b = """if isinstance( foo(), ( bar, bar, baz )) : pass"""
|
|
|
|
a = """if isinstance( foo(), ( bar, baz )) : pass"""
|
2008-03-19 02:04:44 -03:00
|
|
|
self.check(b, a)
|
|
|
|
|
Merged revisions 67806 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk
................
r67806 | benjamin.peterson | 2008-12-15 21:35:28 -0600 (Mon, 15 Dec 2008) | 111 lines
Merged revisions 67427,67431,67433,67435,67630,67652,67656-67657,67674-67675,67678-67679,67705-67706,67716,67723,67765-67771,67774,67776,67778 via svnmerge from
svn+ssh://pythondev@svn.python.org/sandbox/trunk/2to3/lib2to3
........
r67427 | benjamin.peterson | 2008-11-28 16:07:41 -0600 (Fri, 28 Nov 2008) | 1 line
fix spelling in comment
........
r67431 | benjamin.peterson | 2008-11-28 17:14:08 -0600 (Fri, 28 Nov 2008) | 1 line
add a scripts directory; move things to it
........
r67433 | benjamin.peterson | 2008-11-28 17:18:48 -0600 (Fri, 28 Nov 2008) | 1 line
run svneol.py
........
r67435 | benjamin.peterson | 2008-11-28 17:25:03 -0600 (Fri, 28 Nov 2008) | 1 line
rename pre/post_order_mapping to pre/post_order_heads
........
r67630 | alexandre.vassalotti | 2008-12-06 21:51:56 -0600 (Sat, 06 Dec 2008) | 2 lines
Fix typo in the urllib2.HTTPDigestAuthHandler fixer.
........
r67652 | armin.ronacher | 2008-12-07 15:39:43 -0600 (Sun, 07 Dec 2008) | 5 lines
Added a fixer that cleans up a tuple argument to isinstance after the tokens
in it were fixed. This is mainly used to remove double occurrences of
tokens as a leftover of the long -> int / unicode -> str conversion.
........
r67656 | armin.ronacher | 2008-12-07 16:54:16 -0600 (Sun, 07 Dec 2008) | 3 lines
Added missing copyright fo 2to3 fix_isinstance.
........
r67657 | armin.ronacher | 2008-12-07 18:29:35 -0600 (Sun, 07 Dec 2008) | 3 lines
2to3: intern and reduce fixes now add the imports if missing. Because that is a common task the fixer_util module now has a function "touch_import" that adds imports if missing.
........
r67674 | benjamin.peterson | 2008-12-08 19:58:11 -0600 (Mon, 08 Dec 2008) | 1 line
copy permission bits when making backup files #4602
........
r67675 | benjamin.peterson | 2008-12-08 19:59:11 -0600 (Mon, 08 Dec 2008) | 1 line
add forgotten import
........
r67678 | benjamin.peterson | 2008-12-08 20:08:30 -0600 (Mon, 08 Dec 2008) | 1 line
fix #4602 for real
........
r67679 | armin.ronacher | 2008-12-09 00:54:03 -0600 (Tue, 09 Dec 2008) | 3 lines
Removed redudant code from the 2to3 long fixer. This fixes #4590.
........
r67705 | benjamin.peterson | 2008-12-11 13:04:08 -0600 (Thu, 11 Dec 2008) | 1 line
put trailers after a range call after the list()
........
r67706 | benjamin.peterson | 2008-12-11 13:17:57 -0600 (Thu, 11 Dec 2008) | 1 line
add html related modules to the fix_imports mapping
........
r67716 | benjamin.peterson | 2008-12-11 22:16:47 -0600 (Thu, 11 Dec 2008) | 1 line
consolidate tests
........
r67723 | benjamin.peterson | 2008-12-12 19:49:31 -0600 (Fri, 12 Dec 2008) | 1 line
fix name
........
r67765 | benjamin.peterson | 2008-12-14 14:05:05 -0600 (Sun, 14 Dec 2008) | 1 line
run fix_isinstance after fix_long and fix_unicode
........
r67766 | benjamin.peterson | 2008-12-14 14:13:05 -0600 (Sun, 14 Dec 2008) | 1 line
use run_order instead of order
........
r67767 | benjamin.peterson | 2008-12-14 14:28:12 -0600 (Sun, 14 Dec 2008) | 1 line
don't retain parenthesis if there is only one item left
........
r67768 | benjamin.peterson | 2008-12-14 14:32:30 -0600 (Sun, 14 Dec 2008) | 1 line
use insert_child()
........
r67769 | benjamin.peterson | 2008-12-14 14:59:10 -0600 (Sun, 14 Dec 2008) | 1 line
parenthesize doesn't belong in pygram or FixerBase
........
r67770 | alexandre.vassalotti | 2008-12-14 15:15:36 -0600 (Sun, 14 Dec 2008) | 2 lines
Fix typo: html.paser -> html.parser.
........
r67771 | benjamin.peterson | 2008-12-14 15:22:09 -0600 (Sun, 14 Dec 2008) | 1 line
altering .children needs to call changed()
........
r67774 | benjamin.peterson | 2008-12-14 15:55:38 -0600 (Sun, 14 Dec 2008) | 1 line
employ an evil hack to fix multiple names in the same import statement
........
r67776 | benjamin.peterson | 2008-12-14 16:22:38 -0600 (Sun, 14 Dec 2008) | 1 line
make a common mixin class for Test_imports and friends
........
r67778 | alexandre.vassalotti | 2008-12-14 17:48:20 -0600 (Sun, 14 Dec 2008) | 2 lines
Make fix_imports refactor multiple imports as.
........
................
2008-12-15 23:57:54 -04:00
|
|
|
def test_unchanged(self):
|
|
|
|
self.unchanged("isinstance(x, (str, int))")
|
|
|
|
|
2008-03-19 02:04:44 -03:00
|
|
|
class Test_dict(FixerTestCase):
|
|
|
|
fixer = "dict"
|
|
|
|
|
|
|
|
def test_prefix_preservation(self):
|
|
|
|
b = "if d. keys ( ) : pass"
|
|
|
|
a = "if list(d. keys ( )) : pass"
|
|
|
|
self.check(b, a)
|
|
|
|
|
|
|
|
b = "if d. items ( ) : pass"
|
|
|
|
a = "if list(d. items ( )) : pass"
|
|
|
|
self.check(b, a)
|
|
|
|
|
|
|
|
b = "if d. iterkeys ( ) : pass"
|
|
|
|
a = "if iter(d. keys ( )) : pass"
|
|
|
|
self.check(b, a)
|
|
|
|
|
|
|
|
b = "[i for i in d. iterkeys( ) ]"
|
|
|
|
a = "[i for i in d. keys( ) ]"
|
|
|
|
self.check(b, a)
|
|
|
|
|
2010-01-30 07:22:26 -04:00
|
|
|
b = "if d. viewkeys ( ) : pass"
|
|
|
|
a = "if d. keys ( ) : pass"
|
|
|
|
self.check(b, a)
|
|
|
|
|
|
|
|
b = "[i for i in d. viewkeys( ) ]"
|
|
|
|
a = "[i for i in d. keys( ) ]"
|
|
|
|
self.check(b, a)
|
|
|
|
|
2008-03-19 02:04:44 -03:00
|
|
|
def test_trailing_comment(self):
|
|
|
|
b = "d.keys() # foo"
|
|
|
|
a = "list(d.keys()) # foo"
|
|
|
|
self.check(b, a)
|
|
|
|
|
|
|
|
b = "d.items() # foo"
|
|
|
|
a = "list(d.items()) # foo"
|
|
|
|
self.check(b, a)
|
|
|
|
|
|
|
|
b = "d.iterkeys() # foo"
|
|
|
|
a = "iter(d.keys()) # foo"
|
|
|
|
self.check(b, a)
|
|
|
|
|
|
|
|
b = """[i for i in d.iterkeys() # foo
|
|
|
|
]"""
|
|
|
|
a = """[i for i in d.keys() # foo
|
|
|
|
]"""
|
|
|
|
self.check(b, a)
|
|
|
|
|
2010-01-30 07:22:26 -04:00
|
|
|
b = """[i for i in d.iterkeys() # foo
|
|
|
|
]"""
|
|
|
|
a = """[i for i in d.keys() # foo
|
|
|
|
]"""
|
|
|
|
self.check(b, a)
|
|
|
|
|
|
|
|
b = "d.viewitems() # foo"
|
|
|
|
a = "d.items() # foo"
|
|
|
|
self.check(b, a)
|
|
|
|
|
2008-03-19 02:04:44 -03:00
|
|
|
def test_unchanged(self):
|
Merged revisions 64286 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk
................
r64286 | benjamin.peterson | 2008-06-14 21:31:05 -0500 (Sat, 14 Jun 2008) | 49 lines
Merged revisions 63661,63666,63695,63711,63729,63769,63790,63880,63886 via svnmerge from
svn+ssh://pythondev@svn.python.org/sandbox/trunk/2to3/lib2to3
........
r63661 | georg.brandl | 2008-05-26 05:26:20 -0500 (Mon, 26 May 2008) | 2 lines
Add import fixes for dbm package.
........
r63666 | georg.brandl | 2008-05-26 05:49:09 -0500 (Mon, 26 May 2008) | 2 lines
Add xmlrpc package fixes.
........
r63695 | georg.brandl | 2008-05-26 10:14:33 -0500 (Mon, 26 May 2008) | 2 lines
Add fixer entries for http package.
........
r63711 | benjamin.peterson | 2008-05-26 13:43:51 -0500 (Mon, 26 May 2008) | 2 lines
add import mapping for test.test_support -> test.support
........
r63729 | benjamin.peterson | 2008-05-26 16:31:03 -0500 (Mon, 26 May 2008) | 2 lines
mapping for commands module -> subprocess
........
r63769 | brett.cannon | 2008-05-29 00:13:13 -0500 (Thu, 29 May 2008) | 1 line
Fixer for UserString.UserString over to the collections module.
........
r63790 | brett.cannon | 2008-05-29 14:13:51 -0500 (Thu, 29 May 2008) | 4 lines
Add a fixer for UserList.
Closes issue #2878. Thanks to Quentin Gallet-Gilles for the patch.
........
r63880 | collin.winter | 2008-06-01 18:09:38 -0500 (Sun, 01 Jun 2008) | 6 lines
Move lib2to3/fixes/{basefix,util}.py down to lib2to3/.
This is step 1 of turning lib2to3/ into a general-purpose refactoring
library, reusable by other projects.
........
r63886 | collin.winter | 2008-06-01 22:15:01 -0500 (Sun, 01 Jun 2008) | 5 lines
Allow refactoring tools to specify a directory for fixer modules.
This is step 2 of turning lib2to3/ into a general-purpose refactoring
library, reusable by other projects. Step 1: r63880.
........
................
2008-06-14 23:57:40 -03:00
|
|
|
for wrapper in fixer_util.consuming_calls:
|
2008-03-19 02:04:44 -03:00
|
|
|
s = "s = %s(d.keys())" % wrapper
|
|
|
|
self.unchanged(s)
|
|
|
|
|
|
|
|
s = "s = %s(d.values())" % wrapper
|
|
|
|
self.unchanged(s)
|
|
|
|
|
|
|
|
s = "s = %s(d.items())" % wrapper
|
|
|
|
self.unchanged(s)
|
|
|
|
|
|
|
|
def test_01(self):
|
|
|
|
b = "d.keys()"
|
|
|
|
a = "list(d.keys())"
|
|
|
|
self.check(b, a)
|
|
|
|
|
|
|
|
b = "a[0].foo().keys()"
|
|
|
|
a = "list(a[0].foo().keys())"
|
|
|
|
self.check(b, a)
|
|
|
|
|
|
|
|
def test_02(self):
|
|
|
|
b = "d.items()"
|
|
|
|
a = "list(d.items())"
|
|
|
|
self.check(b, a)
|
|
|
|
|
|
|
|
def test_03(self):
|
|
|
|
b = "d.values()"
|
|
|
|
a = "list(d.values())"
|
|
|
|
self.check(b, a)
|
|
|
|
|
|
|
|
def test_04(self):
|
|
|
|
b = "d.iterkeys()"
|
|
|
|
a = "iter(d.keys())"
|
|
|
|
self.check(b, a)
|
|
|
|
|
|
|
|
def test_05(self):
|
|
|
|
b = "d.iteritems()"
|
|
|
|
a = "iter(d.items())"
|
|
|
|
self.check(b, a)
|
|
|
|
|
|
|
|
def test_06(self):
|
|
|
|
b = "d.itervalues()"
|
|
|
|
a = "iter(d.values())"
|
|
|
|
self.check(b, a)
|
|
|
|
|
|
|
|
def test_07(self):
|
|
|
|
s = "list(d.keys())"
|
|
|
|
self.unchanged(s)
|
|
|
|
|
|
|
|
def test_08(self):
|
|
|
|
s = "sorted(d.keys())"
|
|
|
|
self.unchanged(s)
|
|
|
|
|
|
|
|
def test_09(self):
|
|
|
|
b = "iter(d.keys())"
|
|
|
|
a = "iter(list(d.keys()))"
|
|
|
|
self.check(b, a)
|
|
|
|
|
|
|
|
def test_10(self):
|
|
|
|
b = "foo(d.keys())"
|
|
|
|
a = "foo(list(d.keys()))"
|
|
|
|
self.check(b, a)
|
|
|
|
|
|
|
|
def test_11(self):
|
|
|
|
b = "for i in d.keys(): print i"
|
|
|
|
a = "for i in list(d.keys()): print i"
|
|
|
|
self.check(b, a)
|
|
|
|
|
|
|
|
def test_12(self):
|
|
|
|
b = "for i in d.iterkeys(): print i"
|
|
|
|
a = "for i in d.keys(): print i"
|
|
|
|
self.check(b, a)
|
|
|
|
|
|
|
|
def test_13(self):
|
|
|
|
b = "[i for i in d.keys()]"
|
|
|
|
a = "[i for i in list(d.keys())]"
|
|
|
|
self.check(b, a)
|
|
|
|
|
|
|
|
def test_14(self):
|
|
|
|
b = "[i for i in d.iterkeys()]"
|
|
|
|
a = "[i for i in d.keys()]"
|
|
|
|
self.check(b, a)
|
|
|
|
|
|
|
|
def test_15(self):
|
|
|
|
b = "(i for i in d.keys())"
|
|
|
|
a = "(i for i in list(d.keys()))"
|
|
|
|
self.check(b, a)
|
|
|
|
|
|
|
|
def test_16(self):
|
|
|
|
b = "(i for i in d.iterkeys())"
|
|
|
|
a = "(i for i in d.keys())"
|
|
|
|
self.check(b, a)
|
|
|
|
|
|
|
|
def test_17(self):
|
|
|
|
b = "iter(d.iterkeys())"
|
|
|
|
a = "iter(d.keys())"
|
|
|
|
self.check(b, a)
|
|
|
|
|
|
|
|
def test_18(self):
|
|
|
|
b = "list(d.iterkeys())"
|
|
|
|
a = "list(d.keys())"
|
|
|
|
self.check(b, a)
|
|
|
|
|
|
|
|
def test_19(self):
|
|
|
|
b = "sorted(d.iterkeys())"
|
|
|
|
a = "sorted(d.keys())"
|
|
|
|
self.check(b, a)
|
|
|
|
|
|
|
|
def test_20(self):
|
|
|
|
b = "foo(d.iterkeys())"
|
|
|
|
a = "foo(iter(d.keys()))"
|
|
|
|
self.check(b, a)
|
|
|
|
|
|
|
|
def test_21(self):
|
|
|
|
b = "print h.iterkeys().next()"
|
|
|
|
a = "print iter(h.keys()).next()"
|
|
|
|
self.check(b, a)
|
|
|
|
|
|
|
|
def test_22(self):
|
|
|
|
b = "print h.keys()[0]"
|
|
|
|
a = "print list(h.keys())[0]"
|
|
|
|
self.check(b, a)
|
|
|
|
|
|
|
|
def test_23(self):
|
|
|
|
b = "print list(h.iterkeys().next())"
|
|
|
|
a = "print list(iter(h.keys()).next())"
|
|
|
|
self.check(b, a)
|
|
|
|
|
|
|
|
def test_24(self):
|
|
|
|
b = "for x in h.keys()[0]: print x"
|
|
|
|
a = "for x in list(h.keys())[0]: print x"
|
|
|
|
self.check(b, a)
|
|
|
|
|
2010-01-30 07:22:26 -04:00
|
|
|
def test_25(self):
|
|
|
|
b = "d.viewkeys()"
|
|
|
|
a = "d.keys()"
|
|
|
|
self.check(b, a)
|
|
|
|
|
|
|
|
def test_26(self):
|
|
|
|
b = "d.viewitems()"
|
|
|
|
a = "d.items()"
|
|
|
|
self.check(b, a)
|
|
|
|
|
|
|
|
def test_27(self):
|
|
|
|
b = "d.viewvalues()"
|
|
|
|
a = "d.values()"
|
|
|
|
self.check(b, a)
|
|
|
|
|
|
|
|
def test_14(self):
|
|
|
|
b = "[i for i in d.viewkeys()]"
|
|
|
|
a = "[i for i in d.keys()]"
|
|
|
|
self.check(b, a)
|
|
|
|
|
|
|
|
def test_15(self):
|
|
|
|
b = "(i for i in d.viewkeys())"
|
|
|
|
a = "(i for i in d.keys())"
|
|
|
|
self.check(b, a)
|
|
|
|
|
|
|
|
def test_17(self):
|
|
|
|
b = "iter(d.viewkeys())"
|
|
|
|
a = "iter(d.keys())"
|
|
|
|
self.check(b, a)
|
|
|
|
|
|
|
|
def test_18(self):
|
|
|
|
b = "list(d.viewkeys())"
|
|
|
|
a = "list(d.keys())"
|
|
|
|
self.check(b, a)
|
|
|
|
|
|
|
|
def test_19(self):
|
|
|
|
b = "sorted(d.viewkeys())"
|
|
|
|
a = "sorted(d.keys())"
|
|
|
|
self.check(b, a)
|
|
|
|
|
2008-03-19 02:04:44 -03:00
|
|
|
class Test_xrange(FixerTestCase):
|
|
|
|
fixer = "xrange"
|
|
|
|
|
|
|
|
def test_prefix_preservation(self):
|
|
|
|
b = """x = xrange( 10 )"""
|
|
|
|
a = """x = range( 10 )"""
|
|
|
|
self.check(b, a)
|
|
|
|
|
|
|
|
b = """x = xrange( 1 , 10 )"""
|
|
|
|
a = """x = range( 1 , 10 )"""
|
|
|
|
self.check(b, a)
|
|
|
|
|
|
|
|
b = """x = xrange( 0 , 10 , 2 )"""
|
|
|
|
a = """x = range( 0 , 10 , 2 )"""
|
|
|
|
self.check(b, a)
|
|
|
|
|
2008-04-09 23:50:50 -03:00
|
|
|
def test_single_arg(self):
|
2008-03-19 02:04:44 -03:00
|
|
|
b = """x = xrange(10)"""
|
|
|
|
a = """x = range(10)"""
|
|
|
|
self.check(b, a)
|
|
|
|
|
2008-04-09 23:50:50 -03:00
|
|
|
def test_two_args(self):
|
2008-03-19 02:04:44 -03:00
|
|
|
b = """x = xrange(1, 10)"""
|
|
|
|
a = """x = range(1, 10)"""
|
|
|
|
self.check(b, a)
|
|
|
|
|
2008-04-09 23:50:50 -03:00
|
|
|
def test_three_args(self):
|
2008-03-19 02:04:44 -03:00
|
|
|
b = """x = xrange(0, 10, 2)"""
|
|
|
|
a = """x = range(0, 10, 2)"""
|
|
|
|
self.check(b, a)
|
|
|
|
|
2008-04-09 23:50:50 -03:00
|
|
|
def test_wrap_in_list(self):
|
|
|
|
b = """x = range(10, 3, 9)"""
|
|
|
|
a = """x = list(range(10, 3, 9))"""
|
|
|
|
self.check(b, a)
|
|
|
|
|
|
|
|
b = """x = foo(range(10, 3, 9))"""
|
|
|
|
a = """x = foo(list(range(10, 3, 9)))"""
|
|
|
|
self.check(b, a)
|
|
|
|
|
|
|
|
b = """x = range(10, 3, 9) + [4]"""
|
|
|
|
a = """x = list(range(10, 3, 9)) + [4]"""
|
|
|
|
self.check(b, a)
|
|
|
|
|
Merged revisions 67806 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk
................
r67806 | benjamin.peterson | 2008-12-15 21:35:28 -0600 (Mon, 15 Dec 2008) | 111 lines
Merged revisions 67427,67431,67433,67435,67630,67652,67656-67657,67674-67675,67678-67679,67705-67706,67716,67723,67765-67771,67774,67776,67778 via svnmerge from
svn+ssh://pythondev@svn.python.org/sandbox/trunk/2to3/lib2to3
........
r67427 | benjamin.peterson | 2008-11-28 16:07:41 -0600 (Fri, 28 Nov 2008) | 1 line
fix spelling in comment
........
r67431 | benjamin.peterson | 2008-11-28 17:14:08 -0600 (Fri, 28 Nov 2008) | 1 line
add a scripts directory; move things to it
........
r67433 | benjamin.peterson | 2008-11-28 17:18:48 -0600 (Fri, 28 Nov 2008) | 1 line
run svneol.py
........
r67435 | benjamin.peterson | 2008-11-28 17:25:03 -0600 (Fri, 28 Nov 2008) | 1 line
rename pre/post_order_mapping to pre/post_order_heads
........
r67630 | alexandre.vassalotti | 2008-12-06 21:51:56 -0600 (Sat, 06 Dec 2008) | 2 lines
Fix typo in the urllib2.HTTPDigestAuthHandler fixer.
........
r67652 | armin.ronacher | 2008-12-07 15:39:43 -0600 (Sun, 07 Dec 2008) | 5 lines
Added a fixer that cleans up a tuple argument to isinstance after the tokens
in it were fixed. This is mainly used to remove double occurrences of
tokens as a leftover of the long -> int / unicode -> str conversion.
........
r67656 | armin.ronacher | 2008-12-07 16:54:16 -0600 (Sun, 07 Dec 2008) | 3 lines
Added missing copyright fo 2to3 fix_isinstance.
........
r67657 | armin.ronacher | 2008-12-07 18:29:35 -0600 (Sun, 07 Dec 2008) | 3 lines
2to3: intern and reduce fixes now add the imports if missing. Because that is a common task the fixer_util module now has a function "touch_import" that adds imports if missing.
........
r67674 | benjamin.peterson | 2008-12-08 19:58:11 -0600 (Mon, 08 Dec 2008) | 1 line
copy permission bits when making backup files #4602
........
r67675 | benjamin.peterson | 2008-12-08 19:59:11 -0600 (Mon, 08 Dec 2008) | 1 line
add forgotten import
........
r67678 | benjamin.peterson | 2008-12-08 20:08:30 -0600 (Mon, 08 Dec 2008) | 1 line
fix #4602 for real
........
r67679 | armin.ronacher | 2008-12-09 00:54:03 -0600 (Tue, 09 Dec 2008) | 3 lines
Removed redudant code from the 2to3 long fixer. This fixes #4590.
........
r67705 | benjamin.peterson | 2008-12-11 13:04:08 -0600 (Thu, 11 Dec 2008) | 1 line
put trailers after a range call after the list()
........
r67706 | benjamin.peterson | 2008-12-11 13:17:57 -0600 (Thu, 11 Dec 2008) | 1 line
add html related modules to the fix_imports mapping
........
r67716 | benjamin.peterson | 2008-12-11 22:16:47 -0600 (Thu, 11 Dec 2008) | 1 line
consolidate tests
........
r67723 | benjamin.peterson | 2008-12-12 19:49:31 -0600 (Fri, 12 Dec 2008) | 1 line
fix name
........
r67765 | benjamin.peterson | 2008-12-14 14:05:05 -0600 (Sun, 14 Dec 2008) | 1 line
run fix_isinstance after fix_long and fix_unicode
........
r67766 | benjamin.peterson | 2008-12-14 14:13:05 -0600 (Sun, 14 Dec 2008) | 1 line
use run_order instead of order
........
r67767 | benjamin.peterson | 2008-12-14 14:28:12 -0600 (Sun, 14 Dec 2008) | 1 line
don't retain parenthesis if there is only one item left
........
r67768 | benjamin.peterson | 2008-12-14 14:32:30 -0600 (Sun, 14 Dec 2008) | 1 line
use insert_child()
........
r67769 | benjamin.peterson | 2008-12-14 14:59:10 -0600 (Sun, 14 Dec 2008) | 1 line
parenthesize doesn't belong in pygram or FixerBase
........
r67770 | alexandre.vassalotti | 2008-12-14 15:15:36 -0600 (Sun, 14 Dec 2008) | 2 lines
Fix typo: html.paser -> html.parser.
........
r67771 | benjamin.peterson | 2008-12-14 15:22:09 -0600 (Sun, 14 Dec 2008) | 1 line
altering .children needs to call changed()
........
r67774 | benjamin.peterson | 2008-12-14 15:55:38 -0600 (Sun, 14 Dec 2008) | 1 line
employ an evil hack to fix multiple names in the same import statement
........
r67776 | benjamin.peterson | 2008-12-14 16:22:38 -0600 (Sun, 14 Dec 2008) | 1 line
make a common mixin class for Test_imports and friends
........
r67778 | alexandre.vassalotti | 2008-12-14 17:48:20 -0600 (Sun, 14 Dec 2008) | 2 lines
Make fix_imports refactor multiple imports as.
........
................
2008-12-15 23:57:54 -04:00
|
|
|
b = """x = range(10)[::-1]"""
|
|
|
|
a = """x = list(range(10))[::-1]"""
|
|
|
|
self.check(b, a)
|
|
|
|
|
|
|
|
b = """x = range(10) [3]"""
|
|
|
|
a = """x = list(range(10)) [3]"""
|
|
|
|
self.check(b, a)
|
|
|
|
|
2008-04-09 23:50:50 -03:00
|
|
|
def test_xrange_in_for(self):
|
2008-03-19 02:04:44 -03:00
|
|
|
b = """for i in xrange(10):\n j=i"""
|
|
|
|
a = """for i in range(10):\n j=i"""
|
|
|
|
self.check(b, a)
|
|
|
|
|
2008-04-09 23:50:50 -03:00
|
|
|
b = """[i for i in xrange(10)]"""
|
|
|
|
a = """[i for i in range(10)]"""
|
|
|
|
self.check(b, a)
|
|
|
|
|
|
|
|
def test_range_in_for(self):
|
|
|
|
self.unchanged("for i in range(10): pass")
|
|
|
|
self.unchanged("[i for i in range(10)]")
|
|
|
|
|
|
|
|
def test_in_contains_test(self):
|
|
|
|
self.unchanged("x in range(10, 3, 9)")
|
|
|
|
|
|
|
|
def test_in_consuming_context(self):
|
Merged revisions 64286 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk
................
r64286 | benjamin.peterson | 2008-06-14 21:31:05 -0500 (Sat, 14 Jun 2008) | 49 lines
Merged revisions 63661,63666,63695,63711,63729,63769,63790,63880,63886 via svnmerge from
svn+ssh://pythondev@svn.python.org/sandbox/trunk/2to3/lib2to3
........
r63661 | georg.brandl | 2008-05-26 05:26:20 -0500 (Mon, 26 May 2008) | 2 lines
Add import fixes for dbm package.
........
r63666 | georg.brandl | 2008-05-26 05:49:09 -0500 (Mon, 26 May 2008) | 2 lines
Add xmlrpc package fixes.
........
r63695 | georg.brandl | 2008-05-26 10:14:33 -0500 (Mon, 26 May 2008) | 2 lines
Add fixer entries for http package.
........
r63711 | benjamin.peterson | 2008-05-26 13:43:51 -0500 (Mon, 26 May 2008) | 2 lines
add import mapping for test.test_support -> test.support
........
r63729 | benjamin.peterson | 2008-05-26 16:31:03 -0500 (Mon, 26 May 2008) | 2 lines
mapping for commands module -> subprocess
........
r63769 | brett.cannon | 2008-05-29 00:13:13 -0500 (Thu, 29 May 2008) | 1 line
Fixer for UserString.UserString over to the collections module.
........
r63790 | brett.cannon | 2008-05-29 14:13:51 -0500 (Thu, 29 May 2008) | 4 lines
Add a fixer for UserList.
Closes issue #2878. Thanks to Quentin Gallet-Gilles for the patch.
........
r63880 | collin.winter | 2008-06-01 18:09:38 -0500 (Sun, 01 Jun 2008) | 6 lines
Move lib2to3/fixes/{basefix,util}.py down to lib2to3/.
This is step 1 of turning lib2to3/ into a general-purpose refactoring
library, reusable by other projects.
........
r63886 | collin.winter | 2008-06-01 22:15:01 -0500 (Sun, 01 Jun 2008) | 5 lines
Allow refactoring tools to specify a directory for fixer modules.
This is step 2 of turning lib2to3/ into a general-purpose refactoring
library, reusable by other projects. Step 1: r63880.
........
................
2008-06-14 23:57:40 -03:00
|
|
|
for call in fixer_util.consuming_calls:
|
2008-04-09 23:50:50 -03:00
|
|
|
self.unchanged("a = %s(range(10))" % call)
|
|
|
|
|
2008-03-19 02:04:44 -03:00
|
|
|
class Test_raw_input(FixerTestCase):
|
|
|
|
fixer = "raw_input"
|
|
|
|
|
|
|
|
def test_prefix_preservation(self):
|
|
|
|
b = """x = raw_input( )"""
|
|
|
|
a = """x = input( )"""
|
|
|
|
self.check(b, a)
|
|
|
|
|
|
|
|
b = """x = raw_input( '' )"""
|
|
|
|
a = """x = input( '' )"""
|
|
|
|
self.check(b, a)
|
|
|
|
|
|
|
|
def test_1(self):
|
|
|
|
b = """x = raw_input()"""
|
|
|
|
a = """x = input()"""
|
|
|
|
self.check(b, a)
|
|
|
|
|
|
|
|
def test_2(self):
|
|
|
|
b = """x = raw_input('')"""
|
|
|
|
a = """x = input('')"""
|
|
|
|
self.check(b, a)
|
|
|
|
|
|
|
|
def test_3(self):
|
|
|
|
b = """x = raw_input('prompt')"""
|
|
|
|
a = """x = input('prompt')"""
|
|
|
|
self.check(b, a)
|
|
|
|
|
|
|
|
def test_4(self):
|
|
|
|
b = """x = raw_input(foo(a) + 6)"""
|
|
|
|
a = """x = input(foo(a) + 6)"""
|
|
|
|
self.check(b, a)
|
|
|
|
|
2008-09-01 16:56:06 -03:00
|
|
|
def test_5(self):
|
|
|
|
b = """x = raw_input(invite).split()"""
|
|
|
|
a = """x = input(invite).split()"""
|
|
|
|
self.check(b, a)
|
|
|
|
|
|
|
|
def test_6(self):
|
|
|
|
b = """x = raw_input(invite) . split ()"""
|
|
|
|
a = """x = input(invite) . split ()"""
|
|
|
|
self.check(b, a)
|
|
|
|
|
|
|
|
def test_8(self):
|
|
|
|
b = "x = int(raw_input())"
|
|
|
|
a = "x = int(input())"
|
|
|
|
self.check(b, a)
|
|
|
|
|
2008-03-19 02:04:44 -03:00
|
|
|
class Test_funcattrs(FixerTestCase):
|
|
|
|
fixer = "funcattrs"
|
|
|
|
|
|
|
|
attrs = ["closure", "doc", "name", "defaults", "code", "globals", "dict"]
|
|
|
|
|
|
|
|
def test(self):
|
|
|
|
for attr in self.attrs:
|
|
|
|
b = "a.func_%s" % attr
|
|
|
|
a = "a.__%s__" % attr
|
|
|
|
self.check(b, a)
|
|
|
|
|
|
|
|
b = "self.foo.func_%s.foo_bar" % attr
|
|
|
|
a = "self.foo.__%s__.foo_bar" % attr
|
|
|
|
self.check(b, a)
|
|
|
|
|
|
|
|
def test_unchanged(self):
|
|
|
|
for attr in self.attrs:
|
|
|
|
s = "foo(func_%s + 5)" % attr
|
|
|
|
self.unchanged(s)
|
|
|
|
|
|
|
|
s = "f(foo.__%s__)" % attr
|
|
|
|
self.unchanged(s)
|
|
|
|
|
|
|
|
s = "f(foo.__%s__.foo)" % attr
|
|
|
|
self.unchanged(s)
|
|
|
|
|
|
|
|
class Test_xreadlines(FixerTestCase):
|
|
|
|
fixer = "xreadlines"
|
|
|
|
|
|
|
|
def test_call(self):
|
|
|
|
b = "for x in f.xreadlines(): pass"
|
|
|
|
a = "for x in f: pass"
|
|
|
|
self.check(b, a)
|
|
|
|
|
|
|
|
b = "for x in foo().xreadlines(): pass"
|
|
|
|
a = "for x in foo(): pass"
|
|
|
|
self.check(b, a)
|
|
|
|
|
|
|
|
b = "for x in (5 + foo()).xreadlines(): pass"
|
|
|
|
a = "for x in (5 + foo()): pass"
|
|
|
|
self.check(b, a)
|
|
|
|
|
|
|
|
def test_attr_ref(self):
|
|
|
|
b = "foo(f.xreadlines + 5)"
|
|
|
|
a = "foo(f.__iter__ + 5)"
|
|
|
|
self.check(b, a)
|
|
|
|
|
|
|
|
b = "foo(f().xreadlines + 5)"
|
|
|
|
a = "foo(f().__iter__ + 5)"
|
|
|
|
self.check(b, a)
|
|
|
|
|
|
|
|
b = "foo((5 + f()).xreadlines + 5)"
|
|
|
|
a = "foo((5 + f()).__iter__ + 5)"
|
|
|
|
self.check(b, a)
|
|
|
|
|
|
|
|
def test_unchanged(self):
|
|
|
|
s = "for x in f.xreadlines(5): pass"
|
|
|
|
self.unchanged(s)
|
|
|
|
|
|
|
|
s = "for x in f.xreadlines(k=5): pass"
|
|
|
|
self.unchanged(s)
|
|
|
|
|
|
|
|
s = "for x in f.xreadlines(*k, **v): pass"
|
|
|
|
self.unchanged(s)
|
|
|
|
|
|
|
|
s = "foo(xreadlines)"
|
|
|
|
self.unchanged(s)
|
|
|
|
|
Merged revisions 67806 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk
................
r67806 | benjamin.peterson | 2008-12-15 21:35:28 -0600 (Mon, 15 Dec 2008) | 111 lines
Merged revisions 67427,67431,67433,67435,67630,67652,67656-67657,67674-67675,67678-67679,67705-67706,67716,67723,67765-67771,67774,67776,67778 via svnmerge from
svn+ssh://pythondev@svn.python.org/sandbox/trunk/2to3/lib2to3
........
r67427 | benjamin.peterson | 2008-11-28 16:07:41 -0600 (Fri, 28 Nov 2008) | 1 line
fix spelling in comment
........
r67431 | benjamin.peterson | 2008-11-28 17:14:08 -0600 (Fri, 28 Nov 2008) | 1 line
add a scripts directory; move things to it
........
r67433 | benjamin.peterson | 2008-11-28 17:18:48 -0600 (Fri, 28 Nov 2008) | 1 line
run svneol.py
........
r67435 | benjamin.peterson | 2008-11-28 17:25:03 -0600 (Fri, 28 Nov 2008) | 1 line
rename pre/post_order_mapping to pre/post_order_heads
........
r67630 | alexandre.vassalotti | 2008-12-06 21:51:56 -0600 (Sat, 06 Dec 2008) | 2 lines
Fix typo in the urllib2.HTTPDigestAuthHandler fixer.
........
r67652 | armin.ronacher | 2008-12-07 15:39:43 -0600 (Sun, 07 Dec 2008) | 5 lines
Added a fixer that cleans up a tuple argument to isinstance after the tokens
in it were fixed. This is mainly used to remove double occurrences of
tokens as a leftover of the long -> int / unicode -> str conversion.
........
r67656 | armin.ronacher | 2008-12-07 16:54:16 -0600 (Sun, 07 Dec 2008) | 3 lines
Added missing copyright fo 2to3 fix_isinstance.
........
r67657 | armin.ronacher | 2008-12-07 18:29:35 -0600 (Sun, 07 Dec 2008) | 3 lines
2to3: intern and reduce fixes now add the imports if missing. Because that is a common task the fixer_util module now has a function "touch_import" that adds imports if missing.
........
r67674 | benjamin.peterson | 2008-12-08 19:58:11 -0600 (Mon, 08 Dec 2008) | 1 line
copy permission bits when making backup files #4602
........
r67675 | benjamin.peterson | 2008-12-08 19:59:11 -0600 (Mon, 08 Dec 2008) | 1 line
add forgotten import
........
r67678 | benjamin.peterson | 2008-12-08 20:08:30 -0600 (Mon, 08 Dec 2008) | 1 line
fix #4602 for real
........
r67679 | armin.ronacher | 2008-12-09 00:54:03 -0600 (Tue, 09 Dec 2008) | 3 lines
Removed redudant code from the 2to3 long fixer. This fixes #4590.
........
r67705 | benjamin.peterson | 2008-12-11 13:04:08 -0600 (Thu, 11 Dec 2008) | 1 line
put trailers after a range call after the list()
........
r67706 | benjamin.peterson | 2008-12-11 13:17:57 -0600 (Thu, 11 Dec 2008) | 1 line
add html related modules to the fix_imports mapping
........
r67716 | benjamin.peterson | 2008-12-11 22:16:47 -0600 (Thu, 11 Dec 2008) | 1 line
consolidate tests
........
r67723 | benjamin.peterson | 2008-12-12 19:49:31 -0600 (Fri, 12 Dec 2008) | 1 line
fix name
........
r67765 | benjamin.peterson | 2008-12-14 14:05:05 -0600 (Sun, 14 Dec 2008) | 1 line
run fix_isinstance after fix_long and fix_unicode
........
r67766 | benjamin.peterson | 2008-12-14 14:13:05 -0600 (Sun, 14 Dec 2008) | 1 line
use run_order instead of order
........
r67767 | benjamin.peterson | 2008-12-14 14:28:12 -0600 (Sun, 14 Dec 2008) | 1 line
don't retain parenthesis if there is only one item left
........
r67768 | benjamin.peterson | 2008-12-14 14:32:30 -0600 (Sun, 14 Dec 2008) | 1 line
use insert_child()
........
r67769 | benjamin.peterson | 2008-12-14 14:59:10 -0600 (Sun, 14 Dec 2008) | 1 line
parenthesize doesn't belong in pygram or FixerBase
........
r67770 | alexandre.vassalotti | 2008-12-14 15:15:36 -0600 (Sun, 14 Dec 2008) | 2 lines
Fix typo: html.paser -> html.parser.
........
r67771 | benjamin.peterson | 2008-12-14 15:22:09 -0600 (Sun, 14 Dec 2008) | 1 line
altering .children needs to call changed()
........
r67774 | benjamin.peterson | 2008-12-14 15:55:38 -0600 (Sun, 14 Dec 2008) | 1 line
employ an evil hack to fix multiple names in the same import statement
........
r67776 | benjamin.peterson | 2008-12-14 16:22:38 -0600 (Sun, 14 Dec 2008) | 1 line
make a common mixin class for Test_imports and friends
........
r67778 | alexandre.vassalotti | 2008-12-14 17:48:20 -0600 (Sun, 14 Dec 2008) | 2 lines
Make fix_imports refactor multiple imports as.
........
................
2008-12-15 23:57:54 -04:00
|
|
|
|
|
|
|
class ImportsFixerTests:
|
2008-03-19 02:04:44 -03:00
|
|
|
|
|
|
|
def test_import_module(self):
|
2008-07-16 23:21:56 -03:00
|
|
|
for old, new in self.modules.items():
|
2008-03-19 02:04:44 -03:00
|
|
|
b = "import %s" % old
|
|
|
|
a = "import %s" % new
|
|
|
|
self.check(b, a)
|
|
|
|
|
|
|
|
b = "import foo, %s, bar" % old
|
|
|
|
a = "import foo, %s, bar" % new
|
|
|
|
self.check(b, a)
|
|
|
|
|
|
|
|
def test_import_from(self):
|
2008-07-16 23:21:56 -03:00
|
|
|
for old, new in self.modules.items():
|
|
|
|
b = "from %s import foo" % old
|
|
|
|
a = "from %s import foo" % new
|
Merged revisions 63634 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk
................
r63634 | martin.v.loewis | 2008-05-25 16:58:01 +0200 (So, 25 Mai 2008) | 81 lines
Merged revisions 62647-63633 via svnmerge from
svn+ssh://pythondev@svn.python.org/sandbox/trunk/2to3/lib2to3
........
r63047 | alexandre.vassalotti | 2008-05-11 11:03:24 +0200 (So, 11 Mai 2008) | 2 lines
Added import fixer for copy_reg rename.
........
r63081 | alexandre.vassalotti | 2008-05-11 22:06:36 +0200 (So, 11 Mai 2008) | 2 lines
Added import fixer for Queue rename.
........
r63090 | alexandre.vassalotti | 2008-05-11 22:38:16 +0200 (So, 11 Mai 2008) | 2 lines
Added import fixer for PixMapWrapper rename.
........
r63141 | alexandre.vassalotti | 2008-05-12 04:42:03 +0200 (Mo, 12 Mai 2008) | 5 lines
Added fixer for SocketServer renaming.
Removed PixMapWrapper fixer, since the module is actually pending
removal.
........
r63252 | alexandre.vassalotti | 2008-05-15 01:10:20 +0200 (Do, 15 Mai 2008) | 2 lines
Added fixer for ConfigParser rename.
........
r63321 | collin.winter | 2008-05-15 19:42:58 +0200 (Do, 15 Mai 2008) | 1 line
Add a missing comma. Fixes issue 2866.
........
r63356 | alexandre.vassalotti | 2008-05-16 08:55:44 +0200 (Fr, 16 Mai 2008) | 4 lines
Added new tests for fix_imports.
Added refactoring support of from-import statements of the style:
from foo import bar, baz
........
r63362 | alexandre.vassalotti | 2008-05-16 09:17:53 +0200 (Fr, 16 Mai 2008) | 2 lines
Added the repr module import fixer.
........
r63456 | georg.brandl | 2008-05-18 21:51:18 +0200 (So, 18 Mai 2008) | 2 lines
#2908: fixers for Tkinter rename.
........
r63461 | georg.brandl | 2008-05-18 23:00:20 +0200 (So, 18 Mai 2008) | 2 lines
Fix for last patch.
........
r63525 | alexandre.vassalotti | 2008-05-21 23:43:29 +0200 (Mi, 21 Mai 2008) | 4 lines
Add missing comma in fix_imports.
Bug caught by Quentin Gallet-Gilles.
........
r63532 | brett.cannon | 2008-05-22 05:02:43 +0200 (Do, 22 Mai 2008) | 4 lines
When testing fix_imports, no need to only test a subset of input; test it all!
Do all revisions to the sandbox need to be manually applied to the trunk?
........
r63533 | brett.cannon | 2008-05-22 05:16:45 +0200 (Do, 22 Mai 2008) | 1 line
Add _markupbase to the import fixer.
........
r63612 | georg.brandl | 2008-05-25 09:56:59 +0200 (So, 25 Mai 2008) | 2 lines
Add fixer for _winreg rename.
........
r63627 | georg.brandl | 2008-05-25 14:30:10 +0200 (So, 25 Mai 2008) | 2 lines
Add fixer entry for the thread module.
........
r63629 | georg.brandl | 2008-05-25 14:34:13 +0200 (So, 25 Mai 2008) | 2 lines
Fixer entry for dummy_thread.
........
r63633 | martin.v.loewis | 2008-05-25 16:52:41 +0200 (So, 25 Mai 2008) | 2 lines
Temporarily disable Test_imports.
........
................
2008-05-25 12:24:57 -03:00
|
|
|
self.check(b, a)
|
|
|
|
|
2008-07-16 23:21:56 -03:00
|
|
|
b = "from %s import foo, bar" % old
|
|
|
|
a = "from %s import foo, bar" % new
|
|
|
|
self.check(b, a)
|
Merged revisions 63634 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk
................
r63634 | martin.v.loewis | 2008-05-25 16:58:01 +0200 (So, 25 Mai 2008) | 81 lines
Merged revisions 62647-63633 via svnmerge from
svn+ssh://pythondev@svn.python.org/sandbox/trunk/2to3/lib2to3
........
r63047 | alexandre.vassalotti | 2008-05-11 11:03:24 +0200 (So, 11 Mai 2008) | 2 lines
Added import fixer for copy_reg rename.
........
r63081 | alexandre.vassalotti | 2008-05-11 22:06:36 +0200 (So, 11 Mai 2008) | 2 lines
Added import fixer for Queue rename.
........
r63090 | alexandre.vassalotti | 2008-05-11 22:38:16 +0200 (So, 11 Mai 2008) | 2 lines
Added import fixer for PixMapWrapper rename.
........
r63141 | alexandre.vassalotti | 2008-05-12 04:42:03 +0200 (Mo, 12 Mai 2008) | 5 lines
Added fixer for SocketServer renaming.
Removed PixMapWrapper fixer, since the module is actually pending
removal.
........
r63252 | alexandre.vassalotti | 2008-05-15 01:10:20 +0200 (Do, 15 Mai 2008) | 2 lines
Added fixer for ConfigParser rename.
........
r63321 | collin.winter | 2008-05-15 19:42:58 +0200 (Do, 15 Mai 2008) | 1 line
Add a missing comma. Fixes issue 2866.
........
r63356 | alexandre.vassalotti | 2008-05-16 08:55:44 +0200 (Fr, 16 Mai 2008) | 4 lines
Added new tests for fix_imports.
Added refactoring support of from-import statements of the style:
from foo import bar, baz
........
r63362 | alexandre.vassalotti | 2008-05-16 09:17:53 +0200 (Fr, 16 Mai 2008) | 2 lines
Added the repr module import fixer.
........
r63456 | georg.brandl | 2008-05-18 21:51:18 +0200 (So, 18 Mai 2008) | 2 lines
#2908: fixers for Tkinter rename.
........
r63461 | georg.brandl | 2008-05-18 23:00:20 +0200 (So, 18 Mai 2008) | 2 lines
Fix for last patch.
........
r63525 | alexandre.vassalotti | 2008-05-21 23:43:29 +0200 (Mi, 21 Mai 2008) | 4 lines
Add missing comma in fix_imports.
Bug caught by Quentin Gallet-Gilles.
........
r63532 | brett.cannon | 2008-05-22 05:02:43 +0200 (Do, 22 Mai 2008) | 4 lines
When testing fix_imports, no need to only test a subset of input; test it all!
Do all revisions to the sandbox need to be manually applied to the trunk?
........
r63533 | brett.cannon | 2008-05-22 05:16:45 +0200 (Do, 22 Mai 2008) | 1 line
Add _markupbase to the import fixer.
........
r63612 | georg.brandl | 2008-05-25 09:56:59 +0200 (So, 25 Mai 2008) | 2 lines
Add fixer for _winreg rename.
........
r63627 | georg.brandl | 2008-05-25 14:30:10 +0200 (So, 25 Mai 2008) | 2 lines
Add fixer entry for the thread module.
........
r63629 | georg.brandl | 2008-05-25 14:34:13 +0200 (So, 25 Mai 2008) | 2 lines
Fixer entry for dummy_thread.
........
r63633 | martin.v.loewis | 2008-05-25 16:52:41 +0200 (So, 25 Mai 2008) | 2 lines
Temporarily disable Test_imports.
........
................
2008-05-25 12:24:57 -03:00
|
|
|
|
Merged revisions 67180 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk
................
r67180 | benjamin.peterson | 2008-11-10 16:11:12 -0600 (Mon, 10 Nov 2008) | 29 lines
Merged revisions 66985,67170,67173,67177-67179 via svnmerge from
svn+ssh://pythondev@svn.python.org/sandbox/trunk/2to3/lib2to3
........
r66985 | benjamin.peterson | 2008-10-20 16:43:46 -0500 (Mon, 20 Oct 2008) | 1 line
no need to use nested try, except, finally
........
r67170 | benjamin.peterson | 2008-11-08 12:28:31 -0600 (Sat, 08 Nov 2008) | 1 line
fix #4271: fix_imports didn't recognize imports with parenthesis (ie from x import (a, b))
........
r67173 | benjamin.peterson | 2008-11-08 17:42:08 -0600 (Sat, 08 Nov 2008) | 1 line
consolidate test
........
r67177 | benjamin.peterson | 2008-11-09 21:52:52 -0600 (Sun, 09 Nov 2008) | 1 line
let the metclass fixer handle complex assignments in the class body gracefully
........
r67178 | benjamin.peterson | 2008-11-10 15:26:43 -0600 (Mon, 10 Nov 2008) | 1 line
the metaclass fixers shouldn't die when bases are not a simple name
........
r67179 | benjamin.peterson | 2008-11-10 15:29:58 -0600 (Mon, 10 Nov 2008) | 1 line
allow the fix_import pattern to catch from imports with parenthesis
........
................
2008-11-10 18:21:33 -04:00
|
|
|
b = "from %s import (yes, no)" % old
|
|
|
|
a = "from %s import (yes, no)" % new
|
|
|
|
self.check(b, a)
|
|
|
|
|
2008-03-19 02:04:44 -03:00
|
|
|
def test_import_module_as(self):
|
2008-07-16 23:21:56 -03:00
|
|
|
for old, new in self.modules.items():
|
2008-03-19 02:04:44 -03:00
|
|
|
b = "import %s as foo_bar" % old
|
|
|
|
a = "import %s as foo_bar" % new
|
|
|
|
self.check(b, a)
|
|
|
|
|
|
|
|
b = "import %s as foo_bar" % old
|
|
|
|
a = "import %s as foo_bar" % new
|
|
|
|
self.check(b, a)
|
|
|
|
|
|
|
|
def test_import_from_as(self):
|
2008-07-16 23:21:56 -03:00
|
|
|
for old, new in self.modules.items():
|
|
|
|
b = "from %s import foo as bar" % old
|
|
|
|
a = "from %s import foo as bar" % new
|
|
|
|
self.check(b, a)
|
2008-03-19 02:04:44 -03:00
|
|
|
|
|
|
|
def test_star(self):
|
2008-07-16 23:21:56 -03:00
|
|
|
for old, new in self.modules.items():
|
|
|
|
b = "from %s import *" % old
|
|
|
|
a = "from %s import *" % new
|
|
|
|
self.check(b, a)
|
2008-03-19 02:04:44 -03:00
|
|
|
|
|
|
|
def test_import_module_usage(self):
|
2008-07-16 23:21:56 -03:00
|
|
|
for old, new in self.modules.items():
|
Merged revisions 63634 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk
................
r63634 | martin.v.loewis | 2008-05-25 16:58:01 +0200 (So, 25 Mai 2008) | 81 lines
Merged revisions 62647-63633 via svnmerge from
svn+ssh://pythondev@svn.python.org/sandbox/trunk/2to3/lib2to3
........
r63047 | alexandre.vassalotti | 2008-05-11 11:03:24 +0200 (So, 11 Mai 2008) | 2 lines
Added import fixer for copy_reg rename.
........
r63081 | alexandre.vassalotti | 2008-05-11 22:06:36 +0200 (So, 11 Mai 2008) | 2 lines
Added import fixer for Queue rename.
........
r63090 | alexandre.vassalotti | 2008-05-11 22:38:16 +0200 (So, 11 Mai 2008) | 2 lines
Added import fixer for PixMapWrapper rename.
........
r63141 | alexandre.vassalotti | 2008-05-12 04:42:03 +0200 (Mo, 12 Mai 2008) | 5 lines
Added fixer for SocketServer renaming.
Removed PixMapWrapper fixer, since the module is actually pending
removal.
........
r63252 | alexandre.vassalotti | 2008-05-15 01:10:20 +0200 (Do, 15 Mai 2008) | 2 lines
Added fixer for ConfigParser rename.
........
r63321 | collin.winter | 2008-05-15 19:42:58 +0200 (Do, 15 Mai 2008) | 1 line
Add a missing comma. Fixes issue 2866.
........
r63356 | alexandre.vassalotti | 2008-05-16 08:55:44 +0200 (Fr, 16 Mai 2008) | 4 lines
Added new tests for fix_imports.
Added refactoring support of from-import statements of the style:
from foo import bar, baz
........
r63362 | alexandre.vassalotti | 2008-05-16 09:17:53 +0200 (Fr, 16 Mai 2008) | 2 lines
Added the repr module import fixer.
........
r63456 | georg.brandl | 2008-05-18 21:51:18 +0200 (So, 18 Mai 2008) | 2 lines
#2908: fixers for Tkinter rename.
........
r63461 | georg.brandl | 2008-05-18 23:00:20 +0200 (So, 18 Mai 2008) | 2 lines
Fix for last patch.
........
r63525 | alexandre.vassalotti | 2008-05-21 23:43:29 +0200 (Mi, 21 Mai 2008) | 4 lines
Add missing comma in fix_imports.
Bug caught by Quentin Gallet-Gilles.
........
r63532 | brett.cannon | 2008-05-22 05:02:43 +0200 (Do, 22 Mai 2008) | 4 lines
When testing fix_imports, no need to only test a subset of input; test it all!
Do all revisions to the sandbox need to be manually applied to the trunk?
........
r63533 | brett.cannon | 2008-05-22 05:16:45 +0200 (Do, 22 Mai 2008) | 1 line
Add _markupbase to the import fixer.
........
r63612 | georg.brandl | 2008-05-25 09:56:59 +0200 (So, 25 Mai 2008) | 2 lines
Add fixer for _winreg rename.
........
r63627 | georg.brandl | 2008-05-25 14:30:10 +0200 (So, 25 Mai 2008) | 2 lines
Add fixer entry for the thread module.
........
r63629 | georg.brandl | 2008-05-25 14:34:13 +0200 (So, 25 Mai 2008) | 2 lines
Fixer entry for dummy_thread.
........
r63633 | martin.v.loewis | 2008-05-25 16:52:41 +0200 (So, 25 Mai 2008) | 2 lines
Temporarily disable Test_imports.
........
................
2008-05-25 12:24:57 -03:00
|
|
|
b = """
|
2008-07-16 23:21:56 -03:00
|
|
|
import %s
|
|
|
|
foo(%s.bar)
|
|
|
|
""" % (old, old)
|
Merged revisions 63634 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk
................
r63634 | martin.v.loewis | 2008-05-25 16:58:01 +0200 (So, 25 Mai 2008) | 81 lines
Merged revisions 62647-63633 via svnmerge from
svn+ssh://pythondev@svn.python.org/sandbox/trunk/2to3/lib2to3
........
r63047 | alexandre.vassalotti | 2008-05-11 11:03:24 +0200 (So, 11 Mai 2008) | 2 lines
Added import fixer for copy_reg rename.
........
r63081 | alexandre.vassalotti | 2008-05-11 22:06:36 +0200 (So, 11 Mai 2008) | 2 lines
Added import fixer for Queue rename.
........
r63090 | alexandre.vassalotti | 2008-05-11 22:38:16 +0200 (So, 11 Mai 2008) | 2 lines
Added import fixer for PixMapWrapper rename.
........
r63141 | alexandre.vassalotti | 2008-05-12 04:42:03 +0200 (Mo, 12 Mai 2008) | 5 lines
Added fixer for SocketServer renaming.
Removed PixMapWrapper fixer, since the module is actually pending
removal.
........
r63252 | alexandre.vassalotti | 2008-05-15 01:10:20 +0200 (Do, 15 Mai 2008) | 2 lines
Added fixer for ConfigParser rename.
........
r63321 | collin.winter | 2008-05-15 19:42:58 +0200 (Do, 15 Mai 2008) | 1 line
Add a missing comma. Fixes issue 2866.
........
r63356 | alexandre.vassalotti | 2008-05-16 08:55:44 +0200 (Fr, 16 Mai 2008) | 4 lines
Added new tests for fix_imports.
Added refactoring support of from-import statements of the style:
from foo import bar, baz
........
r63362 | alexandre.vassalotti | 2008-05-16 09:17:53 +0200 (Fr, 16 Mai 2008) | 2 lines
Added the repr module import fixer.
........
r63456 | georg.brandl | 2008-05-18 21:51:18 +0200 (So, 18 Mai 2008) | 2 lines
#2908: fixers for Tkinter rename.
........
r63461 | georg.brandl | 2008-05-18 23:00:20 +0200 (So, 18 Mai 2008) | 2 lines
Fix for last patch.
........
r63525 | alexandre.vassalotti | 2008-05-21 23:43:29 +0200 (Mi, 21 Mai 2008) | 4 lines
Add missing comma in fix_imports.
Bug caught by Quentin Gallet-Gilles.
........
r63532 | brett.cannon | 2008-05-22 05:02:43 +0200 (Do, 22 Mai 2008) | 4 lines
When testing fix_imports, no need to only test a subset of input; test it all!
Do all revisions to the sandbox need to be manually applied to the trunk?
........
r63533 | brett.cannon | 2008-05-22 05:16:45 +0200 (Do, 22 Mai 2008) | 1 line
Add _markupbase to the import fixer.
........
r63612 | georg.brandl | 2008-05-25 09:56:59 +0200 (So, 25 Mai 2008) | 2 lines
Add fixer for _winreg rename.
........
r63627 | georg.brandl | 2008-05-25 14:30:10 +0200 (So, 25 Mai 2008) | 2 lines
Add fixer entry for the thread module.
........
r63629 | georg.brandl | 2008-05-25 14:34:13 +0200 (So, 25 Mai 2008) | 2 lines
Fixer entry for dummy_thread.
........
r63633 | martin.v.loewis | 2008-05-25 16:52:41 +0200 (So, 25 Mai 2008) | 2 lines
Temporarily disable Test_imports.
........
................
2008-05-25 12:24:57 -03:00
|
|
|
a = """
|
2008-07-16 23:21:56 -03:00
|
|
|
import %s
|
|
|
|
foo(%s.bar)
|
|
|
|
""" % (new, new)
|
Merged revisions 63634 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk
................
r63634 | martin.v.loewis | 2008-05-25 16:58:01 +0200 (So, 25 Mai 2008) | 81 lines
Merged revisions 62647-63633 via svnmerge from
svn+ssh://pythondev@svn.python.org/sandbox/trunk/2to3/lib2to3
........
r63047 | alexandre.vassalotti | 2008-05-11 11:03:24 +0200 (So, 11 Mai 2008) | 2 lines
Added import fixer for copy_reg rename.
........
r63081 | alexandre.vassalotti | 2008-05-11 22:06:36 +0200 (So, 11 Mai 2008) | 2 lines
Added import fixer for Queue rename.
........
r63090 | alexandre.vassalotti | 2008-05-11 22:38:16 +0200 (So, 11 Mai 2008) | 2 lines
Added import fixer for PixMapWrapper rename.
........
r63141 | alexandre.vassalotti | 2008-05-12 04:42:03 +0200 (Mo, 12 Mai 2008) | 5 lines
Added fixer for SocketServer renaming.
Removed PixMapWrapper fixer, since the module is actually pending
removal.
........
r63252 | alexandre.vassalotti | 2008-05-15 01:10:20 +0200 (Do, 15 Mai 2008) | 2 lines
Added fixer for ConfigParser rename.
........
r63321 | collin.winter | 2008-05-15 19:42:58 +0200 (Do, 15 Mai 2008) | 1 line
Add a missing comma. Fixes issue 2866.
........
r63356 | alexandre.vassalotti | 2008-05-16 08:55:44 +0200 (Fr, 16 Mai 2008) | 4 lines
Added new tests for fix_imports.
Added refactoring support of from-import statements of the style:
from foo import bar, baz
........
r63362 | alexandre.vassalotti | 2008-05-16 09:17:53 +0200 (Fr, 16 Mai 2008) | 2 lines
Added the repr module import fixer.
........
r63456 | georg.brandl | 2008-05-18 21:51:18 +0200 (So, 18 Mai 2008) | 2 lines
#2908: fixers for Tkinter rename.
........
r63461 | georg.brandl | 2008-05-18 23:00:20 +0200 (So, 18 Mai 2008) | 2 lines
Fix for last patch.
........
r63525 | alexandre.vassalotti | 2008-05-21 23:43:29 +0200 (Mi, 21 Mai 2008) | 4 lines
Add missing comma in fix_imports.
Bug caught by Quentin Gallet-Gilles.
........
r63532 | brett.cannon | 2008-05-22 05:02:43 +0200 (Do, 22 Mai 2008) | 4 lines
When testing fix_imports, no need to only test a subset of input; test it all!
Do all revisions to the sandbox need to be manually applied to the trunk?
........
r63533 | brett.cannon | 2008-05-22 05:16:45 +0200 (Do, 22 Mai 2008) | 1 line
Add _markupbase to the import fixer.
........
r63612 | georg.brandl | 2008-05-25 09:56:59 +0200 (So, 25 Mai 2008) | 2 lines
Add fixer for _winreg rename.
........
r63627 | georg.brandl | 2008-05-25 14:30:10 +0200 (So, 25 Mai 2008) | 2 lines
Add fixer entry for the thread module.
........
r63629 | georg.brandl | 2008-05-25 14:34:13 +0200 (So, 25 Mai 2008) | 2 lines
Fixer entry for dummy_thread.
........
r63633 | martin.v.loewis | 2008-05-25 16:52:41 +0200 (So, 25 Mai 2008) | 2 lines
Temporarily disable Test_imports.
........
................
2008-05-25 12:24:57 -03:00
|
|
|
self.check(b, a)
|
|
|
|
|
Merged revisions 67428 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk
................
r67428 | benjamin.peterson | 2008-11-28 16:12:14 -0600 (Fri, 28 Nov 2008) | 57 lines
Merged revisions 67384,67386-67387,67389-67390,67392,67399-67400,67403-67405,67426 via svnmerge from
svn+ssh://pythondev@svn.python.org/sandbox/trunk/2to3/lib2to3
........
r67384 | benjamin.peterson | 2008-11-25 16:13:31 -0600 (Tue, 25 Nov 2008) | 4 lines
don't duplicate calls to start_tree()
RefactoringTool.pre_order values now holds a list of the fixers while pre_order_mapping holds the dict.
........
r67386 | benjamin.peterson | 2008-11-25 16:44:52 -0600 (Tue, 25 Nov 2008) | 1 line
#4423 fix_imports was still replacing usage of a module if attributes were being used
........
r67387 | benjamin.peterson | 2008-11-25 16:47:54 -0600 (Tue, 25 Nov 2008) | 1 line
fix broken test
........
r67389 | benjamin.peterson | 2008-11-25 17:13:17 -0600 (Tue, 25 Nov 2008) | 1 line
remove compatibility code; we only cater to 2.5+
........
r67390 | benjamin.peterson | 2008-11-25 22:03:36 -0600 (Tue, 25 Nov 2008) | 1 line
fix #3994; the usage of changed imports was fixed in nested cases
........
r67392 | benjamin.peterson | 2008-11-26 11:11:40 -0600 (Wed, 26 Nov 2008) | 1 line
simpilfy and comment fix_imports
........
r67399 | benjamin.peterson | 2008-11-26 11:47:03 -0600 (Wed, 26 Nov 2008) | 1 line
remove more compatibility code
........
r67400 | benjamin.peterson | 2008-11-26 12:07:41 -0600 (Wed, 26 Nov 2008) | 1 line
set svn:ignore
........
r67403 | benjamin.peterson | 2008-11-26 13:11:11 -0600 (Wed, 26 Nov 2008) | 1 line
wrap import
........
r67404 | benjamin.peterson | 2008-11-26 13:29:49 -0600 (Wed, 26 Nov 2008) | 1 line
build the fix_imports pattern in compile_pattern, so MAPPING can be changed and reflected in the pattern
........
r67405 | benjamin.peterson | 2008-11-26 14:01:24 -0600 (Wed, 26 Nov 2008) | 1 line
stop ugly messages about runtime errors being from printed
........
r67426 | benjamin.peterson | 2008-11-28 16:01:40 -0600 (Fri, 28 Nov 2008) | 5 lines
don't replace a module name if it is in the middle of a attribute lookup
This fix also stops module names from being replaced if they are not in an attribute lookup.
........
................
2008-11-28 19:01:28 -04:00
|
|
|
b = """
|
|
|
|
from %s import x
|
|
|
|
%s = 23
|
|
|
|
""" % (old, old)
|
|
|
|
a = """
|
|
|
|
from %s import x
|
|
|
|
%s = 23
|
|
|
|
""" % (new, old)
|
|
|
|
self.check(b, a)
|
|
|
|
|
|
|
|
s = """
|
|
|
|
def f():
|
|
|
|
%s.method()
|
|
|
|
""" % (old,)
|
|
|
|
self.unchanged(s)
|
|
|
|
|
|
|
|
# test nested usage
|
|
|
|
b = """
|
|
|
|
import %s
|
|
|
|
%s.bar(%s.foo)
|
|
|
|
""" % (old, old, old)
|
|
|
|
a = """
|
|
|
|
import %s
|
|
|
|
%s.bar(%s.foo)
|
|
|
|
""" % (new, new, new)
|
|
|
|
self.check(b, a)
|
|
|
|
|
|
|
|
b = """
|
|
|
|
import %s
|
|
|
|
x.%s
|
|
|
|
""" % (old, old)
|
|
|
|
a = """
|
|
|
|
import %s
|
|
|
|
x.%s
|
|
|
|
""" % (new, old)
|
|
|
|
self.check(b, a)
|
|
|
|
|
|
|
|
|
Merged revisions 67806 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk
................
r67806 | benjamin.peterson | 2008-12-15 21:35:28 -0600 (Mon, 15 Dec 2008) | 111 lines
Merged revisions 67427,67431,67433,67435,67630,67652,67656-67657,67674-67675,67678-67679,67705-67706,67716,67723,67765-67771,67774,67776,67778 via svnmerge from
svn+ssh://pythondev@svn.python.org/sandbox/trunk/2to3/lib2to3
........
r67427 | benjamin.peterson | 2008-11-28 16:07:41 -0600 (Fri, 28 Nov 2008) | 1 line
fix spelling in comment
........
r67431 | benjamin.peterson | 2008-11-28 17:14:08 -0600 (Fri, 28 Nov 2008) | 1 line
add a scripts directory; move things to it
........
r67433 | benjamin.peterson | 2008-11-28 17:18:48 -0600 (Fri, 28 Nov 2008) | 1 line
run svneol.py
........
r67435 | benjamin.peterson | 2008-11-28 17:25:03 -0600 (Fri, 28 Nov 2008) | 1 line
rename pre/post_order_mapping to pre/post_order_heads
........
r67630 | alexandre.vassalotti | 2008-12-06 21:51:56 -0600 (Sat, 06 Dec 2008) | 2 lines
Fix typo in the urllib2.HTTPDigestAuthHandler fixer.
........
r67652 | armin.ronacher | 2008-12-07 15:39:43 -0600 (Sun, 07 Dec 2008) | 5 lines
Added a fixer that cleans up a tuple argument to isinstance after the tokens
in it were fixed. This is mainly used to remove double occurrences of
tokens as a leftover of the long -> int / unicode -> str conversion.
........
r67656 | armin.ronacher | 2008-12-07 16:54:16 -0600 (Sun, 07 Dec 2008) | 3 lines
Added missing copyright fo 2to3 fix_isinstance.
........
r67657 | armin.ronacher | 2008-12-07 18:29:35 -0600 (Sun, 07 Dec 2008) | 3 lines
2to3: intern and reduce fixes now add the imports if missing. Because that is a common task the fixer_util module now has a function "touch_import" that adds imports if missing.
........
r67674 | benjamin.peterson | 2008-12-08 19:58:11 -0600 (Mon, 08 Dec 2008) | 1 line
copy permission bits when making backup files #4602
........
r67675 | benjamin.peterson | 2008-12-08 19:59:11 -0600 (Mon, 08 Dec 2008) | 1 line
add forgotten import
........
r67678 | benjamin.peterson | 2008-12-08 20:08:30 -0600 (Mon, 08 Dec 2008) | 1 line
fix #4602 for real
........
r67679 | armin.ronacher | 2008-12-09 00:54:03 -0600 (Tue, 09 Dec 2008) | 3 lines
Removed redudant code from the 2to3 long fixer. This fixes #4590.
........
r67705 | benjamin.peterson | 2008-12-11 13:04:08 -0600 (Thu, 11 Dec 2008) | 1 line
put trailers after a range call after the list()
........
r67706 | benjamin.peterson | 2008-12-11 13:17:57 -0600 (Thu, 11 Dec 2008) | 1 line
add html related modules to the fix_imports mapping
........
r67716 | benjamin.peterson | 2008-12-11 22:16:47 -0600 (Thu, 11 Dec 2008) | 1 line
consolidate tests
........
r67723 | benjamin.peterson | 2008-12-12 19:49:31 -0600 (Fri, 12 Dec 2008) | 1 line
fix name
........
r67765 | benjamin.peterson | 2008-12-14 14:05:05 -0600 (Sun, 14 Dec 2008) | 1 line
run fix_isinstance after fix_long and fix_unicode
........
r67766 | benjamin.peterson | 2008-12-14 14:13:05 -0600 (Sun, 14 Dec 2008) | 1 line
use run_order instead of order
........
r67767 | benjamin.peterson | 2008-12-14 14:28:12 -0600 (Sun, 14 Dec 2008) | 1 line
don't retain parenthesis if there is only one item left
........
r67768 | benjamin.peterson | 2008-12-14 14:32:30 -0600 (Sun, 14 Dec 2008) | 1 line
use insert_child()
........
r67769 | benjamin.peterson | 2008-12-14 14:59:10 -0600 (Sun, 14 Dec 2008) | 1 line
parenthesize doesn't belong in pygram or FixerBase
........
r67770 | alexandre.vassalotti | 2008-12-14 15:15:36 -0600 (Sun, 14 Dec 2008) | 2 lines
Fix typo: html.paser -> html.parser.
........
r67771 | benjamin.peterson | 2008-12-14 15:22:09 -0600 (Sun, 14 Dec 2008) | 1 line
altering .children needs to call changed()
........
r67774 | benjamin.peterson | 2008-12-14 15:55:38 -0600 (Sun, 14 Dec 2008) | 1 line
employ an evil hack to fix multiple names in the same import statement
........
r67776 | benjamin.peterson | 2008-12-14 16:22:38 -0600 (Sun, 14 Dec 2008) | 1 line
make a common mixin class for Test_imports and friends
........
r67778 | alexandre.vassalotti | 2008-12-14 17:48:20 -0600 (Sun, 14 Dec 2008) | 2 lines
Make fix_imports refactor multiple imports as.
........
................
2008-12-15 23:57:54 -04:00
|
|
|
class Test_imports(FixerTestCase, ImportsFixerTests):
|
|
|
|
fixer = "imports"
|
|
|
|
from ..fixes.fix_imports import MAPPING as modules
|
|
|
|
|
|
|
|
def test_multiple_imports(self):
|
|
|
|
b = """import urlparse, cStringIO"""
|
|
|
|
a = """import urllib.parse, io"""
|
|
|
|
self.check(b, a)
|
2008-03-19 02:04:44 -03:00
|
|
|
|
Merged revisions 67806 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk
................
r67806 | benjamin.peterson | 2008-12-15 21:35:28 -0600 (Mon, 15 Dec 2008) | 111 lines
Merged revisions 67427,67431,67433,67435,67630,67652,67656-67657,67674-67675,67678-67679,67705-67706,67716,67723,67765-67771,67774,67776,67778 via svnmerge from
svn+ssh://pythondev@svn.python.org/sandbox/trunk/2to3/lib2to3
........
r67427 | benjamin.peterson | 2008-11-28 16:07:41 -0600 (Fri, 28 Nov 2008) | 1 line
fix spelling in comment
........
r67431 | benjamin.peterson | 2008-11-28 17:14:08 -0600 (Fri, 28 Nov 2008) | 1 line
add a scripts directory; move things to it
........
r67433 | benjamin.peterson | 2008-11-28 17:18:48 -0600 (Fri, 28 Nov 2008) | 1 line
run svneol.py
........
r67435 | benjamin.peterson | 2008-11-28 17:25:03 -0600 (Fri, 28 Nov 2008) | 1 line
rename pre/post_order_mapping to pre/post_order_heads
........
r67630 | alexandre.vassalotti | 2008-12-06 21:51:56 -0600 (Sat, 06 Dec 2008) | 2 lines
Fix typo in the urllib2.HTTPDigestAuthHandler fixer.
........
r67652 | armin.ronacher | 2008-12-07 15:39:43 -0600 (Sun, 07 Dec 2008) | 5 lines
Added a fixer that cleans up a tuple argument to isinstance after the tokens
in it were fixed. This is mainly used to remove double occurrences of
tokens as a leftover of the long -> int / unicode -> str conversion.
........
r67656 | armin.ronacher | 2008-12-07 16:54:16 -0600 (Sun, 07 Dec 2008) | 3 lines
Added missing copyright fo 2to3 fix_isinstance.
........
r67657 | armin.ronacher | 2008-12-07 18:29:35 -0600 (Sun, 07 Dec 2008) | 3 lines
2to3: intern and reduce fixes now add the imports if missing. Because that is a common task the fixer_util module now has a function "touch_import" that adds imports if missing.
........
r67674 | benjamin.peterson | 2008-12-08 19:58:11 -0600 (Mon, 08 Dec 2008) | 1 line
copy permission bits when making backup files #4602
........
r67675 | benjamin.peterson | 2008-12-08 19:59:11 -0600 (Mon, 08 Dec 2008) | 1 line
add forgotten import
........
r67678 | benjamin.peterson | 2008-12-08 20:08:30 -0600 (Mon, 08 Dec 2008) | 1 line
fix #4602 for real
........
r67679 | armin.ronacher | 2008-12-09 00:54:03 -0600 (Tue, 09 Dec 2008) | 3 lines
Removed redudant code from the 2to3 long fixer. This fixes #4590.
........
r67705 | benjamin.peterson | 2008-12-11 13:04:08 -0600 (Thu, 11 Dec 2008) | 1 line
put trailers after a range call after the list()
........
r67706 | benjamin.peterson | 2008-12-11 13:17:57 -0600 (Thu, 11 Dec 2008) | 1 line
add html related modules to the fix_imports mapping
........
r67716 | benjamin.peterson | 2008-12-11 22:16:47 -0600 (Thu, 11 Dec 2008) | 1 line
consolidate tests
........
r67723 | benjamin.peterson | 2008-12-12 19:49:31 -0600 (Fri, 12 Dec 2008) | 1 line
fix name
........
r67765 | benjamin.peterson | 2008-12-14 14:05:05 -0600 (Sun, 14 Dec 2008) | 1 line
run fix_isinstance after fix_long and fix_unicode
........
r67766 | benjamin.peterson | 2008-12-14 14:13:05 -0600 (Sun, 14 Dec 2008) | 1 line
use run_order instead of order
........
r67767 | benjamin.peterson | 2008-12-14 14:28:12 -0600 (Sun, 14 Dec 2008) | 1 line
don't retain parenthesis if there is only one item left
........
r67768 | benjamin.peterson | 2008-12-14 14:32:30 -0600 (Sun, 14 Dec 2008) | 1 line
use insert_child()
........
r67769 | benjamin.peterson | 2008-12-14 14:59:10 -0600 (Sun, 14 Dec 2008) | 1 line
parenthesize doesn't belong in pygram or FixerBase
........
r67770 | alexandre.vassalotti | 2008-12-14 15:15:36 -0600 (Sun, 14 Dec 2008) | 2 lines
Fix typo: html.paser -> html.parser.
........
r67771 | benjamin.peterson | 2008-12-14 15:22:09 -0600 (Sun, 14 Dec 2008) | 1 line
altering .children needs to call changed()
........
r67774 | benjamin.peterson | 2008-12-14 15:55:38 -0600 (Sun, 14 Dec 2008) | 1 line
employ an evil hack to fix multiple names in the same import statement
........
r67776 | benjamin.peterson | 2008-12-14 16:22:38 -0600 (Sun, 14 Dec 2008) | 1 line
make a common mixin class for Test_imports and friends
........
r67778 | alexandre.vassalotti | 2008-12-14 17:48:20 -0600 (Sun, 14 Dec 2008) | 2 lines
Make fix_imports refactor multiple imports as.
........
................
2008-12-15 23:57:54 -04:00
|
|
|
def test_multiple_imports_as(self):
|
|
|
|
b = """
|
|
|
|
import copy_reg as bar, HTMLParser as foo, urlparse
|
|
|
|
s = urlparse.spam(bar.foo())
|
|
|
|
"""
|
|
|
|
a = """
|
|
|
|
import copyreg as bar, html.parser as foo, urllib.parse
|
|
|
|
s = urllib.parse.spam(bar.foo())
|
|
|
|
"""
|
|
|
|
self.check(b, a)
|
|
|
|
|
|
|
|
|
|
|
|
class Test_imports2(FixerTestCase, ImportsFixerTests):
|
Merged revisions 65019 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk
................
r65019 | benjamin.peterson | 2008-07-16 12:01:46 -0500 (Wed, 16 Jul 2008) | 43 lines
Merged revisions 64863,64868,64870,64942,65001-65002,65017-65018 via svnmerge from
svn+ssh://pythondev@svn.python.org/sandbox/trunk/2to3/lib2to3
........
r64863 | brett.cannon | 2008-07-10 19:42:32 -0500 (Thu, 10 Jul 2008) | 1 line
Add urlparse -> urllib.parse to fix_imports.
........
r64868 | brett.cannon | 2008-07-10 20:00:10 -0500 (Thu, 10 Jul 2008) | 1 line
Add robotparser -> urllib.robotparser to fix_imports.
........
r64870 | brett.cannon | 2008-07-11 00:56:27 -0500 (Fri, 11 Jul 2008) | 6 lines
Fix the fixers for the new dbm package.
Had to create a new fixer (fix_imports2) which did fixes in post-order. This
because ``import anydbm`` was being translated into ``import dbm`` which was
then subsequently changed into ``import dbm.ndbm``; one transform too many.
........
r64942 | collin.winter | 2008-07-13 20:19:05 -0500 (Sun, 13 Jul 2008) | 1 line
Add a comment explaining part of fix_imports.py
........
r65001 | brett.cannon | 2008-07-16 00:11:12 -0500 (Wed, 16 Jul 2008) | 2 lines
Remove some extraneous whitespace.
........
r65002 | brett.cannon | 2008-07-16 00:12:04 -0500 (Wed, 16 Jul 2008) | 4 lines
Implement a fixer for urllib(2).
Thanks Nick Edds for the patch.
........
r65017 | benjamin.peterson | 2008-07-16 11:04:19 -0500 (Wed, 16 Jul 2008) | 1 line
fix 2to3 in Python 2.6
........
r65018 | benjamin.peterson | 2008-07-16 11:55:21 -0500 (Wed, 16 Jul 2008) | 1 line
normalize whitespace
........
................
2008-07-16 15:44:47 -03:00
|
|
|
fixer = "imports2"
|
|
|
|
from ..fixes.fix_imports2 import MAPPING as modules
|
|
|
|
|
|
|
|
|
Merged revisions 67806 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk
................
r67806 | benjamin.peterson | 2008-12-15 21:35:28 -0600 (Mon, 15 Dec 2008) | 111 lines
Merged revisions 67427,67431,67433,67435,67630,67652,67656-67657,67674-67675,67678-67679,67705-67706,67716,67723,67765-67771,67774,67776,67778 via svnmerge from
svn+ssh://pythondev@svn.python.org/sandbox/trunk/2to3/lib2to3
........
r67427 | benjamin.peterson | 2008-11-28 16:07:41 -0600 (Fri, 28 Nov 2008) | 1 line
fix spelling in comment
........
r67431 | benjamin.peterson | 2008-11-28 17:14:08 -0600 (Fri, 28 Nov 2008) | 1 line
add a scripts directory; move things to it
........
r67433 | benjamin.peterson | 2008-11-28 17:18:48 -0600 (Fri, 28 Nov 2008) | 1 line
run svneol.py
........
r67435 | benjamin.peterson | 2008-11-28 17:25:03 -0600 (Fri, 28 Nov 2008) | 1 line
rename pre/post_order_mapping to pre/post_order_heads
........
r67630 | alexandre.vassalotti | 2008-12-06 21:51:56 -0600 (Sat, 06 Dec 2008) | 2 lines
Fix typo in the urllib2.HTTPDigestAuthHandler fixer.
........
r67652 | armin.ronacher | 2008-12-07 15:39:43 -0600 (Sun, 07 Dec 2008) | 5 lines
Added a fixer that cleans up a tuple argument to isinstance after the tokens
in it were fixed. This is mainly used to remove double occurrences of
tokens as a leftover of the long -> int / unicode -> str conversion.
........
r67656 | armin.ronacher | 2008-12-07 16:54:16 -0600 (Sun, 07 Dec 2008) | 3 lines
Added missing copyright fo 2to3 fix_isinstance.
........
r67657 | armin.ronacher | 2008-12-07 18:29:35 -0600 (Sun, 07 Dec 2008) | 3 lines
2to3: intern and reduce fixes now add the imports if missing. Because that is a common task the fixer_util module now has a function "touch_import" that adds imports if missing.
........
r67674 | benjamin.peterson | 2008-12-08 19:58:11 -0600 (Mon, 08 Dec 2008) | 1 line
copy permission bits when making backup files #4602
........
r67675 | benjamin.peterson | 2008-12-08 19:59:11 -0600 (Mon, 08 Dec 2008) | 1 line
add forgotten import
........
r67678 | benjamin.peterson | 2008-12-08 20:08:30 -0600 (Mon, 08 Dec 2008) | 1 line
fix #4602 for real
........
r67679 | armin.ronacher | 2008-12-09 00:54:03 -0600 (Tue, 09 Dec 2008) | 3 lines
Removed redudant code from the 2to3 long fixer. This fixes #4590.
........
r67705 | benjamin.peterson | 2008-12-11 13:04:08 -0600 (Thu, 11 Dec 2008) | 1 line
put trailers after a range call after the list()
........
r67706 | benjamin.peterson | 2008-12-11 13:17:57 -0600 (Thu, 11 Dec 2008) | 1 line
add html related modules to the fix_imports mapping
........
r67716 | benjamin.peterson | 2008-12-11 22:16:47 -0600 (Thu, 11 Dec 2008) | 1 line
consolidate tests
........
r67723 | benjamin.peterson | 2008-12-12 19:49:31 -0600 (Fri, 12 Dec 2008) | 1 line
fix name
........
r67765 | benjamin.peterson | 2008-12-14 14:05:05 -0600 (Sun, 14 Dec 2008) | 1 line
run fix_isinstance after fix_long and fix_unicode
........
r67766 | benjamin.peterson | 2008-12-14 14:13:05 -0600 (Sun, 14 Dec 2008) | 1 line
use run_order instead of order
........
r67767 | benjamin.peterson | 2008-12-14 14:28:12 -0600 (Sun, 14 Dec 2008) | 1 line
don't retain parenthesis if there is only one item left
........
r67768 | benjamin.peterson | 2008-12-14 14:32:30 -0600 (Sun, 14 Dec 2008) | 1 line
use insert_child()
........
r67769 | benjamin.peterson | 2008-12-14 14:59:10 -0600 (Sun, 14 Dec 2008) | 1 line
parenthesize doesn't belong in pygram or FixerBase
........
r67770 | alexandre.vassalotti | 2008-12-14 15:15:36 -0600 (Sun, 14 Dec 2008) | 2 lines
Fix typo: html.paser -> html.parser.
........
r67771 | benjamin.peterson | 2008-12-14 15:22:09 -0600 (Sun, 14 Dec 2008) | 1 line
altering .children needs to call changed()
........
r67774 | benjamin.peterson | 2008-12-14 15:55:38 -0600 (Sun, 14 Dec 2008) | 1 line
employ an evil hack to fix multiple names in the same import statement
........
r67776 | benjamin.peterson | 2008-12-14 16:22:38 -0600 (Sun, 14 Dec 2008) | 1 line
make a common mixin class for Test_imports and friends
........
r67778 | alexandre.vassalotti | 2008-12-14 17:48:20 -0600 (Sun, 14 Dec 2008) | 2 lines
Make fix_imports refactor multiple imports as.
........
................
2008-12-15 23:57:54 -04:00
|
|
|
class Test_imports_fixer_order(FixerTestCase, ImportsFixerTests):
|
Merged revisions 65019 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk
................
r65019 | benjamin.peterson | 2008-07-16 12:01:46 -0500 (Wed, 16 Jul 2008) | 43 lines
Merged revisions 64863,64868,64870,64942,65001-65002,65017-65018 via svnmerge from
svn+ssh://pythondev@svn.python.org/sandbox/trunk/2to3/lib2to3
........
r64863 | brett.cannon | 2008-07-10 19:42:32 -0500 (Thu, 10 Jul 2008) | 1 line
Add urlparse -> urllib.parse to fix_imports.
........
r64868 | brett.cannon | 2008-07-10 20:00:10 -0500 (Thu, 10 Jul 2008) | 1 line
Add robotparser -> urllib.robotparser to fix_imports.
........
r64870 | brett.cannon | 2008-07-11 00:56:27 -0500 (Fri, 11 Jul 2008) | 6 lines
Fix the fixers for the new dbm package.
Had to create a new fixer (fix_imports2) which did fixes in post-order. This
because ``import anydbm`` was being translated into ``import dbm`` which was
then subsequently changed into ``import dbm.ndbm``; one transform too many.
........
r64942 | collin.winter | 2008-07-13 20:19:05 -0500 (Sun, 13 Jul 2008) | 1 line
Add a comment explaining part of fix_imports.py
........
r65001 | brett.cannon | 2008-07-16 00:11:12 -0500 (Wed, 16 Jul 2008) | 2 lines
Remove some extraneous whitespace.
........
r65002 | brett.cannon | 2008-07-16 00:12:04 -0500 (Wed, 16 Jul 2008) | 4 lines
Implement a fixer for urllib(2).
Thanks Nick Edds for the patch.
........
r65017 | benjamin.peterson | 2008-07-16 11:04:19 -0500 (Wed, 16 Jul 2008) | 1 line
fix 2to3 in Python 2.6
........
r65018 | benjamin.peterson | 2008-07-16 11:55:21 -0500 (Wed, 16 Jul 2008) | 1 line
normalize whitespace
........
................
2008-07-16 15:44:47 -03:00
|
|
|
|
|
|
|
def setUp(self):
|
Merged revisions 67806 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk
................
r67806 | benjamin.peterson | 2008-12-15 21:35:28 -0600 (Mon, 15 Dec 2008) | 111 lines
Merged revisions 67427,67431,67433,67435,67630,67652,67656-67657,67674-67675,67678-67679,67705-67706,67716,67723,67765-67771,67774,67776,67778 via svnmerge from
svn+ssh://pythondev@svn.python.org/sandbox/trunk/2to3/lib2to3
........
r67427 | benjamin.peterson | 2008-11-28 16:07:41 -0600 (Fri, 28 Nov 2008) | 1 line
fix spelling in comment
........
r67431 | benjamin.peterson | 2008-11-28 17:14:08 -0600 (Fri, 28 Nov 2008) | 1 line
add a scripts directory; move things to it
........
r67433 | benjamin.peterson | 2008-11-28 17:18:48 -0600 (Fri, 28 Nov 2008) | 1 line
run svneol.py
........
r67435 | benjamin.peterson | 2008-11-28 17:25:03 -0600 (Fri, 28 Nov 2008) | 1 line
rename pre/post_order_mapping to pre/post_order_heads
........
r67630 | alexandre.vassalotti | 2008-12-06 21:51:56 -0600 (Sat, 06 Dec 2008) | 2 lines
Fix typo in the urllib2.HTTPDigestAuthHandler fixer.
........
r67652 | armin.ronacher | 2008-12-07 15:39:43 -0600 (Sun, 07 Dec 2008) | 5 lines
Added a fixer that cleans up a tuple argument to isinstance after the tokens
in it were fixed. This is mainly used to remove double occurrences of
tokens as a leftover of the long -> int / unicode -> str conversion.
........
r67656 | armin.ronacher | 2008-12-07 16:54:16 -0600 (Sun, 07 Dec 2008) | 3 lines
Added missing copyright fo 2to3 fix_isinstance.
........
r67657 | armin.ronacher | 2008-12-07 18:29:35 -0600 (Sun, 07 Dec 2008) | 3 lines
2to3: intern and reduce fixes now add the imports if missing. Because that is a common task the fixer_util module now has a function "touch_import" that adds imports if missing.
........
r67674 | benjamin.peterson | 2008-12-08 19:58:11 -0600 (Mon, 08 Dec 2008) | 1 line
copy permission bits when making backup files #4602
........
r67675 | benjamin.peterson | 2008-12-08 19:59:11 -0600 (Mon, 08 Dec 2008) | 1 line
add forgotten import
........
r67678 | benjamin.peterson | 2008-12-08 20:08:30 -0600 (Mon, 08 Dec 2008) | 1 line
fix #4602 for real
........
r67679 | armin.ronacher | 2008-12-09 00:54:03 -0600 (Tue, 09 Dec 2008) | 3 lines
Removed redudant code from the 2to3 long fixer. This fixes #4590.
........
r67705 | benjamin.peterson | 2008-12-11 13:04:08 -0600 (Thu, 11 Dec 2008) | 1 line
put trailers after a range call after the list()
........
r67706 | benjamin.peterson | 2008-12-11 13:17:57 -0600 (Thu, 11 Dec 2008) | 1 line
add html related modules to the fix_imports mapping
........
r67716 | benjamin.peterson | 2008-12-11 22:16:47 -0600 (Thu, 11 Dec 2008) | 1 line
consolidate tests
........
r67723 | benjamin.peterson | 2008-12-12 19:49:31 -0600 (Fri, 12 Dec 2008) | 1 line
fix name
........
r67765 | benjamin.peterson | 2008-12-14 14:05:05 -0600 (Sun, 14 Dec 2008) | 1 line
run fix_isinstance after fix_long and fix_unicode
........
r67766 | benjamin.peterson | 2008-12-14 14:13:05 -0600 (Sun, 14 Dec 2008) | 1 line
use run_order instead of order
........
r67767 | benjamin.peterson | 2008-12-14 14:28:12 -0600 (Sun, 14 Dec 2008) | 1 line
don't retain parenthesis if there is only one item left
........
r67768 | benjamin.peterson | 2008-12-14 14:32:30 -0600 (Sun, 14 Dec 2008) | 1 line
use insert_child()
........
r67769 | benjamin.peterson | 2008-12-14 14:59:10 -0600 (Sun, 14 Dec 2008) | 1 line
parenthesize doesn't belong in pygram or FixerBase
........
r67770 | alexandre.vassalotti | 2008-12-14 15:15:36 -0600 (Sun, 14 Dec 2008) | 2 lines
Fix typo: html.paser -> html.parser.
........
r67771 | benjamin.peterson | 2008-12-14 15:22:09 -0600 (Sun, 14 Dec 2008) | 1 line
altering .children needs to call changed()
........
r67774 | benjamin.peterson | 2008-12-14 15:55:38 -0600 (Sun, 14 Dec 2008) | 1 line
employ an evil hack to fix multiple names in the same import statement
........
r67776 | benjamin.peterson | 2008-12-14 16:22:38 -0600 (Sun, 14 Dec 2008) | 1 line
make a common mixin class for Test_imports and friends
........
r67778 | alexandre.vassalotti | 2008-12-14 17:48:20 -0600 (Sun, 14 Dec 2008) | 2 lines
Make fix_imports refactor multiple imports as.
........
................
2008-12-15 23:57:54 -04:00
|
|
|
super(Test_imports_fixer_order, self).setUp(['imports', 'imports2'])
|
Merged revisions 65019 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk
................
r65019 | benjamin.peterson | 2008-07-16 12:01:46 -0500 (Wed, 16 Jul 2008) | 43 lines
Merged revisions 64863,64868,64870,64942,65001-65002,65017-65018 via svnmerge from
svn+ssh://pythondev@svn.python.org/sandbox/trunk/2to3/lib2to3
........
r64863 | brett.cannon | 2008-07-10 19:42:32 -0500 (Thu, 10 Jul 2008) | 1 line
Add urlparse -> urllib.parse to fix_imports.
........
r64868 | brett.cannon | 2008-07-10 20:00:10 -0500 (Thu, 10 Jul 2008) | 1 line
Add robotparser -> urllib.robotparser to fix_imports.
........
r64870 | brett.cannon | 2008-07-11 00:56:27 -0500 (Fri, 11 Jul 2008) | 6 lines
Fix the fixers for the new dbm package.
Had to create a new fixer (fix_imports2) which did fixes in post-order. This
because ``import anydbm`` was being translated into ``import dbm`` which was
then subsequently changed into ``import dbm.ndbm``; one transform too many.
........
r64942 | collin.winter | 2008-07-13 20:19:05 -0500 (Sun, 13 Jul 2008) | 1 line
Add a comment explaining part of fix_imports.py
........
r65001 | brett.cannon | 2008-07-16 00:11:12 -0500 (Wed, 16 Jul 2008) | 2 lines
Remove some extraneous whitespace.
........
r65002 | brett.cannon | 2008-07-16 00:12:04 -0500 (Wed, 16 Jul 2008) | 4 lines
Implement a fixer for urllib(2).
Thanks Nick Edds for the patch.
........
r65017 | benjamin.peterson | 2008-07-16 11:04:19 -0500 (Wed, 16 Jul 2008) | 1 line
fix 2to3 in Python 2.6
........
r65018 | benjamin.peterson | 2008-07-16 11:55:21 -0500 (Wed, 16 Jul 2008) | 1 line
normalize whitespace
........
................
2008-07-16 15:44:47 -03:00
|
|
|
from ..fixes.fix_imports2 import MAPPING as mapping2
|
|
|
|
self.modules = mapping2.copy()
|
|
|
|
from ..fixes.fix_imports import MAPPING as mapping1
|
|
|
|
for key in ('dbhash', 'dumbdbm', 'dbm', 'gdbm'):
|
|
|
|
self.modules[key] = mapping1[key]
|
|
|
|
|
2009-07-21 09:55:57 -03:00
|
|
|
def test_after_local_imports_refactoring(self):
|
|
|
|
for fix in ("imports", "imports2"):
|
|
|
|
self.fixer = fix
|
|
|
|
self.assert_runs_after("import")
|
|
|
|
|
Merged revisions 65019 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk
................
r65019 | benjamin.peterson | 2008-07-16 12:01:46 -0500 (Wed, 16 Jul 2008) | 43 lines
Merged revisions 64863,64868,64870,64942,65001-65002,65017-65018 via svnmerge from
svn+ssh://pythondev@svn.python.org/sandbox/trunk/2to3/lib2to3
........
r64863 | brett.cannon | 2008-07-10 19:42:32 -0500 (Thu, 10 Jul 2008) | 1 line
Add urlparse -> urllib.parse to fix_imports.
........
r64868 | brett.cannon | 2008-07-10 20:00:10 -0500 (Thu, 10 Jul 2008) | 1 line
Add robotparser -> urllib.robotparser to fix_imports.
........
r64870 | brett.cannon | 2008-07-11 00:56:27 -0500 (Fri, 11 Jul 2008) | 6 lines
Fix the fixers for the new dbm package.
Had to create a new fixer (fix_imports2) which did fixes in post-order. This
because ``import anydbm`` was being translated into ``import dbm`` which was
then subsequently changed into ``import dbm.ndbm``; one transform too many.
........
r64942 | collin.winter | 2008-07-13 20:19:05 -0500 (Sun, 13 Jul 2008) | 1 line
Add a comment explaining part of fix_imports.py
........
r65001 | brett.cannon | 2008-07-16 00:11:12 -0500 (Wed, 16 Jul 2008) | 2 lines
Remove some extraneous whitespace.
........
r65002 | brett.cannon | 2008-07-16 00:12:04 -0500 (Wed, 16 Jul 2008) | 4 lines
Implement a fixer for urllib(2).
Thanks Nick Edds for the patch.
........
r65017 | benjamin.peterson | 2008-07-16 11:04:19 -0500 (Wed, 16 Jul 2008) | 1 line
fix 2to3 in Python 2.6
........
r65018 | benjamin.peterson | 2008-07-16 11:55:21 -0500 (Wed, 16 Jul 2008) | 1 line
normalize whitespace
........
................
2008-07-16 15:44:47 -03:00
|
|
|
|
|
|
|
class Test_urllib(FixerTestCase):
|
|
|
|
fixer = "urllib"
|
|
|
|
from ..fixes.fix_urllib import MAPPING as modules
|
|
|
|
|
|
|
|
def test_import_module(self):
|
|
|
|
for old, changes in self.modules.items():
|
|
|
|
b = "import %s" % old
|
|
|
|
a = "import %s" % ", ".join(map(itemgetter(0), changes))
|
|
|
|
self.check(b, a)
|
|
|
|
|
|
|
|
def test_import_from(self):
|
|
|
|
for old, changes in self.modules.items():
|
|
|
|
all_members = []
|
|
|
|
for new, members in changes:
|
|
|
|
for member in members:
|
|
|
|
all_members.append(member)
|
|
|
|
b = "from %s import %s" % (old, member)
|
|
|
|
a = "from %s import %s" % (new, member)
|
|
|
|
self.check(b, a)
|
|
|
|
|
|
|
|
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)
|
|
|
|
|
|
|
|
# test the breaking of a module into multiple replacements
|
|
|
|
b = "from %s import %s" % (old, ", ".join(all_members))
|
|
|
|
a = "\n".join(["from %s import %s" % (new, ", ".join(members))
|
|
|
|
for (new, members) in changes])
|
|
|
|
self.check(b, a)
|
|
|
|
|
|
|
|
def test_import_module_as(self):
|
|
|
|
for old in self.modules:
|
|
|
|
s = "import %s as foo" % old
|
|
|
|
self.warns_unchanged(s, "This module is now multiple modules")
|
|
|
|
|
|
|
|
def test_import_from_as(self):
|
|
|
|
for old, changes in self.modules.items():
|
|
|
|
for new, members in changes:
|
|
|
|
for member in members:
|
|
|
|
b = "from %s import %s as foo_bar" % (old, member)
|
|
|
|
a = "from %s import %s as foo_bar" % (new, member)
|
|
|
|
self.check(b, a)
|
|
|
|
|
|
|
|
def test_star(self):
|
|
|
|
for old in self.modules:
|
|
|
|
s = "from %s import *" % old
|
|
|
|
self.warns_unchanged(s, "Cannot handle star imports")
|
|
|
|
|
|
|
|
def test_import_module_usage(self):
|
|
|
|
for old, changes in self.modules.items():
|
|
|
|
for new, members in changes:
|
|
|
|
for member in members:
|
Merged revisions 76518 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/branches/py3k
................
r76518 | benjamin.peterson | 2009-11-25 12:34:42 -0600 (Wed, 25 Nov 2009) | 60 lines
Merged revisions 76259,76326,76376-76377,76430,76471,76517 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk
................
r76259 | georg.brandl | 2009-11-14 05:50:51 -0600 (Sat, 14 Nov 2009) | 1 line
Fix terminology.
................
r76326 | georg.brandl | 2009-11-16 10:44:05 -0600 (Mon, 16 Nov 2009) | 1 line
#7302: fix link.
................
r76376 | georg.brandl | 2009-11-18 13:39:14 -0600 (Wed, 18 Nov 2009) | 1 line
upcase Python
................
r76377 | georg.brandl | 2009-11-18 14:05:15 -0600 (Wed, 18 Nov 2009) | 1 line
Fix markup.
................
r76430 | r.david.murray | 2009-11-20 07:29:43 -0600 (Fri, 20 Nov 2009) | 2 lines
Issue 7363: fix indentation in socketserver udpserver example.
................
r76471 | georg.brandl | 2009-11-23 13:53:19 -0600 (Mon, 23 Nov 2009) | 1 line
#7345: fix arguments of formatyear().
................
r76517 | benjamin.peterson | 2009-11-25 12:16:46 -0600 (Wed, 25 Nov 2009) | 29 lines
Merged revisions 76160-76161,76250,76252,76447,76506 via svnmerge from
svn+ssh://pythondev@svn.python.org/sandbox/trunk/2to3/lib2to3
........
r76160 | benjamin.peterson | 2009-11-08 18:53:48 -0600 (Sun, 08 Nov 2009) | 1 line
undeprecate the -p option; it's useful for converting python3 sources
........
r76161 | benjamin.peterson | 2009-11-08 19:05:37 -0600 (Sun, 08 Nov 2009) | 1 line
simplify condition
........
r76250 | benjamin.peterson | 2009-11-13 16:56:48 -0600 (Fri, 13 Nov 2009) | 1 line
fix handling of a utf-8 bom #7313
........
r76252 | benjamin.peterson | 2009-11-13 16:58:36 -0600 (Fri, 13 Nov 2009) | 1 line
remove pdb turd
........
r76447 | benjamin.peterson | 2009-11-22 18:17:40 -0600 (Sun, 22 Nov 2009) | 1 line
#7375 fix nested transformations in fix_urllib
........
r76506 | benjamin.peterson | 2009-11-24 18:34:31 -0600 (Tue, 24 Nov 2009) | 1 line
use generator expressions in any()
........
................
................
2009-11-25 14:37:12 -04:00
|
|
|
new_import = ", ".join([n for (n, mems)
|
|
|
|
in self.modules[old]])
|
Merged revisions 65019 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk
................
r65019 | benjamin.peterson | 2008-07-16 12:01:46 -0500 (Wed, 16 Jul 2008) | 43 lines
Merged revisions 64863,64868,64870,64942,65001-65002,65017-65018 via svnmerge from
svn+ssh://pythondev@svn.python.org/sandbox/trunk/2to3/lib2to3
........
r64863 | brett.cannon | 2008-07-10 19:42:32 -0500 (Thu, 10 Jul 2008) | 1 line
Add urlparse -> urllib.parse to fix_imports.
........
r64868 | brett.cannon | 2008-07-10 20:00:10 -0500 (Thu, 10 Jul 2008) | 1 line
Add robotparser -> urllib.robotparser to fix_imports.
........
r64870 | brett.cannon | 2008-07-11 00:56:27 -0500 (Fri, 11 Jul 2008) | 6 lines
Fix the fixers for the new dbm package.
Had to create a new fixer (fix_imports2) which did fixes in post-order. This
because ``import anydbm`` was being translated into ``import dbm`` which was
then subsequently changed into ``import dbm.ndbm``; one transform too many.
........
r64942 | collin.winter | 2008-07-13 20:19:05 -0500 (Sun, 13 Jul 2008) | 1 line
Add a comment explaining part of fix_imports.py
........
r65001 | brett.cannon | 2008-07-16 00:11:12 -0500 (Wed, 16 Jul 2008) | 2 lines
Remove some extraneous whitespace.
........
r65002 | brett.cannon | 2008-07-16 00:12:04 -0500 (Wed, 16 Jul 2008) | 4 lines
Implement a fixer for urllib(2).
Thanks Nick Edds for the patch.
........
r65017 | benjamin.peterson | 2008-07-16 11:04:19 -0500 (Wed, 16 Jul 2008) | 1 line
fix 2to3 in Python 2.6
........
r65018 | benjamin.peterson | 2008-07-16 11:55:21 -0500 (Wed, 16 Jul 2008) | 1 line
normalize whitespace
........
................
2008-07-16 15:44:47 -03:00
|
|
|
b = """
|
|
|
|
import %s
|
|
|
|
foo(%s.%s)
|
|
|
|
""" % (old, old, member)
|
|
|
|
a = """
|
|
|
|
import %s
|
|
|
|
foo(%s.%s)
|
Merged revisions 76518 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/branches/py3k
................
r76518 | benjamin.peterson | 2009-11-25 12:34:42 -0600 (Wed, 25 Nov 2009) | 60 lines
Merged revisions 76259,76326,76376-76377,76430,76471,76517 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk
................
r76259 | georg.brandl | 2009-11-14 05:50:51 -0600 (Sat, 14 Nov 2009) | 1 line
Fix terminology.
................
r76326 | georg.brandl | 2009-11-16 10:44:05 -0600 (Mon, 16 Nov 2009) | 1 line
#7302: fix link.
................
r76376 | georg.brandl | 2009-11-18 13:39:14 -0600 (Wed, 18 Nov 2009) | 1 line
upcase Python
................
r76377 | georg.brandl | 2009-11-18 14:05:15 -0600 (Wed, 18 Nov 2009) | 1 line
Fix markup.
................
r76430 | r.david.murray | 2009-11-20 07:29:43 -0600 (Fri, 20 Nov 2009) | 2 lines
Issue 7363: fix indentation in socketserver udpserver example.
................
r76471 | georg.brandl | 2009-11-23 13:53:19 -0600 (Mon, 23 Nov 2009) | 1 line
#7345: fix arguments of formatyear().
................
r76517 | benjamin.peterson | 2009-11-25 12:16:46 -0600 (Wed, 25 Nov 2009) | 29 lines
Merged revisions 76160-76161,76250,76252,76447,76506 via svnmerge from
svn+ssh://pythondev@svn.python.org/sandbox/trunk/2to3/lib2to3
........
r76160 | benjamin.peterson | 2009-11-08 18:53:48 -0600 (Sun, 08 Nov 2009) | 1 line
undeprecate the -p option; it's useful for converting python3 sources
........
r76161 | benjamin.peterson | 2009-11-08 19:05:37 -0600 (Sun, 08 Nov 2009) | 1 line
simplify condition
........
r76250 | benjamin.peterson | 2009-11-13 16:56:48 -0600 (Fri, 13 Nov 2009) | 1 line
fix handling of a utf-8 bom #7313
........
r76252 | benjamin.peterson | 2009-11-13 16:58:36 -0600 (Fri, 13 Nov 2009) | 1 line
remove pdb turd
........
r76447 | benjamin.peterson | 2009-11-22 18:17:40 -0600 (Sun, 22 Nov 2009) | 1 line
#7375 fix nested transformations in fix_urllib
........
r76506 | benjamin.peterson | 2009-11-24 18:34:31 -0600 (Tue, 24 Nov 2009) | 1 line
use generator expressions in any()
........
................
................
2009-11-25 14:37:12 -04:00
|
|
|
""" % (new_import, new, member)
|
|
|
|
self.check(b, a)
|
|
|
|
b = """
|
|
|
|
import %s
|
|
|
|
%s.%s(%s.%s)
|
|
|
|
""" % (old, old, member, old, member)
|
|
|
|
a = """
|
|
|
|
import %s
|
|
|
|
%s.%s(%s.%s)
|
|
|
|
""" % (new_import, new, member, new, member)
|
Merged revisions 65019 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk
................
r65019 | benjamin.peterson | 2008-07-16 12:01:46 -0500 (Wed, 16 Jul 2008) | 43 lines
Merged revisions 64863,64868,64870,64942,65001-65002,65017-65018 via svnmerge from
svn+ssh://pythondev@svn.python.org/sandbox/trunk/2to3/lib2to3
........
r64863 | brett.cannon | 2008-07-10 19:42:32 -0500 (Thu, 10 Jul 2008) | 1 line
Add urlparse -> urllib.parse to fix_imports.
........
r64868 | brett.cannon | 2008-07-10 20:00:10 -0500 (Thu, 10 Jul 2008) | 1 line
Add robotparser -> urllib.robotparser to fix_imports.
........
r64870 | brett.cannon | 2008-07-11 00:56:27 -0500 (Fri, 11 Jul 2008) | 6 lines
Fix the fixers for the new dbm package.
Had to create a new fixer (fix_imports2) which did fixes in post-order. This
because ``import anydbm`` was being translated into ``import dbm`` which was
then subsequently changed into ``import dbm.ndbm``; one transform too many.
........
r64942 | collin.winter | 2008-07-13 20:19:05 -0500 (Sun, 13 Jul 2008) | 1 line
Add a comment explaining part of fix_imports.py
........
r65001 | brett.cannon | 2008-07-16 00:11:12 -0500 (Wed, 16 Jul 2008) | 2 lines
Remove some extraneous whitespace.
........
r65002 | brett.cannon | 2008-07-16 00:12:04 -0500 (Wed, 16 Jul 2008) | 4 lines
Implement a fixer for urllib(2).
Thanks Nick Edds for the patch.
........
r65017 | benjamin.peterson | 2008-07-16 11:04:19 -0500 (Wed, 16 Jul 2008) | 1 line
fix 2to3 in Python 2.6
........
r65018 | benjamin.peterson | 2008-07-16 11:55:21 -0500 (Wed, 16 Jul 2008) | 1 line
normalize whitespace
........
................
2008-07-16 15:44:47 -03:00
|
|
|
self.check(b, a)
|
|
|
|
|
|
|
|
|
2008-03-19 02:04:44 -03:00
|
|
|
class Test_input(FixerTestCase):
|
|
|
|
fixer = "input"
|
|
|
|
|
|
|
|
def test_prefix_preservation(self):
|
|
|
|
b = """x = input( )"""
|
|
|
|
a = """x = eval(input( ))"""
|
|
|
|
self.check(b, a)
|
|
|
|
|
|
|
|
b = """x = input( '' )"""
|
|
|
|
a = """x = eval(input( '' ))"""
|
|
|
|
self.check(b, a)
|
|
|
|
|
|
|
|
def test_trailing_comment(self):
|
|
|
|
b = """x = input() # foo"""
|
|
|
|
a = """x = eval(input()) # foo"""
|
|
|
|
self.check(b, a)
|
|
|
|
|
|
|
|
def test_idempotency(self):
|
|
|
|
s = """x = eval(input())"""
|
|
|
|
self.unchanged(s)
|
|
|
|
|
|
|
|
s = """x = eval(input(''))"""
|
|
|
|
self.unchanged(s)
|
|
|
|
|
|
|
|
s = """x = eval(input(foo(5) + 9))"""
|
|
|
|
self.unchanged(s)
|
|
|
|
|
|
|
|
def test_1(self):
|
|
|
|
b = """x = input()"""
|
|
|
|
a = """x = eval(input())"""
|
|
|
|
self.check(b, a)
|
|
|
|
|
|
|
|
def test_2(self):
|
|
|
|
b = """x = input('')"""
|
|
|
|
a = """x = eval(input(''))"""
|
|
|
|
self.check(b, a)
|
|
|
|
|
|
|
|
def test_3(self):
|
|
|
|
b = """x = input('prompt')"""
|
|
|
|
a = """x = eval(input('prompt'))"""
|
|
|
|
self.check(b, a)
|
|
|
|
|
|
|
|
def test_4(self):
|
|
|
|
b = """x = input(foo(5) + 9)"""
|
|
|
|
a = """x = eval(input(foo(5) + 9))"""
|
|
|
|
self.check(b, a)
|
|
|
|
|
|
|
|
class Test_tuple_params(FixerTestCase):
|
|
|
|
fixer = "tuple_params"
|
|
|
|
|
|
|
|
def test_unchanged_1(self):
|
|
|
|
s = """def foo(): pass"""
|
|
|
|
self.unchanged(s)
|
|
|
|
|
|
|
|
def test_unchanged_2(self):
|
|
|
|
s = """def foo(a, b, c): pass"""
|
|
|
|
self.unchanged(s)
|
|
|
|
|
|
|
|
def test_unchanged_3(self):
|
|
|
|
s = """def foo(a=3, b=4, c=5): pass"""
|
|
|
|
self.unchanged(s)
|
|
|
|
|
|
|
|
def test_1(self):
|
|
|
|
b = """
|
|
|
|
def foo(((a, b), c)):
|
|
|
|
x = 5"""
|
|
|
|
|
|
|
|
a = """
|
|
|
|
def foo(xxx_todo_changeme):
|
|
|
|
((a, b), c) = xxx_todo_changeme
|
|
|
|
x = 5"""
|
|
|
|
self.check(b, a)
|
|
|
|
|
|
|
|
def test_2(self):
|
|
|
|
b = """
|
|
|
|
def foo(((a, b), c), d):
|
|
|
|
x = 5"""
|
|
|
|
|
|
|
|
a = """
|
|
|
|
def foo(xxx_todo_changeme, d):
|
|
|
|
((a, b), c) = xxx_todo_changeme
|
|
|
|
x = 5"""
|
|
|
|
self.check(b, a)
|
|
|
|
|
|
|
|
def test_3(self):
|
|
|
|
b = """
|
|
|
|
def foo(((a, b), c), d) -> e:
|
|
|
|
x = 5"""
|
|
|
|
|
|
|
|
a = """
|
|
|
|
def foo(xxx_todo_changeme, d) -> e:
|
|
|
|
((a, b), c) = xxx_todo_changeme
|
|
|
|
x = 5"""
|
|
|
|
self.check(b, a)
|
|
|
|
|
|
|
|
def test_semicolon(self):
|
|
|
|
b = """
|
|
|
|
def foo(((a, b), c)): x = 5; y = 7"""
|
|
|
|
|
|
|
|
a = """
|
|
|
|
def foo(xxx_todo_changeme): ((a, b), c) = xxx_todo_changeme; x = 5; y = 7"""
|
|
|
|
self.check(b, a)
|
|
|
|
|
|
|
|
def test_keywords(self):
|
|
|
|
b = """
|
|
|
|
def foo(((a, b), c), d, e=5) -> z:
|
|
|
|
x = 5"""
|
|
|
|
|
|
|
|
a = """
|
|
|
|
def foo(xxx_todo_changeme, d, e=5) -> z:
|
|
|
|
((a, b), c) = xxx_todo_changeme
|
|
|
|
x = 5"""
|
|
|
|
self.check(b, a)
|
|
|
|
|
|
|
|
def test_varargs(self):
|
|
|
|
b = """
|
|
|
|
def foo(((a, b), c), d, *vargs, **kwargs) -> z:
|
|
|
|
x = 5"""
|
|
|
|
|
|
|
|
a = """
|
|
|
|
def foo(xxx_todo_changeme, d, *vargs, **kwargs) -> z:
|
|
|
|
((a, b), c) = xxx_todo_changeme
|
|
|
|
x = 5"""
|
|
|
|
self.check(b, a)
|
|
|
|
|
|
|
|
def test_multi_1(self):
|
|
|
|
b = """
|
|
|
|
def foo(((a, b), c), (d, e, f)) -> z:
|
|
|
|
x = 5"""
|
|
|
|
|
|
|
|
a = """
|
|
|
|
def foo(xxx_todo_changeme, xxx_todo_changeme1) -> z:
|
|
|
|
((a, b), c) = xxx_todo_changeme
|
|
|
|
(d, e, f) = xxx_todo_changeme1
|
|
|
|
x = 5"""
|
|
|
|
self.check(b, a)
|
|
|
|
|
|
|
|
def test_multi_2(self):
|
|
|
|
b = """
|
|
|
|
def foo(x, ((a, b), c), d, (e, f, g), y) -> z:
|
|
|
|
x = 5"""
|
|
|
|
|
|
|
|
a = """
|
|
|
|
def foo(x, xxx_todo_changeme, d, xxx_todo_changeme1, y) -> z:
|
|
|
|
((a, b), c) = xxx_todo_changeme
|
|
|
|
(e, f, g) = xxx_todo_changeme1
|
|
|
|
x = 5"""
|
|
|
|
self.check(b, a)
|
|
|
|
|
|
|
|
def test_docstring(self):
|
|
|
|
b = """
|
|
|
|
def foo(((a, b), c), (d, e, f)) -> z:
|
|
|
|
"foo foo foo foo"
|
|
|
|
x = 5"""
|
|
|
|
|
|
|
|
a = """
|
|
|
|
def foo(xxx_todo_changeme, xxx_todo_changeme1) -> z:
|
|
|
|
"foo foo foo foo"
|
|
|
|
((a, b), c) = xxx_todo_changeme
|
|
|
|
(d, e, f) = xxx_todo_changeme1
|
|
|
|
x = 5"""
|
|
|
|
self.check(b, a)
|
|
|
|
|
|
|
|
def test_lambda_no_change(self):
|
|
|
|
s = """lambda x: x + 5"""
|
|
|
|
self.unchanged(s)
|
|
|
|
|
|
|
|
def test_lambda_parens_single_arg(self):
|
|
|
|
b = """lambda (x): x + 5"""
|
|
|
|
a = """lambda x: x + 5"""
|
|
|
|
self.check(b, a)
|
|
|
|
|
|
|
|
b = """lambda(x): x + 5"""
|
|
|
|
a = """lambda x: x + 5"""
|
|
|
|
self.check(b, a)
|
|
|
|
|
|
|
|
b = """lambda ((((x)))): x + 5"""
|
|
|
|
a = """lambda x: x + 5"""
|
|
|
|
self.check(b, a)
|
|
|
|
|
|
|
|
b = """lambda((((x)))): x + 5"""
|
|
|
|
a = """lambda x: x + 5"""
|
|
|
|
self.check(b, a)
|
|
|
|
|
|
|
|
def test_lambda_simple(self):
|
|
|
|
b = """lambda (x, y): x + f(y)"""
|
|
|
|
a = """lambda x_y: x_y[0] + f(x_y[1])"""
|
|
|
|
self.check(b, a)
|
|
|
|
|
|
|
|
b = """lambda(x, y): x + f(y)"""
|
|
|
|
a = """lambda x_y: x_y[0] + f(x_y[1])"""
|
|
|
|
self.check(b, a)
|
|
|
|
|
|
|
|
b = """lambda (((x, y))): x + f(y)"""
|
|
|
|
a = """lambda x_y: x_y[0] + f(x_y[1])"""
|
|
|
|
self.check(b, a)
|
|
|
|
|
|
|
|
b = """lambda(((x, y))): x + f(y)"""
|
|
|
|
a = """lambda x_y: x_y[0] + f(x_y[1])"""
|
|
|
|
self.check(b, a)
|
|
|
|
|
|
|
|
def test_lambda_one_tuple(self):
|
|
|
|
b = """lambda (x,): x + f(x)"""
|
|
|
|
a = """lambda x1: x1[0] + f(x1[0])"""
|
|
|
|
self.check(b, a)
|
|
|
|
|
|
|
|
b = """lambda (((x,))): x + f(x)"""
|
|
|
|
a = """lambda x1: x1[0] + f(x1[0])"""
|
|
|
|
self.check(b, a)
|
|
|
|
|
|
|
|
def test_lambda_simple_multi_use(self):
|
|
|
|
b = """lambda (x, y): x + x + f(x) + x"""
|
|
|
|
a = """lambda x_y: x_y[0] + x_y[0] + f(x_y[0]) + x_y[0]"""
|
|
|
|
self.check(b, a)
|
|
|
|
|
|
|
|
def test_lambda_simple_reverse(self):
|
|
|
|
b = """lambda (x, y): y + x"""
|
|
|
|
a = """lambda x_y: x_y[1] + x_y[0]"""
|
|
|
|
self.check(b, a)
|
|
|
|
|
|
|
|
def test_lambda_nested(self):
|
|
|
|
b = """lambda (x, (y, z)): x + y + z"""
|
|
|
|
a = """lambda x_y_z: x_y_z[0] + x_y_z[1][0] + x_y_z[1][1]"""
|
|
|
|
self.check(b, a)
|
|
|
|
|
|
|
|
b = """lambda (((x, (y, z)))): x + y + z"""
|
|
|
|
a = """lambda x_y_z: x_y_z[0] + x_y_z[1][0] + x_y_z[1][1]"""
|
|
|
|
self.check(b, a)
|
|
|
|
|
|
|
|
def test_lambda_nested_multi_use(self):
|
|
|
|
b = """lambda (x, (y, z)): x + y + f(y)"""
|
|
|
|
a = """lambda x_y_z: x_y_z[0] + x_y_z[1][0] + f(x_y_z[1][0])"""
|
|
|
|
self.check(b, a)
|
|
|
|
|
|
|
|
class Test_methodattrs(FixerTestCase):
|
|
|
|
fixer = "methodattrs"
|
|
|
|
|
|
|
|
attrs = ["func", "self", "class"]
|
|
|
|
|
|
|
|
def test(self):
|
|
|
|
for attr in self.attrs:
|
|
|
|
b = "a.im_%s" % attr
|
|
|
|
if attr == "class":
|
|
|
|
a = "a.__self__.__class__"
|
|
|
|
else:
|
|
|
|
a = "a.__%s__" % attr
|
|
|
|
self.check(b, a)
|
|
|
|
|
|
|
|
b = "self.foo.im_%s.foo_bar" % attr
|
|
|
|
if attr == "class":
|
|
|
|
a = "self.foo.__self__.__class__.foo_bar"
|
|
|
|
else:
|
|
|
|
a = "self.foo.__%s__.foo_bar" % attr
|
|
|
|
self.check(b, a)
|
|
|
|
|
|
|
|
def test_unchanged(self):
|
|
|
|
for attr in self.attrs:
|
|
|
|
s = "foo(im_%s + 5)" % attr
|
|
|
|
self.unchanged(s)
|
|
|
|
|
|
|
|
s = "f(foo.__%s__)" % attr
|
|
|
|
self.unchanged(s)
|
|
|
|
|
|
|
|
s = "f(foo.__%s__.foo)" % attr
|
|
|
|
self.unchanged(s)
|
|
|
|
|
|
|
|
class Test_next(FixerTestCase):
|
|
|
|
fixer = "next"
|
|
|
|
|
|
|
|
def test_1(self):
|
|
|
|
b = """it.next()"""
|
|
|
|
a = """next(it)"""
|
|
|
|
self.check(b, a)
|
|
|
|
|
|
|
|
def test_2(self):
|
|
|
|
b = """a.b.c.d.next()"""
|
|
|
|
a = """next(a.b.c.d)"""
|
|
|
|
self.check(b, a)
|
|
|
|
|
|
|
|
def test_3(self):
|
|
|
|
b = """(a + b).next()"""
|
|
|
|
a = """next((a + b))"""
|
|
|
|
self.check(b, a)
|
|
|
|
|
|
|
|
def test_4(self):
|
|
|
|
b = """a().next()"""
|
|
|
|
a = """next(a())"""
|
|
|
|
self.check(b, a)
|
|
|
|
|
|
|
|
def test_5(self):
|
|
|
|
b = """a().next() + b"""
|
|
|
|
a = """next(a()) + b"""
|
|
|
|
self.check(b, a)
|
|
|
|
|
|
|
|
def test_6(self):
|
|
|
|
b = """c( a().next() + b)"""
|
|
|
|
a = """c( next(a()) + b)"""
|
|
|
|
self.check(b, a)
|
|
|
|
|
|
|
|
def test_prefix_preservation_1(self):
|
|
|
|
b = """
|
|
|
|
for a in b:
|
|
|
|
foo(a)
|
|
|
|
a.next()
|
|
|
|
"""
|
|
|
|
a = """
|
|
|
|
for a in b:
|
|
|
|
foo(a)
|
|
|
|
next(a)
|
|
|
|
"""
|
|
|
|
self.check(b, a)
|
|
|
|
|
|
|
|
def test_prefix_preservation_2(self):
|
|
|
|
b = """
|
|
|
|
for a in b:
|
|
|
|
foo(a) # abc
|
|
|
|
# def
|
|
|
|
a.next()
|
|
|
|
"""
|
|
|
|
a = """
|
|
|
|
for a in b:
|
|
|
|
foo(a) # abc
|
|
|
|
# def
|
|
|
|
next(a)
|
|
|
|
"""
|
|
|
|
self.check(b, a)
|
|
|
|
|
|
|
|
def test_prefix_preservation_3(self):
|
|
|
|
b = """
|
|
|
|
next = 5
|
|
|
|
for a in b:
|
|
|
|
foo(a)
|
|
|
|
a.next()
|
|
|
|
"""
|
|
|
|
a = """
|
|
|
|
next = 5
|
|
|
|
for a in b:
|
|
|
|
foo(a)
|
|
|
|
a.__next__()
|
|
|
|
"""
|
|
|
|
self.check(b, a, ignore_warnings=True)
|
|
|
|
|
|
|
|
def test_prefix_preservation_4(self):
|
|
|
|
b = """
|
|
|
|
next = 5
|
|
|
|
for a in b:
|
|
|
|
foo(a) # abc
|
|
|
|
# def
|
|
|
|
a.next()
|
|
|
|
"""
|
|
|
|
a = """
|
|
|
|
next = 5
|
|
|
|
for a in b:
|
|
|
|
foo(a) # abc
|
|
|
|
# def
|
|
|
|
a.__next__()
|
|
|
|
"""
|
|
|
|
self.check(b, a, ignore_warnings=True)
|
|
|
|
|
|
|
|
def test_prefix_preservation_5(self):
|
|
|
|
b = """
|
|
|
|
next = 5
|
|
|
|
for a in b:
|
|
|
|
foo(foo(a), # abc
|
|
|
|
a.next())
|
|
|
|
"""
|
|
|
|
a = """
|
|
|
|
next = 5
|
|
|
|
for a in b:
|
|
|
|
foo(foo(a), # abc
|
|
|
|
a.__next__())
|
|
|
|
"""
|
|
|
|
self.check(b, a, ignore_warnings=True)
|
|
|
|
|
|
|
|
def test_prefix_preservation_6(self):
|
|
|
|
b = """
|
|
|
|
for a in b:
|
|
|
|
foo(foo(a), # abc
|
|
|
|
a.next())
|
|
|
|
"""
|
|
|
|
a = """
|
|
|
|
for a in b:
|
|
|
|
foo(foo(a), # abc
|
|
|
|
next(a))
|
|
|
|
"""
|
|
|
|
self.check(b, a)
|
|
|
|
|
|
|
|
def test_method_1(self):
|
|
|
|
b = """
|
|
|
|
class A:
|
|
|
|
def next(self):
|
|
|
|
pass
|
|
|
|
"""
|
|
|
|
a = """
|
|
|
|
class A:
|
|
|
|
def __next__(self):
|
|
|
|
pass
|
|
|
|
"""
|
|
|
|
self.check(b, a)
|
|
|
|
|
|
|
|
def test_method_2(self):
|
|
|
|
b = """
|
|
|
|
class A(object):
|
|
|
|
def next(self):
|
|
|
|
pass
|
|
|
|
"""
|
|
|
|
a = """
|
|
|
|
class A(object):
|
|
|
|
def __next__(self):
|
|
|
|
pass
|
|
|
|
"""
|
|
|
|
self.check(b, a)
|
|
|
|
|
|
|
|
def test_method_3(self):
|
|
|
|
b = """
|
|
|
|
class A:
|
|
|
|
def next(x):
|
|
|
|
pass
|
|
|
|
"""
|
|
|
|
a = """
|
|
|
|
class A:
|
|
|
|
def __next__(x):
|
|
|
|
pass
|
|
|
|
"""
|
|
|
|
self.check(b, a)
|
|
|
|
|
|
|
|
def test_method_4(self):
|
|
|
|
b = """
|
|
|
|
class A:
|
|
|
|
def __init__(self, foo):
|
|
|
|
self.foo = foo
|
|
|
|
|
|
|
|
def next(self):
|
|
|
|
pass
|
|
|
|
|
|
|
|
def __iter__(self):
|
|
|
|
return self
|
|
|
|
"""
|
|
|
|
a = """
|
|
|
|
class A:
|
|
|
|
def __init__(self, foo):
|
|
|
|
self.foo = foo
|
|
|
|
|
|
|
|
def __next__(self):
|
|
|
|
pass
|
|
|
|
|
|
|
|
def __iter__(self):
|
|
|
|
return self
|
|
|
|
"""
|
|
|
|
self.check(b, a)
|
|
|
|
|
|
|
|
def test_method_unchanged(self):
|
|
|
|
s = """
|
|
|
|
class A:
|
|
|
|
def next(self, a, b):
|
|
|
|
pass
|
|
|
|
"""
|
|
|
|
self.unchanged(s)
|
|
|
|
|
|
|
|
def test_shadowing_assign_simple(self):
|
|
|
|
s = """
|
|
|
|
next = foo
|
|
|
|
|
|
|
|
class A:
|
|
|
|
def next(self, a, b):
|
|
|
|
pass
|
|
|
|
"""
|
|
|
|
self.warns_unchanged(s, "Calls to builtin next() possibly shadowed")
|
|
|
|
|
|
|
|
def test_shadowing_assign_tuple_1(self):
|
|
|
|
s = """
|
|
|
|
(next, a) = foo
|
|
|
|
|
|
|
|
class A:
|
|
|
|
def next(self, a, b):
|
|
|
|
pass
|
|
|
|
"""
|
|
|
|
self.warns_unchanged(s, "Calls to builtin next() possibly shadowed")
|
|
|
|
|
|
|
|
def test_shadowing_assign_tuple_2(self):
|
|
|
|
s = """
|
|
|
|
(a, (b, (next, c)), a) = foo
|
|
|
|
|
|
|
|
class A:
|
|
|
|
def next(self, a, b):
|
|
|
|
pass
|
|
|
|
"""
|
|
|
|
self.warns_unchanged(s, "Calls to builtin next() possibly shadowed")
|
|
|
|
|
|
|
|
def test_shadowing_assign_list_1(self):
|
|
|
|
s = """
|
|
|
|
[next, a] = foo
|
|
|
|
|
|
|
|
class A:
|
|
|
|
def next(self, a, b):
|
|
|
|
pass
|
|
|
|
"""
|
|
|
|
self.warns_unchanged(s, "Calls to builtin next() possibly shadowed")
|
|
|
|
|
|
|
|
def test_shadowing_assign_list_2(self):
|
|
|
|
s = """
|
|
|
|
[a, [b, [next, c]], a] = foo
|
|
|
|
|
|
|
|
class A:
|
|
|
|
def next(self, a, b):
|
|
|
|
pass
|
|
|
|
"""
|
|
|
|
self.warns_unchanged(s, "Calls to builtin next() possibly shadowed")
|
|
|
|
|
|
|
|
def test_builtin_assign(self):
|
|
|
|
s = """
|
|
|
|
def foo():
|
|
|
|
__builtin__.next = foo
|
|
|
|
|
|
|
|
class A:
|
|
|
|
def next(self, a, b):
|
|
|
|
pass
|
|
|
|
"""
|
|
|
|
self.warns_unchanged(s, "Calls to builtin next() possibly shadowed")
|
|
|
|
|
|
|
|
def test_builtin_assign_in_tuple(self):
|
|
|
|
s = """
|
|
|
|
def foo():
|
|
|
|
(a, __builtin__.next) = foo
|
|
|
|
|
|
|
|
class A:
|
|
|
|
def next(self, a, b):
|
|
|
|
pass
|
|
|
|
"""
|
|
|
|
self.warns_unchanged(s, "Calls to builtin next() possibly shadowed")
|
|
|
|
|
|
|
|
def test_builtin_assign_in_list(self):
|
|
|
|
s = """
|
|
|
|
def foo():
|
|
|
|
[a, __builtin__.next] = foo
|
|
|
|
|
|
|
|
class A:
|
|
|
|
def next(self, a, b):
|
|
|
|
pass
|
|
|
|
"""
|
|
|
|
self.warns_unchanged(s, "Calls to builtin next() possibly shadowed")
|
|
|
|
|
|
|
|
def test_assign_to_next(self):
|
|
|
|
s = """
|
|
|
|
def foo():
|
|
|
|
A.next = foo
|
|
|
|
|
|
|
|
class A:
|
|
|
|
def next(self, a, b):
|
|
|
|
pass
|
|
|
|
"""
|
|
|
|
self.unchanged(s)
|
|
|
|
|
|
|
|
def test_assign_to_next_in_tuple(self):
|
|
|
|
s = """
|
|
|
|
def foo():
|
|
|
|
(a, A.next) = foo
|
|
|
|
|
|
|
|
class A:
|
|
|
|
def next(self, a, b):
|
|
|
|
pass
|
|
|
|
"""
|
|
|
|
self.unchanged(s)
|
|
|
|
|
|
|
|
def test_assign_to_next_in_list(self):
|
|
|
|
s = """
|
|
|
|
def foo():
|
|
|
|
[a, A.next] = foo
|
|
|
|
|
|
|
|
class A:
|
|
|
|
def next(self, a, b):
|
|
|
|
pass
|
|
|
|
"""
|
|
|
|
self.unchanged(s)
|
|
|
|
|
|
|
|
def test_shadowing_import_1(self):
|
|
|
|
s = """
|
|
|
|
import foo.bar as next
|
|
|
|
|
|
|
|
class A:
|
|
|
|
def next(self, a, b):
|
|
|
|
pass
|
|
|
|
"""
|
|
|
|
self.warns_unchanged(s, "Calls to builtin next() possibly shadowed")
|
|
|
|
|
|
|
|
def test_shadowing_import_2(self):
|
|
|
|
s = """
|
|
|
|
import bar, bar.foo as next
|
|
|
|
|
|
|
|
class A:
|
|
|
|
def next(self, a, b):
|
|
|
|
pass
|
|
|
|
"""
|
|
|
|
self.warns_unchanged(s, "Calls to builtin next() possibly shadowed")
|
|
|
|
|
|
|
|
def test_shadowing_import_3(self):
|
|
|
|
s = """
|
|
|
|
import bar, bar.foo as next, baz
|
|
|
|
|
|
|
|
class A:
|
|
|
|
def next(self, a, b):
|
|
|
|
pass
|
|
|
|
"""
|
|
|
|
self.warns_unchanged(s, "Calls to builtin next() possibly shadowed")
|
|
|
|
|
|
|
|
def test_shadowing_import_from_1(self):
|
|
|
|
s = """
|
|
|
|
from x import next
|
|
|
|
|
|
|
|
class A:
|
|
|
|
def next(self, a, b):
|
|
|
|
pass
|
|
|
|
"""
|
|
|
|
self.warns_unchanged(s, "Calls to builtin next() possibly shadowed")
|
|
|
|
|
|
|
|
def test_shadowing_import_from_2(self):
|
|
|
|
s = """
|
|
|
|
from x.a import next
|
|
|
|
|
|
|
|
class A:
|
|
|
|
def next(self, a, b):
|
|
|
|
pass
|
|
|
|
"""
|
|
|
|
self.warns_unchanged(s, "Calls to builtin next() possibly shadowed")
|
|
|
|
|
|
|
|
def test_shadowing_import_from_3(self):
|
|
|
|
s = """
|
|
|
|
from x import a, next, b
|
|
|
|
|
|
|
|
class A:
|
|
|
|
def next(self, a, b):
|
|
|
|
pass
|
|
|
|
"""
|
|
|
|
self.warns_unchanged(s, "Calls to builtin next() possibly shadowed")
|
|
|
|
|
|
|
|
def test_shadowing_import_from_4(self):
|
|
|
|
s = """
|
|
|
|
from x.a import a, next, b
|
|
|
|
|
|
|
|
class A:
|
|
|
|
def next(self, a, b):
|
|
|
|
pass
|
|
|
|
"""
|
|
|
|
self.warns_unchanged(s, "Calls to builtin next() possibly shadowed")
|
|
|
|
|
|
|
|
def test_shadowing_funcdef_1(self):
|
|
|
|
s = """
|
|
|
|
def next(a):
|
|
|
|
pass
|
|
|
|
|
|
|
|
class A:
|
|
|
|
def next(self, a, b):
|
|
|
|
pass
|
|
|
|
"""
|
|
|
|
self.warns_unchanged(s, "Calls to builtin next() possibly shadowed")
|
|
|
|
|
|
|
|
def test_shadowing_funcdef_2(self):
|
|
|
|
b = """
|
|
|
|
def next(a):
|
|
|
|
pass
|
|
|
|
|
|
|
|
class A:
|
|
|
|
def next(self):
|
|
|
|
pass
|
|
|
|
|
|
|
|
it.next()
|
|
|
|
"""
|
|
|
|
a = """
|
|
|
|
def next(a):
|
|
|
|
pass
|
|
|
|
|
|
|
|
class A:
|
|
|
|
def __next__(self):
|
|
|
|
pass
|
|
|
|
|
|
|
|
it.__next__()
|
|
|
|
"""
|
|
|
|
self.warns(b, a, "Calls to builtin next() possibly shadowed")
|
|
|
|
|
|
|
|
def test_shadowing_global_1(self):
|
|
|
|
s = """
|
|
|
|
def f():
|
|
|
|
global next
|
|
|
|
next = 5
|
|
|
|
"""
|
|
|
|
self.warns_unchanged(s, "Calls to builtin next() possibly shadowed")
|
|
|
|
|
|
|
|
def test_shadowing_global_2(self):
|
|
|
|
s = """
|
|
|
|
def f():
|
|
|
|
global a, next, b
|
|
|
|
next = 5
|
|
|
|
"""
|
|
|
|
self.warns_unchanged(s, "Calls to builtin next() possibly shadowed")
|
|
|
|
|
|
|
|
def test_shadowing_for_simple(self):
|
|
|
|
s = """
|
|
|
|
for next in it():
|
|
|
|
pass
|
|
|
|
|
|
|
|
b = 5
|
|
|
|
c = 6
|
|
|
|
"""
|
|
|
|
self.warns_unchanged(s, "Calls to builtin next() possibly shadowed")
|
|
|
|
|
|
|
|
def test_shadowing_for_tuple_1(self):
|
|
|
|
s = """
|
|
|
|
for next, b in it():
|
|
|
|
pass
|
|
|
|
|
|
|
|
b = 5
|
|
|
|
c = 6
|
|
|
|
"""
|
|
|
|
self.warns_unchanged(s, "Calls to builtin next() possibly shadowed")
|
|
|
|
|
|
|
|
def test_shadowing_for_tuple_2(self):
|
|
|
|
s = """
|
|
|
|
for a, (next, c), b in it():
|
|
|
|
pass
|
|
|
|
|
|
|
|
b = 5
|
|
|
|
c = 6
|
|
|
|
"""
|
|
|
|
self.warns_unchanged(s, "Calls to builtin next() possibly shadowed")
|
|
|
|
|
|
|
|
def test_noncall_access_1(self):
|
|
|
|
b = """gnext = g.next"""
|
|
|
|
a = """gnext = g.__next__"""
|
|
|
|
self.check(b, a)
|
|
|
|
|
|
|
|
def test_noncall_access_2(self):
|
|
|
|
b = """f(g.next + 5)"""
|
|
|
|
a = """f(g.__next__ + 5)"""
|
|
|
|
self.check(b, a)
|
|
|
|
|
|
|
|
def test_noncall_access_3(self):
|
|
|
|
b = """f(g().next + 5)"""
|
|
|
|
a = """f(g().__next__ + 5)"""
|
|
|
|
self.check(b, a)
|
|
|
|
|
|
|
|
class Test_nonzero(FixerTestCase):
|
|
|
|
fixer = "nonzero"
|
|
|
|
|
|
|
|
def test_1(self):
|
|
|
|
b = """
|
|
|
|
class A:
|
|
|
|
def __nonzero__(self):
|
|
|
|
pass
|
|
|
|
"""
|
|
|
|
a = """
|
|
|
|
class A:
|
|
|
|
def __bool__(self):
|
|
|
|
pass
|
|
|
|
"""
|
|
|
|
self.check(b, a)
|
|
|
|
|
|
|
|
def test_2(self):
|
|
|
|
b = """
|
|
|
|
class A(object):
|
|
|
|
def __nonzero__(self):
|
|
|
|
pass
|
|
|
|
"""
|
|
|
|
a = """
|
|
|
|
class A(object):
|
|
|
|
def __bool__(self):
|
|
|
|
pass
|
|
|
|
"""
|
|
|
|
self.check(b, a)
|
|
|
|
|
|
|
|
def test_unchanged_1(self):
|
|
|
|
s = """
|
|
|
|
class A(object):
|
|
|
|
def __bool__(self):
|
|
|
|
pass
|
|
|
|
"""
|
|
|
|
self.unchanged(s)
|
|
|
|
|
|
|
|
def test_unchanged_2(self):
|
|
|
|
s = """
|
|
|
|
class A(object):
|
|
|
|
def __nonzero__(self, a):
|
|
|
|
pass
|
|
|
|
"""
|
|
|
|
self.unchanged(s)
|
|
|
|
|
|
|
|
def test_unchanged_func(self):
|
|
|
|
s = """
|
|
|
|
def __nonzero__(self):
|
|
|
|
pass
|
|
|
|
"""
|
|
|
|
self.unchanged(s)
|
|
|
|
|
|
|
|
class Test_numliterals(FixerTestCase):
|
|
|
|
fixer = "numliterals"
|
|
|
|
|
|
|
|
def test_octal_1(self):
|
|
|
|
b = """0755"""
|
|
|
|
a = """0o755"""
|
|
|
|
self.check(b, a)
|
|
|
|
|
|
|
|
def test_long_int_1(self):
|
|
|
|
b = """a = 12L"""
|
|
|
|
a = """a = 12"""
|
|
|
|
self.check(b, a)
|
|
|
|
|
|
|
|
def test_long_int_2(self):
|
|
|
|
b = """a = 12l"""
|
|
|
|
a = """a = 12"""
|
|
|
|
self.check(b, a)
|
|
|
|
|
|
|
|
def test_long_hex(self):
|
|
|
|
b = """b = 0x12l"""
|
|
|
|
a = """b = 0x12"""
|
|
|
|
self.check(b, a)
|
|
|
|
|
2008-09-13 15:37:09 -03:00
|
|
|
def test_comments_and_spacing(self):
|
|
|
|
b = """b = 0x12L"""
|
|
|
|
a = """b = 0x12"""
|
|
|
|
self.check(b, a)
|
|
|
|
|
|
|
|
b = """b = 0755 # spam"""
|
|
|
|
a = """b = 0o755 # spam"""
|
|
|
|
self.check(b, a)
|
|
|
|
|
2008-03-19 02:04:44 -03:00
|
|
|
def test_unchanged_int(self):
|
|
|
|
s = """5"""
|
|
|
|
self.unchanged(s)
|
|
|
|
|
|
|
|
def test_unchanged_float(self):
|
|
|
|
s = """5.0"""
|
|
|
|
self.unchanged(s)
|
|
|
|
|
|
|
|
def test_unchanged_octal(self):
|
|
|
|
s = """0o755"""
|
|
|
|
self.unchanged(s)
|
|
|
|
|
|
|
|
def test_unchanged_hex(self):
|
|
|
|
s = """0xABC"""
|
|
|
|
self.unchanged(s)
|
|
|
|
|
|
|
|
def test_unchanged_exp(self):
|
|
|
|
s = """5.0e10"""
|
|
|
|
self.unchanged(s)
|
|
|
|
|
|
|
|
def test_unchanged_complex_int(self):
|
|
|
|
s = """5 + 4j"""
|
|
|
|
self.unchanged(s)
|
|
|
|
|
|
|
|
def test_unchanged_complex_float(self):
|
|
|
|
s = """5.4 + 4.9j"""
|
|
|
|
self.unchanged(s)
|
|
|
|
|
|
|
|
def test_unchanged_complex_bare(self):
|
|
|
|
s = """4j"""
|
|
|
|
self.unchanged(s)
|
|
|
|
s = """4.4j"""
|
|
|
|
self.unchanged(s)
|
|
|
|
|
|
|
|
class Test_renames(FixerTestCase):
|
|
|
|
fixer = "renames"
|
|
|
|
|
|
|
|
modules = {"sys": ("maxint", "maxsize"),
|
|
|
|
}
|
|
|
|
|
|
|
|
def test_import_from(self):
|
2008-03-19 02:33:36 -03:00
|
|
|
for mod, (old, new) in list(self.modules.items()):
|
2008-03-19 02:04:44 -03:00
|
|
|
b = "from %s import %s" % (mod, old)
|
|
|
|
a = "from %s import %s" % (mod, new)
|
|
|
|
self.check(b, a)
|
|
|
|
|
|
|
|
s = "from foo import %s" % old
|
|
|
|
self.unchanged(s)
|
|
|
|
|
|
|
|
def test_import_from_as(self):
|
2008-03-19 02:33:36 -03:00
|
|
|
for mod, (old, new) in list(self.modules.items()):
|
2008-03-19 02:04:44 -03:00
|
|
|
b = "from %s import %s as foo_bar" % (mod, old)
|
|
|
|
a = "from %s import %s as foo_bar" % (mod, new)
|
|
|
|
self.check(b, a)
|
|
|
|
|
|
|
|
def test_import_module_usage(self):
|
2008-03-19 02:33:36 -03:00
|
|
|
for mod, (old, new) in list(self.modules.items()):
|
2008-03-19 02:04:44 -03:00
|
|
|
b = """
|
|
|
|
import %s
|
|
|
|
foo(%s, %s.%s)
|
|
|
|
""" % (mod, mod, mod, old)
|
|
|
|
a = """
|
|
|
|
import %s
|
|
|
|
foo(%s, %s.%s)
|
|
|
|
""" % (mod, mod, mod, new)
|
|
|
|
self.check(b, a)
|
|
|
|
|
|
|
|
def XXX_test_from_import_usage(self):
|
|
|
|
# not implemented yet
|
2008-03-19 02:33:36 -03:00
|
|
|
for mod, (old, new) in list(self.modules.items()):
|
2008-03-19 02:04:44 -03:00
|
|
|
b = """
|
|
|
|
from %s import %s
|
|
|
|
foo(%s, %s)
|
|
|
|
""" % (mod, old, mod, old)
|
|
|
|
a = """
|
|
|
|
from %s import %s
|
|
|
|
foo(%s, %s)
|
|
|
|
""" % (mod, new, mod, new)
|
|
|
|
self.check(b, a)
|
|
|
|
|
|
|
|
class Test_unicode(FixerTestCase):
|
|
|
|
fixer = "unicode"
|
|
|
|
|
Merged revisions 73370 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk
................
r73370 | benjamin.peterson | 2009-06-11 17:06:46 -0500 (Thu, 11 Jun 2009) | 105 lines
Merged revisions 72523,72950-72951,72994,73003,73033,73036-73040,73091-73093,73096,73179-73181,73192,73231,73244,73255-73256,73365 via svnmerge from
svn+ssh://pythondev@svn.python.org/sandbox/trunk/2to3/lib2to3
........
r72523 | benjamin.peterson | 2009-05-09 14:42:26 -0500 (Sat, 09 May 2009) | 1 line
remove parenthesis
........
r72950 | benjamin.peterson | 2009-05-26 18:19:45 -0500 (Tue, 26 May 2009) | 1 line
remove unused imports
........
r72951 | benjamin.peterson | 2009-05-26 18:27:00 -0500 (Tue, 26 May 2009) | 1 line
this is no longer executable
........
r72994 | benjamin.peterson | 2009-05-28 15:32:54 -0500 (Thu, 28 May 2009) | 1 line
fix test_all_fixers on Windows #6134
........
r73003 | benjamin.peterson | 2009-05-28 21:57:28 -0500 (Thu, 28 May 2009) | 4 lines
make 2to3 test utilities easier to use with other applications (3to2)
Patch by Joe Amenta
........
r73033 | benjamin.peterson | 2009-05-29 16:58:32 -0500 (Fri, 29 May 2009) | 1 line
update grammar for multi with statement
........
r73036 | benjamin.peterson | 2009-05-29 17:33:20 -0500 (Fri, 29 May 2009) | 1 line
simplify fix_unicode
........
r73037 | benjamin.peterson | 2009-05-29 17:53:03 -0500 (Fri, 29 May 2009) | 1 line
add custom error for pattern syntax errors
........
r73038 | benjamin.peterson | 2009-05-29 17:55:00 -0500 (Fri, 29 May 2009) | 1 line
complain if details are attached to a token
........
r73039 | benjamin.peterson | 2009-05-29 18:00:28 -0500 (Fri, 29 May 2009) | 1 line
add a test for whitespace
........
r73040 | benjamin.peterson | 2009-05-29 18:01:17 -0500 (Fri, 29 May 2009) | 1 line
a fix for emacs highlighting
........
r73091 | benjamin.peterson | 2009-05-31 20:55:25 -0500 (Sun, 31 May 2009) | 1 line
deprecate set_prefix() and get_prefix() in favor of a prefix property
........
r73092 | benjamin.peterson | 2009-05-31 21:00:51 -0500 (Sun, 31 May 2009) | 1 line
change hideous java naming scheme
........
r73093 | benjamin.peterson | 2009-05-31 21:01:39 -0500 (Sun, 31 May 2009) | 1 line
remove dated comment
........
r73096 | benjamin.peterson | 2009-05-31 21:40:53 -0500 (Sun, 31 May 2009) | 1 line
group tests
........
r73179 | benjamin.peterson | 2009-06-03 13:09:53 -0500 (Wed, 03 Jun 2009) | 1 line
handle the case where there's multiple trailers #6185
........
r73180 | benjamin.peterson | 2009-06-03 13:18:05 -0500 (Wed, 03 Jun 2009) | 1 line
scrap __main__ section
........
r73181 | benjamin.peterson | 2009-06-03 13:24:48 -0500 (Wed, 03 Jun 2009) | 1 line
remove shebang lines and __main__ sections
........
r73192 | benjamin.peterson | 2009-06-03 19:16:30 -0500 (Wed, 03 Jun 2009) | 4 lines
actually test something here
Thanks to Joe Amenta for noticing.y
........
r73231 | benjamin.peterson | 2009-06-04 13:38:50 -0500 (Thu, 04 Jun 2009) | 1 line
remove unused variable
........
r73244 | benjamin.peterson | 2009-06-05 08:39:25 -0500 (Fri, 05 Jun 2009) | 1 line
allow fixers to give different options in setUp
........
r73255 | benjamin.peterson | 2009-06-06 11:23:46 -0500 (Sat, 06 Jun 2009) | 1 line
fix the except fixer on one line suites #6222
........
r73256 | benjamin.peterson | 2009-06-06 11:27:40 -0500 (Sat, 06 Jun 2009) | 1 line
test one-line else and finally clauses
........
r73365 | benjamin.peterson | 2009-06-11 17:01:32 -0500 (Thu, 11 Jun 2009) | 1 line
normalize whitespace
........
................
2009-06-11 20:47:38 -03:00
|
|
|
def test_whitespace(self):
|
|
|
|
b = """unicode( x)"""
|
|
|
|
a = """str( x)"""
|
|
|
|
self.check(b, a)
|
|
|
|
|
|
|
|
b = """ unicode(x )"""
|
|
|
|
a = """ str(x )"""
|
|
|
|
self.check(b, a)
|
|
|
|
|
|
|
|
b = """ u'h'"""
|
|
|
|
a = """ 'h'"""
|
|
|
|
self.check(b, a)
|
|
|
|
|
2008-03-19 02:04:44 -03:00
|
|
|
def test_unicode_call(self):
|
|
|
|
b = """unicode(x, y, z)"""
|
|
|
|
a = """str(x, y, z)"""
|
|
|
|
self.check(b, a)
|
|
|
|
|
Merged revisions 73370 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk
................
r73370 | benjamin.peterson | 2009-06-11 17:06:46 -0500 (Thu, 11 Jun 2009) | 105 lines
Merged revisions 72523,72950-72951,72994,73003,73033,73036-73040,73091-73093,73096,73179-73181,73192,73231,73244,73255-73256,73365 via svnmerge from
svn+ssh://pythondev@svn.python.org/sandbox/trunk/2to3/lib2to3
........
r72523 | benjamin.peterson | 2009-05-09 14:42:26 -0500 (Sat, 09 May 2009) | 1 line
remove parenthesis
........
r72950 | benjamin.peterson | 2009-05-26 18:19:45 -0500 (Tue, 26 May 2009) | 1 line
remove unused imports
........
r72951 | benjamin.peterson | 2009-05-26 18:27:00 -0500 (Tue, 26 May 2009) | 1 line
this is no longer executable
........
r72994 | benjamin.peterson | 2009-05-28 15:32:54 -0500 (Thu, 28 May 2009) | 1 line
fix test_all_fixers on Windows #6134
........
r73003 | benjamin.peterson | 2009-05-28 21:57:28 -0500 (Thu, 28 May 2009) | 4 lines
make 2to3 test utilities easier to use with other applications (3to2)
Patch by Joe Amenta
........
r73033 | benjamin.peterson | 2009-05-29 16:58:32 -0500 (Fri, 29 May 2009) | 1 line
update grammar for multi with statement
........
r73036 | benjamin.peterson | 2009-05-29 17:33:20 -0500 (Fri, 29 May 2009) | 1 line
simplify fix_unicode
........
r73037 | benjamin.peterson | 2009-05-29 17:53:03 -0500 (Fri, 29 May 2009) | 1 line
add custom error for pattern syntax errors
........
r73038 | benjamin.peterson | 2009-05-29 17:55:00 -0500 (Fri, 29 May 2009) | 1 line
complain if details are attached to a token
........
r73039 | benjamin.peterson | 2009-05-29 18:00:28 -0500 (Fri, 29 May 2009) | 1 line
add a test for whitespace
........
r73040 | benjamin.peterson | 2009-05-29 18:01:17 -0500 (Fri, 29 May 2009) | 1 line
a fix for emacs highlighting
........
r73091 | benjamin.peterson | 2009-05-31 20:55:25 -0500 (Sun, 31 May 2009) | 1 line
deprecate set_prefix() and get_prefix() in favor of a prefix property
........
r73092 | benjamin.peterson | 2009-05-31 21:00:51 -0500 (Sun, 31 May 2009) | 1 line
change hideous java naming scheme
........
r73093 | benjamin.peterson | 2009-05-31 21:01:39 -0500 (Sun, 31 May 2009) | 1 line
remove dated comment
........
r73096 | benjamin.peterson | 2009-05-31 21:40:53 -0500 (Sun, 31 May 2009) | 1 line
group tests
........
r73179 | benjamin.peterson | 2009-06-03 13:09:53 -0500 (Wed, 03 Jun 2009) | 1 line
handle the case where there's multiple trailers #6185
........
r73180 | benjamin.peterson | 2009-06-03 13:18:05 -0500 (Wed, 03 Jun 2009) | 1 line
scrap __main__ section
........
r73181 | benjamin.peterson | 2009-06-03 13:24:48 -0500 (Wed, 03 Jun 2009) | 1 line
remove shebang lines and __main__ sections
........
r73192 | benjamin.peterson | 2009-06-03 19:16:30 -0500 (Wed, 03 Jun 2009) | 4 lines
actually test something here
Thanks to Joe Amenta for noticing.y
........
r73231 | benjamin.peterson | 2009-06-04 13:38:50 -0500 (Thu, 04 Jun 2009) | 1 line
remove unused variable
........
r73244 | benjamin.peterson | 2009-06-05 08:39:25 -0500 (Fri, 05 Jun 2009) | 1 line
allow fixers to give different options in setUp
........
r73255 | benjamin.peterson | 2009-06-06 11:23:46 -0500 (Sat, 06 Jun 2009) | 1 line
fix the except fixer on one line suites #6222
........
r73256 | benjamin.peterson | 2009-06-06 11:27:40 -0500 (Sat, 06 Jun 2009) | 1 line
test one-line else and finally clauses
........
r73365 | benjamin.peterson | 2009-06-11 17:01:32 -0500 (Thu, 11 Jun 2009) | 1 line
normalize whitespace
........
................
2009-06-11 20:47:38 -03:00
|
|
|
def test_unichr(self):
|
|
|
|
b = """unichr(u'h')"""
|
|
|
|
a = """chr('h')"""
|
|
|
|
self.check(b, a)
|
|
|
|
|
2008-03-19 02:04:44 -03:00
|
|
|
def test_unicode_literal_1(self):
|
|
|
|
b = '''u"x"'''
|
|
|
|
a = '''"x"'''
|
|
|
|
self.check(b, a)
|
|
|
|
|
|
|
|
def test_unicode_literal_2(self):
|
|
|
|
b = """ur'x'"""
|
|
|
|
a = """r'x'"""
|
|
|
|
self.check(b, a)
|
|
|
|
|
|
|
|
def test_unicode_literal_3(self):
|
Merged revisions 73370 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk
................
r73370 | benjamin.peterson | 2009-06-11 17:06:46 -0500 (Thu, 11 Jun 2009) | 105 lines
Merged revisions 72523,72950-72951,72994,73003,73033,73036-73040,73091-73093,73096,73179-73181,73192,73231,73244,73255-73256,73365 via svnmerge from
svn+ssh://pythondev@svn.python.org/sandbox/trunk/2to3/lib2to3
........
r72523 | benjamin.peterson | 2009-05-09 14:42:26 -0500 (Sat, 09 May 2009) | 1 line
remove parenthesis
........
r72950 | benjamin.peterson | 2009-05-26 18:19:45 -0500 (Tue, 26 May 2009) | 1 line
remove unused imports
........
r72951 | benjamin.peterson | 2009-05-26 18:27:00 -0500 (Tue, 26 May 2009) | 1 line
this is no longer executable
........
r72994 | benjamin.peterson | 2009-05-28 15:32:54 -0500 (Thu, 28 May 2009) | 1 line
fix test_all_fixers on Windows #6134
........
r73003 | benjamin.peterson | 2009-05-28 21:57:28 -0500 (Thu, 28 May 2009) | 4 lines
make 2to3 test utilities easier to use with other applications (3to2)
Patch by Joe Amenta
........
r73033 | benjamin.peterson | 2009-05-29 16:58:32 -0500 (Fri, 29 May 2009) | 1 line
update grammar for multi with statement
........
r73036 | benjamin.peterson | 2009-05-29 17:33:20 -0500 (Fri, 29 May 2009) | 1 line
simplify fix_unicode
........
r73037 | benjamin.peterson | 2009-05-29 17:53:03 -0500 (Fri, 29 May 2009) | 1 line
add custom error for pattern syntax errors
........
r73038 | benjamin.peterson | 2009-05-29 17:55:00 -0500 (Fri, 29 May 2009) | 1 line
complain if details are attached to a token
........
r73039 | benjamin.peterson | 2009-05-29 18:00:28 -0500 (Fri, 29 May 2009) | 1 line
add a test for whitespace
........
r73040 | benjamin.peterson | 2009-05-29 18:01:17 -0500 (Fri, 29 May 2009) | 1 line
a fix for emacs highlighting
........
r73091 | benjamin.peterson | 2009-05-31 20:55:25 -0500 (Sun, 31 May 2009) | 1 line
deprecate set_prefix() and get_prefix() in favor of a prefix property
........
r73092 | benjamin.peterson | 2009-05-31 21:00:51 -0500 (Sun, 31 May 2009) | 1 line
change hideous java naming scheme
........
r73093 | benjamin.peterson | 2009-05-31 21:01:39 -0500 (Sun, 31 May 2009) | 1 line
remove dated comment
........
r73096 | benjamin.peterson | 2009-05-31 21:40:53 -0500 (Sun, 31 May 2009) | 1 line
group tests
........
r73179 | benjamin.peterson | 2009-06-03 13:09:53 -0500 (Wed, 03 Jun 2009) | 1 line
handle the case where there's multiple trailers #6185
........
r73180 | benjamin.peterson | 2009-06-03 13:18:05 -0500 (Wed, 03 Jun 2009) | 1 line
scrap __main__ section
........
r73181 | benjamin.peterson | 2009-06-03 13:24:48 -0500 (Wed, 03 Jun 2009) | 1 line
remove shebang lines and __main__ sections
........
r73192 | benjamin.peterson | 2009-06-03 19:16:30 -0500 (Wed, 03 Jun 2009) | 4 lines
actually test something here
Thanks to Joe Amenta for noticing.y
........
r73231 | benjamin.peterson | 2009-06-04 13:38:50 -0500 (Thu, 04 Jun 2009) | 1 line
remove unused variable
........
r73244 | benjamin.peterson | 2009-06-05 08:39:25 -0500 (Fri, 05 Jun 2009) | 1 line
allow fixers to give different options in setUp
........
r73255 | benjamin.peterson | 2009-06-06 11:23:46 -0500 (Sat, 06 Jun 2009) | 1 line
fix the except fixer on one line suites #6222
........
r73256 | benjamin.peterson | 2009-06-06 11:27:40 -0500 (Sat, 06 Jun 2009) | 1 line
test one-line else and finally clauses
........
r73365 | benjamin.peterson | 2009-06-11 17:01:32 -0500 (Thu, 11 Jun 2009) | 1 line
normalize whitespace
........
................
2009-06-11 20:47:38 -03:00
|
|
|
b = """UR'''x''' """
|
|
|
|
a = """R'''x''' """
|
2008-03-19 02:04:44 -03:00
|
|
|
self.check(b, a)
|
|
|
|
|
|
|
|
class Test_callable(FixerTestCase):
|
|
|
|
fixer = "callable"
|
|
|
|
|
|
|
|
def test_prefix_preservation(self):
|
|
|
|
b = """callable( x)"""
|
Merged revisions 77103,77105-77106 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/branches/py3k
................
r77103 | benjamin.peterson | 2009-12-28 18:06:20 -0600 (Mon, 28 Dec 2009) | 57 lines
Merged revisions 77102 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk
................
r77102 | benjamin.peterson | 2009-12-28 17:50:41 -0600 (Mon, 28 Dec 2009) | 50 lines
Merged revisions 76871-76872,77093-77095,77097-77101 via svnmerge from
svn+ssh://pythondev@svn.python.org/sandbox/trunk/2to3/lib2to3
........
r76871 | benjamin.peterson | 2009-12-17 20:49:21 -0600 (Thu, 17 Dec 2009) | 1 line
handle unencodable diffs gracefully #5093
........
r76872 | benjamin.peterson | 2009-12-17 20:51:37 -0600 (Thu, 17 Dec 2009) | 1 line
fix emacs header
........
r77093 | benjamin.peterson | 2009-12-28 14:43:32 -0600 (Mon, 28 Dec 2009) | 7 lines
replace callable(x) with isinstance(x, collections.Callable) #7006
This is a more accurate translation than hasattr(x, '__call__') which failed in
the case that somebody had put __call__ in the instance dictionary.
Patch mostly by Joe Amenta.
........
r77094 | benjamin.peterson | 2009-12-28 14:45:13 -0600 (Mon, 28 Dec 2009) | 2 lines
deuglify imports
........
r77095 | benjamin.peterson | 2009-12-28 14:49:23 -0600 (Mon, 28 Dec 2009) | 1 line
remove unused flag
........
r77097 | benjamin.peterson | 2009-12-28 16:12:13 -0600 (Mon, 28 Dec 2009) | 2 lines
clean up imports and whitespace
........
r77098 | benjamin.peterson | 2009-12-28 16:43:35 -0600 (Mon, 28 Dec 2009) | 1 line
*** empty log message ***
........
r77099 | benjamin.peterson | 2009-12-28 16:45:10 -0600 (Mon, 28 Dec 2009) | 1 line
revert unintended change
........
r77100 | benjamin.peterson | 2009-12-28 16:53:21 -0600 (Mon, 28 Dec 2009) | 1 line
revert unintended changes
........
r77101 | benjamin.peterson | 2009-12-28 17:46:02 -0600 (Mon, 28 Dec 2009) | 1 line
normalize whitespace
........
................
................
r77105 | benjamin.peterson | 2009-12-28 18:37:04 -0600 (Mon, 28 Dec 2009) | 1 line
fix test on py3
................
r77106 | benjamin.peterson | 2009-12-28 18:38:47 -0600 (Mon, 28 Dec 2009) | 9 lines
Merged revisions 77104 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk
........
r77104 | benjamin.peterson | 2009-12-28 18:09:33 -0600 (Mon, 28 Dec 2009) | 1 line
enable test_main.py
........
................
2009-12-28 20:44:14 -04:00
|
|
|
a = """import collections\nisinstance( x, collections.Callable)"""
|
2008-03-19 02:04:44 -03:00
|
|
|
self.check(b, a)
|
|
|
|
|
|
|
|
b = """if callable(x): pass"""
|
Merged revisions 77103,77105-77106 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/branches/py3k
................
r77103 | benjamin.peterson | 2009-12-28 18:06:20 -0600 (Mon, 28 Dec 2009) | 57 lines
Merged revisions 77102 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk
................
r77102 | benjamin.peterson | 2009-12-28 17:50:41 -0600 (Mon, 28 Dec 2009) | 50 lines
Merged revisions 76871-76872,77093-77095,77097-77101 via svnmerge from
svn+ssh://pythondev@svn.python.org/sandbox/trunk/2to3/lib2to3
........
r76871 | benjamin.peterson | 2009-12-17 20:49:21 -0600 (Thu, 17 Dec 2009) | 1 line
handle unencodable diffs gracefully #5093
........
r76872 | benjamin.peterson | 2009-12-17 20:51:37 -0600 (Thu, 17 Dec 2009) | 1 line
fix emacs header
........
r77093 | benjamin.peterson | 2009-12-28 14:43:32 -0600 (Mon, 28 Dec 2009) | 7 lines
replace callable(x) with isinstance(x, collections.Callable) #7006
This is a more accurate translation than hasattr(x, '__call__') which failed in
the case that somebody had put __call__ in the instance dictionary.
Patch mostly by Joe Amenta.
........
r77094 | benjamin.peterson | 2009-12-28 14:45:13 -0600 (Mon, 28 Dec 2009) | 2 lines
deuglify imports
........
r77095 | benjamin.peterson | 2009-12-28 14:49:23 -0600 (Mon, 28 Dec 2009) | 1 line
remove unused flag
........
r77097 | benjamin.peterson | 2009-12-28 16:12:13 -0600 (Mon, 28 Dec 2009) | 2 lines
clean up imports and whitespace
........
r77098 | benjamin.peterson | 2009-12-28 16:43:35 -0600 (Mon, 28 Dec 2009) | 1 line
*** empty log message ***
........
r77099 | benjamin.peterson | 2009-12-28 16:45:10 -0600 (Mon, 28 Dec 2009) | 1 line
revert unintended change
........
r77100 | benjamin.peterson | 2009-12-28 16:53:21 -0600 (Mon, 28 Dec 2009) | 1 line
revert unintended changes
........
r77101 | benjamin.peterson | 2009-12-28 17:46:02 -0600 (Mon, 28 Dec 2009) | 1 line
normalize whitespace
........
................
................
r77105 | benjamin.peterson | 2009-12-28 18:37:04 -0600 (Mon, 28 Dec 2009) | 1 line
fix test on py3
................
r77106 | benjamin.peterson | 2009-12-28 18:38:47 -0600 (Mon, 28 Dec 2009) | 9 lines
Merged revisions 77104 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk
........
r77104 | benjamin.peterson | 2009-12-28 18:09:33 -0600 (Mon, 28 Dec 2009) | 1 line
enable test_main.py
........
................
2009-12-28 20:44:14 -04:00
|
|
|
a = """import collections
|
|
|
|
if isinstance(x, collections.Callable): pass"""
|
2008-03-19 02:04:44 -03:00
|
|
|
self.check(b, a)
|
|
|
|
|
|
|
|
def test_callable_call(self):
|
|
|
|
b = """callable(x)"""
|
Merged revisions 77103,77105-77106 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/branches/py3k
................
r77103 | benjamin.peterson | 2009-12-28 18:06:20 -0600 (Mon, 28 Dec 2009) | 57 lines
Merged revisions 77102 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk
................
r77102 | benjamin.peterson | 2009-12-28 17:50:41 -0600 (Mon, 28 Dec 2009) | 50 lines
Merged revisions 76871-76872,77093-77095,77097-77101 via svnmerge from
svn+ssh://pythondev@svn.python.org/sandbox/trunk/2to3/lib2to3
........
r76871 | benjamin.peterson | 2009-12-17 20:49:21 -0600 (Thu, 17 Dec 2009) | 1 line
handle unencodable diffs gracefully #5093
........
r76872 | benjamin.peterson | 2009-12-17 20:51:37 -0600 (Thu, 17 Dec 2009) | 1 line
fix emacs header
........
r77093 | benjamin.peterson | 2009-12-28 14:43:32 -0600 (Mon, 28 Dec 2009) | 7 lines
replace callable(x) with isinstance(x, collections.Callable) #7006
This is a more accurate translation than hasattr(x, '__call__') which failed in
the case that somebody had put __call__ in the instance dictionary.
Patch mostly by Joe Amenta.
........
r77094 | benjamin.peterson | 2009-12-28 14:45:13 -0600 (Mon, 28 Dec 2009) | 2 lines
deuglify imports
........
r77095 | benjamin.peterson | 2009-12-28 14:49:23 -0600 (Mon, 28 Dec 2009) | 1 line
remove unused flag
........
r77097 | benjamin.peterson | 2009-12-28 16:12:13 -0600 (Mon, 28 Dec 2009) | 2 lines
clean up imports and whitespace
........
r77098 | benjamin.peterson | 2009-12-28 16:43:35 -0600 (Mon, 28 Dec 2009) | 1 line
*** empty log message ***
........
r77099 | benjamin.peterson | 2009-12-28 16:45:10 -0600 (Mon, 28 Dec 2009) | 1 line
revert unintended change
........
r77100 | benjamin.peterson | 2009-12-28 16:53:21 -0600 (Mon, 28 Dec 2009) | 1 line
revert unintended changes
........
r77101 | benjamin.peterson | 2009-12-28 17:46:02 -0600 (Mon, 28 Dec 2009) | 1 line
normalize whitespace
........
................
................
r77105 | benjamin.peterson | 2009-12-28 18:37:04 -0600 (Mon, 28 Dec 2009) | 1 line
fix test on py3
................
r77106 | benjamin.peterson | 2009-12-28 18:38:47 -0600 (Mon, 28 Dec 2009) | 9 lines
Merged revisions 77104 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk
........
r77104 | benjamin.peterson | 2009-12-28 18:09:33 -0600 (Mon, 28 Dec 2009) | 1 line
enable test_main.py
........
................
2009-12-28 20:44:14 -04:00
|
|
|
a = """import collections\nisinstance(x, collections.Callable)"""
|
|
|
|
self.check(b, a)
|
|
|
|
|
|
|
|
def test_global_import(self):
|
|
|
|
b = """
|
|
|
|
def spam(foo):
|
|
|
|
callable(foo)"""[1:]
|
|
|
|
a = """
|
|
|
|
import collections
|
|
|
|
def spam(foo):
|
|
|
|
isinstance(foo, collections.Callable)"""[1:]
|
|
|
|
self.check(b, a)
|
|
|
|
|
|
|
|
b = """
|
|
|
|
import collections
|
|
|
|
def spam(foo):
|
|
|
|
callable(foo)"""[1:]
|
|
|
|
# same output if it was already imported
|
|
|
|
self.check(b, a)
|
|
|
|
|
|
|
|
b = """
|
|
|
|
from collections import *
|
|
|
|
def spam(foo):
|
|
|
|
callable(foo)"""[1:]
|
|
|
|
a = """
|
|
|
|
from collections import *
|
|
|
|
import collections
|
|
|
|
def spam(foo):
|
|
|
|
isinstance(foo, collections.Callable)"""[1:]
|
|
|
|
self.check(b, a)
|
|
|
|
|
|
|
|
b = """
|
|
|
|
do_stuff()
|
|
|
|
do_some_other_stuff()
|
|
|
|
assert callable(do_stuff)"""[1:]
|
|
|
|
a = """
|
|
|
|
import collections
|
|
|
|
do_stuff()
|
|
|
|
do_some_other_stuff()
|
|
|
|
assert isinstance(do_stuff, collections.Callable)"""[1:]
|
|
|
|
self.check(b, a)
|
|
|
|
|
|
|
|
b = """
|
|
|
|
if isinstance(do_stuff, Callable):
|
|
|
|
assert callable(do_stuff)
|
|
|
|
do_stuff(do_stuff)
|
|
|
|
if not callable(do_stuff):
|
|
|
|
exit(1)
|
|
|
|
else:
|
|
|
|
assert callable(do_stuff)
|
|
|
|
else:
|
|
|
|
assert not callable(do_stuff)"""[1:]
|
|
|
|
a = """
|
|
|
|
import collections
|
|
|
|
if isinstance(do_stuff, Callable):
|
|
|
|
assert isinstance(do_stuff, collections.Callable)
|
|
|
|
do_stuff(do_stuff)
|
|
|
|
if not isinstance(do_stuff, collections.Callable):
|
|
|
|
exit(1)
|
|
|
|
else:
|
|
|
|
assert isinstance(do_stuff, collections.Callable)
|
|
|
|
else:
|
|
|
|
assert not isinstance(do_stuff, collections.Callable)"""[1:]
|
2008-03-19 02:04:44 -03:00
|
|
|
self.check(b, a)
|
|
|
|
|
|
|
|
def test_callable_should_not_change(self):
|
|
|
|
a = """callable(*x)"""
|
|
|
|
self.unchanged(a)
|
|
|
|
|
|
|
|
a = """callable(x, y)"""
|
|
|
|
self.unchanged(a)
|
|
|
|
|
|
|
|
a = """callable(x, kw=y)"""
|
|
|
|
self.unchanged(a)
|
|
|
|
|
|
|
|
a = """callable()"""
|
|
|
|
self.unchanged(a)
|
|
|
|
|
|
|
|
class Test_filter(FixerTestCase):
|
|
|
|
fixer = "filter"
|
|
|
|
|
|
|
|
def test_prefix_preservation(self):
|
|
|
|
b = """x = filter( foo, 'abc' )"""
|
|
|
|
a = """x = list(filter( foo, 'abc' ))"""
|
|
|
|
self.check(b, a)
|
|
|
|
|
|
|
|
b = """x = filter( None , 'abc' )"""
|
|
|
|
a = """x = [_f for _f in 'abc' if _f]"""
|
|
|
|
self.check(b, a)
|
|
|
|
|
|
|
|
def test_filter_basic(self):
|
|
|
|
b = """x = filter(None, 'abc')"""
|
|
|
|
a = """x = [_f for _f in 'abc' if _f]"""
|
|
|
|
self.check(b, a)
|
|
|
|
|
|
|
|
b = """x = len(filter(f, 'abc'))"""
|
|
|
|
a = """x = len(list(filter(f, 'abc')))"""
|
|
|
|
self.check(b, a)
|
|
|
|
|
|
|
|
b = """x = filter(lambda x: x%2 == 0, range(10))"""
|
|
|
|
a = """x = [x for x in range(10) if x%2 == 0]"""
|
|
|
|
self.check(b, a)
|
|
|
|
|
|
|
|
# Note the parens around x
|
|
|
|
b = """x = filter(lambda (x): x%2 == 0, range(10))"""
|
|
|
|
a = """x = [x for x in range(10) if x%2 == 0]"""
|
|
|
|
self.check(b, a)
|
|
|
|
|
|
|
|
# XXX This (rare) case is not supported
|
|
|
|
## b = """x = filter(f, 'abc')[0]"""
|
|
|
|
## a = """x = list(filter(f, 'abc'))[0]"""
|
|
|
|
## self.check(b, a)
|
|
|
|
|
|
|
|
def test_filter_nochange(self):
|
|
|
|
a = """b.join(filter(f, 'abc'))"""
|
|
|
|
self.unchanged(a)
|
|
|
|
a = """(a + foo(5)).join(filter(f, 'abc'))"""
|
|
|
|
self.unchanged(a)
|
|
|
|
a = """iter(filter(f, 'abc'))"""
|
|
|
|
self.unchanged(a)
|
|
|
|
a = """list(filter(f, 'abc'))"""
|
|
|
|
self.unchanged(a)
|
|
|
|
a = """list(filter(f, 'abc'))[0]"""
|
|
|
|
self.unchanged(a)
|
|
|
|
a = """set(filter(f, 'abc'))"""
|
|
|
|
self.unchanged(a)
|
|
|
|
a = """set(filter(f, 'abc')).pop()"""
|
|
|
|
self.unchanged(a)
|
|
|
|
a = """tuple(filter(f, 'abc'))"""
|
|
|
|
self.unchanged(a)
|
|
|
|
a = """any(filter(f, 'abc'))"""
|
|
|
|
self.unchanged(a)
|
|
|
|
a = """all(filter(f, 'abc'))"""
|
|
|
|
self.unchanged(a)
|
|
|
|
a = """sum(filter(f, 'abc'))"""
|
|
|
|
self.unchanged(a)
|
|
|
|
a = """sorted(filter(f, 'abc'))"""
|
|
|
|
self.unchanged(a)
|
|
|
|
a = """sorted(filter(f, 'abc'), key=blah)"""
|
|
|
|
self.unchanged(a)
|
|
|
|
a = """sorted(filter(f, 'abc'), key=blah)[0]"""
|
|
|
|
self.unchanged(a)
|
|
|
|
a = """for i in filter(f, 'abc'): pass"""
|
|
|
|
self.unchanged(a)
|
|
|
|
a = """[x for x in filter(f, 'abc')]"""
|
|
|
|
self.unchanged(a)
|
|
|
|
a = """(x for x in filter(f, 'abc'))"""
|
|
|
|
self.unchanged(a)
|
|
|
|
|
|
|
|
def test_future_builtins(self):
|
|
|
|
a = "from future_builtins import spam, filter; filter(f, 'ham')"
|
|
|
|
self.unchanged(a)
|
|
|
|
|
|
|
|
b = """from future_builtins import spam; x = filter(f, 'abc')"""
|
|
|
|
a = """from future_builtins import spam; x = list(filter(f, 'abc'))"""
|
|
|
|
self.check(b, a)
|
|
|
|
|
|
|
|
a = "from future_builtins import *; filter(f, 'ham')"
|
|
|
|
self.unchanged(a)
|
|
|
|
|
|
|
|
class Test_map(FixerTestCase):
|
|
|
|
fixer = "map"
|
|
|
|
|
|
|
|
def check(self, b, a):
|
|
|
|
self.unchanged("from future_builtins import map; " + b, a)
|
2008-11-24 23:08:21 -04:00
|
|
|
super(Test_map, self).check(b, a)
|
2008-03-19 02:04:44 -03:00
|
|
|
|
|
|
|
def test_prefix_preservation(self):
|
|
|
|
b = """x = map( f, 'abc' )"""
|
|
|
|
a = """x = list(map( f, 'abc' ))"""
|
|
|
|
self.check(b, a)
|
|
|
|
|
|
|
|
def test_trailing_comment(self):
|
|
|
|
b = """x = map(f, 'abc') # foo"""
|
|
|
|
a = """x = list(map(f, 'abc')) # foo"""
|
|
|
|
self.check(b, a)
|
|
|
|
|
Merged revisions 76063,76068 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/branches/py3k
................
r76063 | benjamin.peterson | 2009-11-02 12:16:28 -0600 (Mon, 02 Nov 2009) | 77 lines
Merged revisions 76062 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk
................
r76062 | benjamin.peterson | 2009-11-02 12:12:12 -0600 (Mon, 02 Nov 2009) | 70 lines
Merged revisions 74359,75081,75088,75213,75278,75303,75427-75428,75734-75736,75865,76059-76061 via svnmerge from
svn+ssh://pythondev@svn.python.org/sandbox/trunk/2to3/lib2to3
........
r74359 | benjamin.peterson | 2009-08-12 17:23:13 -0500 (Wed, 12 Aug 2009) | 1 line
don't pass the deprecated print_function option
........
r75081 | benjamin.peterson | 2009-09-26 22:02:57 -0500 (Sat, 26 Sep 2009) | 1 line
let 2to3 work with extended iterable unpacking
........
r75088 | benjamin.peterson | 2009-09-27 11:25:21 -0500 (Sun, 27 Sep 2009) | 1 line
look on the type only for __call__
........
r75213 | benjamin.peterson | 2009-10-03 10:09:46 -0500 (Sat, 03 Oct 2009) | 5 lines
revert 75212; it's not correct
People can use isinstance(x, collections.Callable) if they expect objects with
__call__ in their instance dictionaries.
........
r75278 | benjamin.peterson | 2009-10-07 16:25:56 -0500 (Wed, 07 Oct 2009) | 4 lines
fix whitespace problems with fix_idioms #3563
Patch by Joe Amenta.
........
r75303 | benjamin.peterson | 2009-10-09 16:59:11 -0500 (Fri, 09 Oct 2009) | 1 line
port latin-1 and utf-8 cookie improvements
........
r75427 | benjamin.peterson | 2009-10-14 20:35:57 -0500 (Wed, 14 Oct 2009) | 1 line
force floor division
........
r75428 | benjamin.peterson | 2009-10-14 20:39:21 -0500 (Wed, 14 Oct 2009) | 1 line
silence -3 warnings about __hash__
........
r75734 | benjamin.peterson | 2009-10-26 16:25:53 -0500 (Mon, 26 Oct 2009) | 2 lines
warn on map(None, ...) with more than 2 arguments #7203
........
r75735 | benjamin.peterson | 2009-10-26 16:28:25 -0500 (Mon, 26 Oct 2009) | 1 line
remove unused result
........
r75736 | benjamin.peterson | 2009-10-26 16:29:02 -0500 (Mon, 26 Oct 2009) | 1 line
using get() here is a bit pointless
........
r75865 | benjamin.peterson | 2009-10-27 15:49:00 -0500 (Tue, 27 Oct 2009) | 1 line
explain reason for warning
........
r76059 | benjamin.peterson | 2009-11-02 11:43:47 -0600 (Mon, 02 Nov 2009) | 1 line
tuples are no longer used for children
........
r76060 | benjamin.peterson | 2009-11-02 11:55:40 -0600 (Mon, 02 Nov 2009) | 1 line
revert r76059; apparently some fixers rely on Leaf no () for children
........
r76061 | benjamin.peterson | 2009-11-02 12:06:17 -0600 (Mon, 02 Nov 2009) | 1 line
make fix_tuple_params keep the tree valid #7253
........
................
................
r76068 | benjamin.peterson | 2009-11-02 12:30:48 -0600 (Mon, 02 Nov 2009) | 24 lines
Merged revisions 76064,76066-76067 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk
................
r76064 | benjamin.peterson | 2009-11-02 12:16:36 -0600 (Mon, 02 Nov 2009) | 1 line
add space
................
r76066 | benjamin.peterson | 2009-11-02 12:22:53 -0600 (Mon, 02 Nov 2009) | 9 lines
Merged revisions 76065 via svnmerge from
svn+ssh://pythondev@svn.python.org/sandbox/trunk/2to3/lib2to3
........
r76065 | benjamin.peterson | 2009-11-02 12:21:25 -0600 (Mon, 02 Nov 2009) | 1 line
don't print stuff in tests
........
................
r76067 | benjamin.peterson | 2009-11-02 12:24:57 -0600 (Mon, 02 Nov 2009) | 1 line
enable test_parser in lib2to3
................
................
2009-11-02 14:33:36 -04:00
|
|
|
def test_None_with_multiple_arguments(self):
|
|
|
|
s = """x = map(None, a, b, c)"""
|
|
|
|
self.warns_unchanged(s, "cannot convert map(None, ...) with "
|
|
|
|
"multiple arguments")
|
|
|
|
|
2008-03-19 02:04:44 -03:00
|
|
|
def test_map_basic(self):
|
|
|
|
b = """x = map(f, 'abc')"""
|
|
|
|
a = """x = list(map(f, 'abc'))"""
|
|
|
|
self.check(b, a)
|
|
|
|
|
|
|
|
b = """x = len(map(f, 'abc', 'def'))"""
|
|
|
|
a = """x = len(list(map(f, 'abc', 'def')))"""
|
|
|
|
self.check(b, a)
|
|
|
|
|
|
|
|
b = """x = map(None, 'abc')"""
|
|
|
|
a = """x = list('abc')"""
|
|
|
|
self.check(b, a)
|
|
|
|
|
|
|
|
b = """x = map(lambda x: x+1, range(4))"""
|
|
|
|
a = """x = [x+1 for x in range(4)]"""
|
|
|
|
self.check(b, a)
|
|
|
|
|
|
|
|
# Note the parens around x
|
|
|
|
b = """x = map(lambda (x): x+1, range(4))"""
|
|
|
|
a = """x = [x+1 for x in range(4)]"""
|
|
|
|
self.check(b, a)
|
|
|
|
|
|
|
|
b = """
|
|
|
|
foo()
|
|
|
|
# foo
|
|
|
|
map(f, x)
|
|
|
|
"""
|
|
|
|
a = """
|
|
|
|
foo()
|
|
|
|
# foo
|
|
|
|
list(map(f, x))
|
|
|
|
"""
|
|
|
|
self.warns(b, a, "You should use a for loop here")
|
|
|
|
|
|
|
|
# XXX This (rare) case is not supported
|
|
|
|
## b = """x = map(f, 'abc')[0]"""
|
|
|
|
## a = """x = list(map(f, 'abc'))[0]"""
|
|
|
|
## self.check(b, a)
|
|
|
|
|
|
|
|
def test_map_nochange(self):
|
|
|
|
a = """b.join(map(f, 'abc'))"""
|
|
|
|
self.unchanged(a)
|
|
|
|
a = """(a + foo(5)).join(map(f, 'abc'))"""
|
|
|
|
self.unchanged(a)
|
|
|
|
a = """iter(map(f, 'abc'))"""
|
|
|
|
self.unchanged(a)
|
|
|
|
a = """list(map(f, 'abc'))"""
|
|
|
|
self.unchanged(a)
|
|
|
|
a = """list(map(f, 'abc'))[0]"""
|
|
|
|
self.unchanged(a)
|
|
|
|
a = """set(map(f, 'abc'))"""
|
|
|
|
self.unchanged(a)
|
|
|
|
a = """set(map(f, 'abc')).pop()"""
|
|
|
|
self.unchanged(a)
|
|
|
|
a = """tuple(map(f, 'abc'))"""
|
|
|
|
self.unchanged(a)
|
|
|
|
a = """any(map(f, 'abc'))"""
|
|
|
|
self.unchanged(a)
|
|
|
|
a = """all(map(f, 'abc'))"""
|
|
|
|
self.unchanged(a)
|
|
|
|
a = """sum(map(f, 'abc'))"""
|
|
|
|
self.unchanged(a)
|
|
|
|
a = """sorted(map(f, 'abc'))"""
|
|
|
|
self.unchanged(a)
|
|
|
|
a = """sorted(map(f, 'abc'), key=blah)"""
|
|
|
|
self.unchanged(a)
|
|
|
|
a = """sorted(map(f, 'abc'), key=blah)[0]"""
|
|
|
|
self.unchanged(a)
|
|
|
|
a = """for i in map(f, 'abc'): pass"""
|
|
|
|
self.unchanged(a)
|
|
|
|
a = """[x for x in map(f, 'abc')]"""
|
|
|
|
self.unchanged(a)
|
|
|
|
a = """(x for x in map(f, 'abc'))"""
|
|
|
|
self.unchanged(a)
|
|
|
|
|
|
|
|
def test_future_builtins(self):
|
|
|
|
a = "from future_builtins import spam, map, eggs; map(f, 'ham')"
|
|
|
|
self.unchanged(a)
|
|
|
|
|
|
|
|
b = """from future_builtins import spam, eggs; x = map(f, 'abc')"""
|
|
|
|
a = """from future_builtins import spam, eggs; x = list(map(f, 'abc'))"""
|
|
|
|
self.check(b, a)
|
|
|
|
|
|
|
|
a = "from future_builtins import *; map(f, 'ham')"
|
|
|
|
self.unchanged(a)
|
|
|
|
|
2008-03-19 02:26:18 -03:00
|
|
|
class Test_zip(FixerTestCase):
|
|
|
|
fixer = "zip"
|
|
|
|
|
|
|
|
def check(self, b, a):
|
|
|
|
self.unchanged("from future_builtins import zip; " + b, a)
|
2008-11-24 23:08:21 -04:00
|
|
|
super(Test_zip, self).check(b, a)
|
2008-03-19 02:26:18 -03:00
|
|
|
|
|
|
|
def test_zip_basic(self):
|
|
|
|
b = """x = zip(a, b, c)"""
|
|
|
|
a = """x = list(zip(a, b, c))"""
|
|
|
|
self.check(b, a)
|
|
|
|
|
|
|
|
b = """x = len(zip(a, b))"""
|
|
|
|
a = """x = len(list(zip(a, b)))"""
|
|
|
|
self.check(b, a)
|
|
|
|
|
|
|
|
def test_zip_nochange(self):
|
|
|
|
a = """b.join(zip(a, b))"""
|
|
|
|
self.unchanged(a)
|
|
|
|
a = """(a + foo(5)).join(zip(a, b))"""
|
|
|
|
self.unchanged(a)
|
|
|
|
a = """iter(zip(a, b))"""
|
|
|
|
self.unchanged(a)
|
|
|
|
a = """list(zip(a, b))"""
|
|
|
|
self.unchanged(a)
|
|
|
|
a = """list(zip(a, b))[0]"""
|
|
|
|
self.unchanged(a)
|
|
|
|
a = """set(zip(a, b))"""
|
|
|
|
self.unchanged(a)
|
|
|
|
a = """set(zip(a, b)).pop()"""
|
|
|
|
self.unchanged(a)
|
|
|
|
a = """tuple(zip(a, b))"""
|
|
|
|
self.unchanged(a)
|
|
|
|
a = """any(zip(a, b))"""
|
|
|
|
self.unchanged(a)
|
|
|
|
a = """all(zip(a, b))"""
|
|
|
|
self.unchanged(a)
|
|
|
|
a = """sum(zip(a, b))"""
|
|
|
|
self.unchanged(a)
|
|
|
|
a = """sorted(zip(a, b))"""
|
|
|
|
self.unchanged(a)
|
|
|
|
a = """sorted(zip(a, b), key=blah)"""
|
|
|
|
self.unchanged(a)
|
|
|
|
a = """sorted(zip(a, b), key=blah)[0]"""
|
|
|
|
self.unchanged(a)
|
|
|
|
a = """for i in zip(a, b): pass"""
|
|
|
|
self.unchanged(a)
|
|
|
|
a = """[x for x in zip(a, b)]"""
|
|
|
|
self.unchanged(a)
|
|
|
|
a = """(x for x in zip(a, b))"""
|
|
|
|
self.unchanged(a)
|
|
|
|
|
|
|
|
def test_future_builtins(self):
|
|
|
|
a = "from future_builtins import spam, zip, eggs; zip(a, b)"
|
|
|
|
self.unchanged(a)
|
|
|
|
|
|
|
|
b = """from future_builtins import spam, eggs; x = zip(a, b)"""
|
|
|
|
a = """from future_builtins import spam, eggs; x = list(zip(a, b))"""
|
|
|
|
self.check(b, a)
|
|
|
|
|
|
|
|
a = "from future_builtins import *; zip(a, b)"
|
|
|
|
self.unchanged(a)
|
|
|
|
|
2008-03-19 02:04:44 -03:00
|
|
|
class Test_standarderror(FixerTestCase):
|
|
|
|
fixer = "standarderror"
|
|
|
|
|
|
|
|
def test(self):
|
|
|
|
b = """x = StandardError()"""
|
|
|
|
a = """x = Exception()"""
|
|
|
|
self.check(b, a)
|
|
|
|
|
|
|
|
b = """x = StandardError(a, b, c)"""
|
|
|
|
a = """x = Exception(a, b, c)"""
|
|
|
|
self.check(b, a)
|
|
|
|
|
|
|
|
b = """f(2 + StandardError(a, b, c))"""
|
|
|
|
a = """f(2 + Exception(a, b, c))"""
|
|
|
|
self.check(b, a)
|
|
|
|
|
|
|
|
class Test_types(FixerTestCase):
|
|
|
|
fixer = "types"
|
|
|
|
|
|
|
|
def test_basic_types_convert(self):
|
|
|
|
b = """types.StringType"""
|
|
|
|
a = """bytes"""
|
|
|
|
self.check(b, a)
|
|
|
|
|
|
|
|
b = """types.DictType"""
|
|
|
|
a = """dict"""
|
|
|
|
self.check(b, a)
|
|
|
|
|
|
|
|
b = """types . IntType"""
|
|
|
|
a = """int"""
|
|
|
|
self.check(b, a)
|
|
|
|
|
|
|
|
b = """types.ListType"""
|
|
|
|
a = """list"""
|
|
|
|
self.check(b, a)
|
|
|
|
|
|
|
|
b = """types.LongType"""
|
|
|
|
a = """int"""
|
|
|
|
self.check(b, a)
|
|
|
|
|
|
|
|
b = """types.NoneType"""
|
|
|
|
a = """type(None)"""
|
|
|
|
self.check(b, a)
|
|
|
|
|
|
|
|
class Test_idioms(FixerTestCase):
|
|
|
|
fixer = "idioms"
|
|
|
|
|
|
|
|
def test_while(self):
|
|
|
|
b = """while 1: foo()"""
|
|
|
|
a = """while True: foo()"""
|
|
|
|
self.check(b, a)
|
|
|
|
|
|
|
|
b = """while 1: foo()"""
|
|
|
|
a = """while True: foo()"""
|
|
|
|
self.check(b, a)
|
|
|
|
|
|
|
|
b = """
|
|
|
|
while 1:
|
|
|
|
foo()
|
|
|
|
"""
|
|
|
|
a = """
|
|
|
|
while True:
|
|
|
|
foo()
|
|
|
|
"""
|
|
|
|
self.check(b, a)
|
|
|
|
|
|
|
|
def test_while_unchanged(self):
|
|
|
|
s = """while 11: foo()"""
|
|
|
|
self.unchanged(s)
|
|
|
|
|
|
|
|
s = """while 0: foo()"""
|
|
|
|
self.unchanged(s)
|
|
|
|
|
|
|
|
s = """while foo(): foo()"""
|
|
|
|
self.unchanged(s)
|
|
|
|
|
|
|
|
s = """while []: foo()"""
|
|
|
|
self.unchanged(s)
|
|
|
|
|
|
|
|
def test_eq_simple(self):
|
|
|
|
b = """type(x) == T"""
|
|
|
|
a = """isinstance(x, T)"""
|
|
|
|
self.check(b, a)
|
|
|
|
|
|
|
|
b = """if type(x) == T: pass"""
|
|
|
|
a = """if isinstance(x, T): pass"""
|
|
|
|
self.check(b, a)
|
|
|
|
|
|
|
|
def test_eq_reverse(self):
|
|
|
|
b = """T == type(x)"""
|
|
|
|
a = """isinstance(x, T)"""
|
|
|
|
self.check(b, a)
|
|
|
|
|
|
|
|
b = """if T == type(x): pass"""
|
|
|
|
a = """if isinstance(x, T): pass"""
|
|
|
|
self.check(b, a)
|
|
|
|
|
|
|
|
def test_eq_expression(self):
|
|
|
|
b = """type(x+y) == d.get('T')"""
|
|
|
|
a = """isinstance(x+y, d.get('T'))"""
|
|
|
|
self.check(b, a)
|
|
|
|
|
|
|
|
b = """type( x + y) == d.get('T')"""
|
|
|
|
a = """isinstance(x + y, d.get('T'))"""
|
|
|
|
self.check(b, a)
|
|
|
|
|
|
|
|
def test_is_simple(self):
|
|
|
|
b = """type(x) is T"""
|
|
|
|
a = """isinstance(x, T)"""
|
|
|
|
self.check(b, a)
|
|
|
|
|
|
|
|
b = """if type(x) is T: pass"""
|
|
|
|
a = """if isinstance(x, T): pass"""
|
|
|
|
self.check(b, a)
|
|
|
|
|
|
|
|
def test_is_reverse(self):
|
|
|
|
b = """T is type(x)"""
|
|
|
|
a = """isinstance(x, T)"""
|
|
|
|
self.check(b, a)
|
|
|
|
|
|
|
|
b = """if T is type(x): pass"""
|
|
|
|
a = """if isinstance(x, T): pass"""
|
|
|
|
self.check(b, a)
|
|
|
|
|
|
|
|
def test_is_expression(self):
|
|
|
|
b = """type(x+y) is d.get('T')"""
|
|
|
|
a = """isinstance(x+y, d.get('T'))"""
|
|
|
|
self.check(b, a)
|
|
|
|
|
|
|
|
b = """type( x + y) is d.get('T')"""
|
|
|
|
a = """isinstance(x + y, d.get('T'))"""
|
|
|
|
self.check(b, a)
|
|
|
|
|
|
|
|
def test_is_not_simple(self):
|
|
|
|
b = """type(x) is not T"""
|
|
|
|
a = """not isinstance(x, T)"""
|
|
|
|
self.check(b, a)
|
|
|
|
|
|
|
|
b = """if type(x) is not T: pass"""
|
|
|
|
a = """if not isinstance(x, T): pass"""
|
|
|
|
self.check(b, a)
|
|
|
|
|
|
|
|
def test_is_not_reverse(self):
|
|
|
|
b = """T is not type(x)"""
|
|
|
|
a = """not isinstance(x, T)"""
|
|
|
|
self.check(b, a)
|
|
|
|
|
|
|
|
b = """if T is not type(x): pass"""
|
|
|
|
a = """if not isinstance(x, T): pass"""
|
|
|
|
self.check(b, a)
|
|
|
|
|
|
|
|
def test_is_not_expression(self):
|
|
|
|
b = """type(x+y) is not d.get('T')"""
|
|
|
|
a = """not isinstance(x+y, d.get('T'))"""
|
|
|
|
self.check(b, a)
|
|
|
|
|
|
|
|
b = """type( x + y) is not d.get('T')"""
|
|
|
|
a = """not isinstance(x + y, d.get('T'))"""
|
|
|
|
self.check(b, a)
|
|
|
|
|
|
|
|
def test_ne_simple(self):
|
|
|
|
b = """type(x) != T"""
|
|
|
|
a = """not isinstance(x, T)"""
|
|
|
|
self.check(b, a)
|
|
|
|
|
|
|
|
b = """if type(x) != T: pass"""
|
|
|
|
a = """if not isinstance(x, T): pass"""
|
|
|
|
self.check(b, a)
|
|
|
|
|
|
|
|
def test_ne_reverse(self):
|
|
|
|
b = """T != type(x)"""
|
|
|
|
a = """not isinstance(x, T)"""
|
|
|
|
self.check(b, a)
|
|
|
|
|
|
|
|
b = """if T != type(x): pass"""
|
|
|
|
a = """if not isinstance(x, T): pass"""
|
|
|
|
self.check(b, a)
|
|
|
|
|
|
|
|
def test_ne_expression(self):
|
|
|
|
b = """type(x+y) != d.get('T')"""
|
|
|
|
a = """not isinstance(x+y, d.get('T'))"""
|
|
|
|
self.check(b, a)
|
|
|
|
|
|
|
|
b = """type( x + y) != d.get('T')"""
|
|
|
|
a = """not isinstance(x + y, d.get('T'))"""
|
|
|
|
self.check(b, a)
|
|
|
|
|
|
|
|
def test_type_unchanged(self):
|
|
|
|
a = """type(x).__name__"""
|
|
|
|
self.unchanged(a)
|
|
|
|
|
|
|
|
def test_sort_list_call(self):
|
|
|
|
b = """
|
|
|
|
v = list(t)
|
|
|
|
v.sort()
|
|
|
|
foo(v)
|
|
|
|
"""
|
|
|
|
a = """
|
|
|
|
v = sorted(t)
|
|
|
|
foo(v)
|
|
|
|
"""
|
|
|
|
self.check(b, a)
|
|
|
|
|
|
|
|
b = """
|
|
|
|
v = list(foo(b) + d)
|
|
|
|
v.sort()
|
|
|
|
foo(v)
|
|
|
|
"""
|
|
|
|
a = """
|
|
|
|
v = sorted(foo(b) + d)
|
|
|
|
foo(v)
|
|
|
|
"""
|
|
|
|
self.check(b, a)
|
|
|
|
|
|
|
|
b = """
|
|
|
|
while x:
|
|
|
|
v = list(t)
|
|
|
|
v.sort()
|
|
|
|
foo(v)
|
|
|
|
"""
|
|
|
|
a = """
|
|
|
|
while x:
|
|
|
|
v = sorted(t)
|
|
|
|
foo(v)
|
|
|
|
"""
|
|
|
|
self.check(b, a)
|
|
|
|
|
|
|
|
b = """
|
|
|
|
v = list(t)
|
|
|
|
# foo
|
|
|
|
v.sort()
|
|
|
|
foo(v)
|
|
|
|
"""
|
|
|
|
a = """
|
|
|
|
v = sorted(t)
|
|
|
|
# foo
|
|
|
|
foo(v)
|
|
|
|
"""
|
|
|
|
self.check(b, a)
|
|
|
|
|
|
|
|
b = r"""
|
|
|
|
v = list( t)
|
|
|
|
v.sort()
|
|
|
|
foo(v)
|
|
|
|
"""
|
|
|
|
a = r"""
|
|
|
|
v = sorted( t)
|
|
|
|
foo(v)
|
|
|
|
"""
|
|
|
|
self.check(b, a)
|
|
|
|
|
Merged revisions 76063,76068 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/branches/py3k
................
r76063 | benjamin.peterson | 2009-11-02 12:16:28 -0600 (Mon, 02 Nov 2009) | 77 lines
Merged revisions 76062 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk
................
r76062 | benjamin.peterson | 2009-11-02 12:12:12 -0600 (Mon, 02 Nov 2009) | 70 lines
Merged revisions 74359,75081,75088,75213,75278,75303,75427-75428,75734-75736,75865,76059-76061 via svnmerge from
svn+ssh://pythondev@svn.python.org/sandbox/trunk/2to3/lib2to3
........
r74359 | benjamin.peterson | 2009-08-12 17:23:13 -0500 (Wed, 12 Aug 2009) | 1 line
don't pass the deprecated print_function option
........
r75081 | benjamin.peterson | 2009-09-26 22:02:57 -0500 (Sat, 26 Sep 2009) | 1 line
let 2to3 work with extended iterable unpacking
........
r75088 | benjamin.peterson | 2009-09-27 11:25:21 -0500 (Sun, 27 Sep 2009) | 1 line
look on the type only for __call__
........
r75213 | benjamin.peterson | 2009-10-03 10:09:46 -0500 (Sat, 03 Oct 2009) | 5 lines
revert 75212; it's not correct
People can use isinstance(x, collections.Callable) if they expect objects with
__call__ in their instance dictionaries.
........
r75278 | benjamin.peterson | 2009-10-07 16:25:56 -0500 (Wed, 07 Oct 2009) | 4 lines
fix whitespace problems with fix_idioms #3563
Patch by Joe Amenta.
........
r75303 | benjamin.peterson | 2009-10-09 16:59:11 -0500 (Fri, 09 Oct 2009) | 1 line
port latin-1 and utf-8 cookie improvements
........
r75427 | benjamin.peterson | 2009-10-14 20:35:57 -0500 (Wed, 14 Oct 2009) | 1 line
force floor division
........
r75428 | benjamin.peterson | 2009-10-14 20:39:21 -0500 (Wed, 14 Oct 2009) | 1 line
silence -3 warnings about __hash__
........
r75734 | benjamin.peterson | 2009-10-26 16:25:53 -0500 (Mon, 26 Oct 2009) | 2 lines
warn on map(None, ...) with more than 2 arguments #7203
........
r75735 | benjamin.peterson | 2009-10-26 16:28:25 -0500 (Mon, 26 Oct 2009) | 1 line
remove unused result
........
r75736 | benjamin.peterson | 2009-10-26 16:29:02 -0500 (Mon, 26 Oct 2009) | 1 line
using get() here is a bit pointless
........
r75865 | benjamin.peterson | 2009-10-27 15:49:00 -0500 (Tue, 27 Oct 2009) | 1 line
explain reason for warning
........
r76059 | benjamin.peterson | 2009-11-02 11:43:47 -0600 (Mon, 02 Nov 2009) | 1 line
tuples are no longer used for children
........
r76060 | benjamin.peterson | 2009-11-02 11:55:40 -0600 (Mon, 02 Nov 2009) | 1 line
revert r76059; apparently some fixers rely on Leaf no () for children
........
r76061 | benjamin.peterson | 2009-11-02 12:06:17 -0600 (Mon, 02 Nov 2009) | 1 line
make fix_tuple_params keep the tree valid #7253
........
................
................
r76068 | benjamin.peterson | 2009-11-02 12:30:48 -0600 (Mon, 02 Nov 2009) | 24 lines
Merged revisions 76064,76066-76067 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk
................
r76064 | benjamin.peterson | 2009-11-02 12:16:36 -0600 (Mon, 02 Nov 2009) | 1 line
add space
................
r76066 | benjamin.peterson | 2009-11-02 12:22:53 -0600 (Mon, 02 Nov 2009) | 9 lines
Merged revisions 76065 via svnmerge from
svn+ssh://pythondev@svn.python.org/sandbox/trunk/2to3/lib2to3
........
r76065 | benjamin.peterson | 2009-11-02 12:21:25 -0600 (Mon, 02 Nov 2009) | 1 line
don't print stuff in tests
........
................
r76067 | benjamin.peterson | 2009-11-02 12:24:57 -0600 (Mon, 02 Nov 2009) | 1 line
enable test_parser in lib2to3
................
................
2009-11-02 14:33:36 -04:00
|
|
|
b = r"""
|
|
|
|
try:
|
|
|
|
m = list(s)
|
|
|
|
m.sort()
|
|
|
|
except: pass
|
|
|
|
"""
|
|
|
|
|
|
|
|
a = r"""
|
|
|
|
try:
|
|
|
|
m = sorted(s)
|
|
|
|
except: pass
|
|
|
|
"""
|
|
|
|
self.check(b, a)
|
|
|
|
|
|
|
|
b = r"""
|
|
|
|
try:
|
|
|
|
m = list(s)
|
|
|
|
# foo
|
|
|
|
m.sort()
|
|
|
|
except: pass
|
|
|
|
"""
|
|
|
|
|
|
|
|
a = r"""
|
|
|
|
try:
|
|
|
|
m = sorted(s)
|
|
|
|
# foo
|
|
|
|
except: pass
|
|
|
|
"""
|
|
|
|
self.check(b, a)
|
|
|
|
|
|
|
|
b = r"""
|
|
|
|
m = list(s)
|
|
|
|
# more comments
|
|
|
|
m.sort()"""
|
|
|
|
|
|
|
|
a = r"""
|
|
|
|
m = sorted(s)
|
|
|
|
# more comments"""
|
|
|
|
self.check(b, a)
|
|
|
|
|
2008-03-19 02:04:44 -03:00
|
|
|
def test_sort_simple_expr(self):
|
|
|
|
b = """
|
|
|
|
v = t
|
|
|
|
v.sort()
|
|
|
|
foo(v)
|
|
|
|
"""
|
|
|
|
a = """
|
|
|
|
v = sorted(t)
|
|
|
|
foo(v)
|
|
|
|
"""
|
|
|
|
self.check(b, a)
|
|
|
|
|
|
|
|
b = """
|
|
|
|
v = foo(b)
|
|
|
|
v.sort()
|
|
|
|
foo(v)
|
|
|
|
"""
|
|
|
|
a = """
|
|
|
|
v = sorted(foo(b))
|
|
|
|
foo(v)
|
|
|
|
"""
|
|
|
|
self.check(b, a)
|
|
|
|
|
|
|
|
b = """
|
|
|
|
v = b.keys()
|
|
|
|
v.sort()
|
|
|
|
foo(v)
|
|
|
|
"""
|
|
|
|
a = """
|
|
|
|
v = sorted(b.keys())
|
|
|
|
foo(v)
|
|
|
|
"""
|
|
|
|
self.check(b, a)
|
|
|
|
|
|
|
|
b = """
|
|
|
|
v = foo(b) + d
|
|
|
|
v.sort()
|
|
|
|
foo(v)
|
|
|
|
"""
|
|
|
|
a = """
|
|
|
|
v = sorted(foo(b) + d)
|
|
|
|
foo(v)
|
|
|
|
"""
|
|
|
|
self.check(b, a)
|
|
|
|
|
|
|
|
b = """
|
|
|
|
while x:
|
|
|
|
v = t
|
|
|
|
v.sort()
|
|
|
|
foo(v)
|
|
|
|
"""
|
|
|
|
a = """
|
|
|
|
while x:
|
|
|
|
v = sorted(t)
|
|
|
|
foo(v)
|
|
|
|
"""
|
|
|
|
self.check(b, a)
|
|
|
|
|
|
|
|
b = """
|
|
|
|
v = t
|
|
|
|
# foo
|
|
|
|
v.sort()
|
|
|
|
foo(v)
|
|
|
|
"""
|
|
|
|
a = """
|
|
|
|
v = sorted(t)
|
|
|
|
# foo
|
|
|
|
foo(v)
|
|
|
|
"""
|
|
|
|
self.check(b, a)
|
|
|
|
|
|
|
|
b = r"""
|
|
|
|
v = t
|
|
|
|
v.sort()
|
|
|
|
foo(v)
|
|
|
|
"""
|
|
|
|
a = r"""
|
|
|
|
v = sorted(t)
|
|
|
|
foo(v)
|
|
|
|
"""
|
|
|
|
self.check(b, a)
|
|
|
|
|
|
|
|
def test_sort_unchanged(self):
|
|
|
|
s = """
|
|
|
|
v = list(t)
|
|
|
|
w.sort()
|
|
|
|
foo(w)
|
|
|
|
"""
|
|
|
|
self.unchanged(s)
|
|
|
|
|
|
|
|
s = """
|
|
|
|
v = list(t)
|
|
|
|
v.sort(u)
|
|
|
|
foo(v)
|
|
|
|
"""
|
|
|
|
self.unchanged(s)
|
|
|
|
|
|
|
|
class Test_basestring(FixerTestCase):
|
|
|
|
fixer = "basestring"
|
|
|
|
|
|
|
|
def test_basestring(self):
|
|
|
|
b = """isinstance(x, basestring)"""
|
|
|
|
a = """isinstance(x, str)"""
|
|
|
|
self.check(b, a)
|
|
|
|
|
|
|
|
class Test_buffer(FixerTestCase):
|
|
|
|
fixer = "buffer"
|
|
|
|
|
|
|
|
def test_buffer(self):
|
|
|
|
b = """x = buffer(y)"""
|
|
|
|
a = """x = memoryview(y)"""
|
|
|
|
self.check(b, a)
|
|
|
|
|
Merged revisions 73370 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk
................
r73370 | benjamin.peterson | 2009-06-11 17:06:46 -0500 (Thu, 11 Jun 2009) | 105 lines
Merged revisions 72523,72950-72951,72994,73003,73033,73036-73040,73091-73093,73096,73179-73181,73192,73231,73244,73255-73256,73365 via svnmerge from
svn+ssh://pythondev@svn.python.org/sandbox/trunk/2to3/lib2to3
........
r72523 | benjamin.peterson | 2009-05-09 14:42:26 -0500 (Sat, 09 May 2009) | 1 line
remove parenthesis
........
r72950 | benjamin.peterson | 2009-05-26 18:19:45 -0500 (Tue, 26 May 2009) | 1 line
remove unused imports
........
r72951 | benjamin.peterson | 2009-05-26 18:27:00 -0500 (Tue, 26 May 2009) | 1 line
this is no longer executable
........
r72994 | benjamin.peterson | 2009-05-28 15:32:54 -0500 (Thu, 28 May 2009) | 1 line
fix test_all_fixers on Windows #6134
........
r73003 | benjamin.peterson | 2009-05-28 21:57:28 -0500 (Thu, 28 May 2009) | 4 lines
make 2to3 test utilities easier to use with other applications (3to2)
Patch by Joe Amenta
........
r73033 | benjamin.peterson | 2009-05-29 16:58:32 -0500 (Fri, 29 May 2009) | 1 line
update grammar for multi with statement
........
r73036 | benjamin.peterson | 2009-05-29 17:33:20 -0500 (Fri, 29 May 2009) | 1 line
simplify fix_unicode
........
r73037 | benjamin.peterson | 2009-05-29 17:53:03 -0500 (Fri, 29 May 2009) | 1 line
add custom error for pattern syntax errors
........
r73038 | benjamin.peterson | 2009-05-29 17:55:00 -0500 (Fri, 29 May 2009) | 1 line
complain if details are attached to a token
........
r73039 | benjamin.peterson | 2009-05-29 18:00:28 -0500 (Fri, 29 May 2009) | 1 line
add a test for whitespace
........
r73040 | benjamin.peterson | 2009-05-29 18:01:17 -0500 (Fri, 29 May 2009) | 1 line
a fix for emacs highlighting
........
r73091 | benjamin.peterson | 2009-05-31 20:55:25 -0500 (Sun, 31 May 2009) | 1 line
deprecate set_prefix() and get_prefix() in favor of a prefix property
........
r73092 | benjamin.peterson | 2009-05-31 21:00:51 -0500 (Sun, 31 May 2009) | 1 line
change hideous java naming scheme
........
r73093 | benjamin.peterson | 2009-05-31 21:01:39 -0500 (Sun, 31 May 2009) | 1 line
remove dated comment
........
r73096 | benjamin.peterson | 2009-05-31 21:40:53 -0500 (Sun, 31 May 2009) | 1 line
group tests
........
r73179 | benjamin.peterson | 2009-06-03 13:09:53 -0500 (Wed, 03 Jun 2009) | 1 line
handle the case where there's multiple trailers #6185
........
r73180 | benjamin.peterson | 2009-06-03 13:18:05 -0500 (Wed, 03 Jun 2009) | 1 line
scrap __main__ section
........
r73181 | benjamin.peterson | 2009-06-03 13:24:48 -0500 (Wed, 03 Jun 2009) | 1 line
remove shebang lines and __main__ sections
........
r73192 | benjamin.peterson | 2009-06-03 19:16:30 -0500 (Wed, 03 Jun 2009) | 4 lines
actually test something here
Thanks to Joe Amenta for noticing.y
........
r73231 | benjamin.peterson | 2009-06-04 13:38:50 -0500 (Thu, 04 Jun 2009) | 1 line
remove unused variable
........
r73244 | benjamin.peterson | 2009-06-05 08:39:25 -0500 (Fri, 05 Jun 2009) | 1 line
allow fixers to give different options in setUp
........
r73255 | benjamin.peterson | 2009-06-06 11:23:46 -0500 (Sat, 06 Jun 2009) | 1 line
fix the except fixer on one line suites #6222
........
r73256 | benjamin.peterson | 2009-06-06 11:27:40 -0500 (Sat, 06 Jun 2009) | 1 line
test one-line else and finally clauses
........
r73365 | benjamin.peterson | 2009-06-11 17:01:32 -0500 (Thu, 11 Jun 2009) | 1 line
normalize whitespace
........
................
2009-06-11 20:47:38 -03:00
|
|
|
def test_slicing(self):
|
|
|
|
b = """buffer(y)[4:5]"""
|
|
|
|
a = """memoryview(y)[4:5]"""
|
|
|
|
self.check(b, a)
|
|
|
|
|
2008-03-19 02:04:44 -03:00
|
|
|
class Test_future(FixerTestCase):
|
|
|
|
fixer = "future"
|
|
|
|
|
|
|
|
def test_future(self):
|
|
|
|
b = """from __future__ import braces"""
|
|
|
|
a = """"""
|
|
|
|
self.check(b, a)
|
|
|
|
|
Merged revisions 61724-61725 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk
................
r61724 | martin.v.loewis | 2008-03-22 01:01:12 +0100 (Sa, 22 Mär 2008) | 49 lines
Merged revisions 61602-61723 via svnmerge from
svn+ssh://pythondev@svn.python.org/sandbox/trunk/2to3/lib2to3
........
r61626 | david.wolever | 2008-03-19 17:19:16 +0100 (Mi, 19 Mär 2008) | 1 line
Added fixer for implicit local imports. See #2414.
........
r61628 | david.wolever | 2008-03-19 17:57:43 +0100 (Mi, 19 Mär 2008) | 1 line
Added a class for tests which should not run if a particular import is found.
........
r61629 | collin.winter | 2008-03-19 17:58:19 +0100 (Mi, 19 Mär 2008) | 1 line
Two more relative import fixes in pgen2.
........
r61635 | david.wolever | 2008-03-19 20:16:03 +0100 (Mi, 19 Mär 2008) | 1 line
Fixed print fixer so it will do the Right Thing when it encounters __future__.print_function. 2to3 gets upset, though, so the tests have been commented out.
........
r61637 | david.wolever | 2008-03-19 21:37:17 +0100 (Mi, 19 Mär 2008) | 3 lines
Added a fixer for itertools imports (from itertools import imap, ifilterfalse --> from itertools import filterfalse)
........
r61645 | david.wolever | 2008-03-19 23:22:35 +0100 (Mi, 19 Mär 2008) | 1 line
SVN is happier when you add the files you create... -_-'
........
r61654 | david.wolever | 2008-03-20 01:09:56 +0100 (Do, 20 Mär 2008) | 1 line
Added an explicit sort order to fixers -- fixes problems like #2427
........
r61664 | david.wolever | 2008-03-20 04:32:40 +0100 (Do, 20 Mär 2008) | 3 lines
Fixes #2428 -- comments are no longer eatten by __future__ fixer.
........
r61673 | david.wolever | 2008-03-20 17:22:40 +0100 (Do, 20 Mär 2008) | 1 line
Added 2to3 node pretty-printer
........
r61679 | david.wolever | 2008-03-20 20:50:42 +0100 (Do, 20 Mär 2008) | 1 line
Made node printing a little bit prettier
........
r61723 | martin.v.loewis | 2008-03-22 00:59:27 +0100 (Sa, 22 Mär 2008) | 2 lines
Fix whitespace.
........
................
r61725 | martin.v.loewis | 2008-03-22 01:02:41 +0100 (Sa, 22 Mär 2008) | 2 lines
Install lib2to3.
................
2008-03-21 21:07:09 -03:00
|
|
|
b = """# comment\nfrom __future__ import braces"""
|
|
|
|
a = """# comment\n"""
|
|
|
|
self.check(b, a)
|
|
|
|
|
|
|
|
b = """from __future__ import braces\n# comment"""
|
|
|
|
a = """\n# comment"""
|
|
|
|
self.check(b, a)
|
|
|
|
|
|
|
|
def test_run_order(self):
|
|
|
|
self.assert_runs_after('print')
|
|
|
|
|
2008-03-19 02:04:44 -03:00
|
|
|
class Test_itertools(FixerTestCase):
|
|
|
|
fixer = "itertools"
|
|
|
|
|
|
|
|
def checkall(self, before, after):
|
|
|
|
# Because we need to check with and without the itertools prefix
|
|
|
|
# and on each of the three functions, these loops make it all
|
|
|
|
# much easier
|
|
|
|
for i in ('itertools.', ''):
|
|
|
|
for f in ('map', 'filter', 'zip'):
|
|
|
|
b = before %(i+'i'+f)
|
|
|
|
a = after %(f)
|
|
|
|
self.check(b, a)
|
|
|
|
|
|
|
|
def test_0(self):
|
|
|
|
# A simple example -- test_1 covers exactly the same thing,
|
|
|
|
# but it's not quite as clear.
|
|
|
|
b = "itertools.izip(a, b)"
|
|
|
|
a = "zip(a, b)"
|
|
|
|
self.check(b, a)
|
|
|
|
|
|
|
|
def test_1(self):
|
|
|
|
b = """%s(f, a)"""
|
|
|
|
a = """%s(f, a)"""
|
|
|
|
self.checkall(b, a)
|
|
|
|
|
|
|
|
def test_2(self):
|
|
|
|
b = """itertools.ifilterfalse(a, b)"""
|
|
|
|
a = """itertools.filterfalse(a, b)"""
|
|
|
|
self.check(b, a)
|
|
|
|
|
|
|
|
def test_4(self):
|
|
|
|
b = """ifilterfalse(a, b)"""
|
|
|
|
a = """filterfalse(a, b)"""
|
|
|
|
self.check(b, a)
|
|
|
|
|
|
|
|
def test_space_1(self):
|
|
|
|
b = """ %s(f, a)"""
|
|
|
|
a = """ %s(f, a)"""
|
|
|
|
self.checkall(b, a)
|
|
|
|
|
|
|
|
def test_space_2(self):
|
|
|
|
b = """ itertools.ifilterfalse(a, b)"""
|
|
|
|
a = """ itertools.filterfalse(a, b)"""
|
|
|
|
self.check(b, a)
|
|
|
|
|
Merged revisions 61724-61725 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk
................
r61724 | martin.v.loewis | 2008-03-22 01:01:12 +0100 (Sa, 22 Mär 2008) | 49 lines
Merged revisions 61602-61723 via svnmerge from
svn+ssh://pythondev@svn.python.org/sandbox/trunk/2to3/lib2to3
........
r61626 | david.wolever | 2008-03-19 17:19:16 +0100 (Mi, 19 Mär 2008) | 1 line
Added fixer for implicit local imports. See #2414.
........
r61628 | david.wolever | 2008-03-19 17:57:43 +0100 (Mi, 19 Mär 2008) | 1 line
Added a class for tests which should not run if a particular import is found.
........
r61629 | collin.winter | 2008-03-19 17:58:19 +0100 (Mi, 19 Mär 2008) | 1 line
Two more relative import fixes in pgen2.
........
r61635 | david.wolever | 2008-03-19 20:16:03 +0100 (Mi, 19 Mär 2008) | 1 line
Fixed print fixer so it will do the Right Thing when it encounters __future__.print_function. 2to3 gets upset, though, so the tests have been commented out.
........
r61637 | david.wolever | 2008-03-19 21:37:17 +0100 (Mi, 19 Mär 2008) | 3 lines
Added a fixer for itertools imports (from itertools import imap, ifilterfalse --> from itertools import filterfalse)
........
r61645 | david.wolever | 2008-03-19 23:22:35 +0100 (Mi, 19 Mär 2008) | 1 line
SVN is happier when you add the files you create... -_-'
........
r61654 | david.wolever | 2008-03-20 01:09:56 +0100 (Do, 20 Mär 2008) | 1 line
Added an explicit sort order to fixers -- fixes problems like #2427
........
r61664 | david.wolever | 2008-03-20 04:32:40 +0100 (Do, 20 Mär 2008) | 3 lines
Fixes #2428 -- comments are no longer eatten by __future__ fixer.
........
r61673 | david.wolever | 2008-03-20 17:22:40 +0100 (Do, 20 Mär 2008) | 1 line
Added 2to3 node pretty-printer
........
r61679 | david.wolever | 2008-03-20 20:50:42 +0100 (Do, 20 Mär 2008) | 1 line
Made node printing a little bit prettier
........
r61723 | martin.v.loewis | 2008-03-22 00:59:27 +0100 (Sa, 22 Mär 2008) | 2 lines
Fix whitespace.
........
................
r61725 | martin.v.loewis | 2008-03-22 01:02:41 +0100 (Sa, 22 Mär 2008) | 2 lines
Install lib2to3.
................
2008-03-21 21:07:09 -03:00
|
|
|
def test_run_order(self):
|
|
|
|
self.assert_runs_after('map', 'zip', 'filter')
|
|
|
|
|
|
|
|
class Test_itertools_imports(FixerTestCase):
|
|
|
|
fixer = 'itertools_imports'
|
|
|
|
|
|
|
|
def test_reduced(self):
|
|
|
|
b = "from itertools import imap, izip, foo"
|
|
|
|
a = "from itertools import foo"
|
|
|
|
self.check(b, a)
|
|
|
|
|
|
|
|
b = "from itertools import bar, imap, izip, foo"
|
|
|
|
a = "from itertools import bar, foo"
|
|
|
|
self.check(b, a)
|
|
|
|
|
|
|
|
def test_comments(self):
|
|
|
|
b = "#foo\nfrom itertools import imap, izip"
|
|
|
|
a = "#foo\n"
|
|
|
|
self.check(b, a)
|
|
|
|
|
|
|
|
def test_none(self):
|
|
|
|
b = "from itertools import imap, izip"
|
|
|
|
a = ""
|
|
|
|
self.check(b, a)
|
|
|
|
|
2008-03-23 21:50:58 -03:00
|
|
|
b = "from itertools import izip"
|
|
|
|
a = ""
|
|
|
|
self.check(b, a)
|
|
|
|
|
Merged revisions 61724-61725 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk
................
r61724 | martin.v.loewis | 2008-03-22 01:01:12 +0100 (Sa, 22 Mär 2008) | 49 lines
Merged revisions 61602-61723 via svnmerge from
svn+ssh://pythondev@svn.python.org/sandbox/trunk/2to3/lib2to3
........
r61626 | david.wolever | 2008-03-19 17:19:16 +0100 (Mi, 19 Mär 2008) | 1 line
Added fixer for implicit local imports. See #2414.
........
r61628 | david.wolever | 2008-03-19 17:57:43 +0100 (Mi, 19 Mär 2008) | 1 line
Added a class for tests which should not run if a particular import is found.
........
r61629 | collin.winter | 2008-03-19 17:58:19 +0100 (Mi, 19 Mär 2008) | 1 line
Two more relative import fixes in pgen2.
........
r61635 | david.wolever | 2008-03-19 20:16:03 +0100 (Mi, 19 Mär 2008) | 1 line
Fixed print fixer so it will do the Right Thing when it encounters __future__.print_function. 2to3 gets upset, though, so the tests have been commented out.
........
r61637 | david.wolever | 2008-03-19 21:37:17 +0100 (Mi, 19 Mär 2008) | 3 lines
Added a fixer for itertools imports (from itertools import imap, ifilterfalse --> from itertools import filterfalse)
........
r61645 | david.wolever | 2008-03-19 23:22:35 +0100 (Mi, 19 Mär 2008) | 1 line
SVN is happier when you add the files you create... -_-'
........
r61654 | david.wolever | 2008-03-20 01:09:56 +0100 (Do, 20 Mär 2008) | 1 line
Added an explicit sort order to fixers -- fixes problems like #2427
........
r61664 | david.wolever | 2008-03-20 04:32:40 +0100 (Do, 20 Mär 2008) | 3 lines
Fixes #2428 -- comments are no longer eatten by __future__ fixer.
........
r61673 | david.wolever | 2008-03-20 17:22:40 +0100 (Do, 20 Mär 2008) | 1 line
Added 2to3 node pretty-printer
........
r61679 | david.wolever | 2008-03-20 20:50:42 +0100 (Do, 20 Mär 2008) | 1 line
Made node printing a little bit prettier
........
r61723 | martin.v.loewis | 2008-03-22 00:59:27 +0100 (Sa, 22 Mär 2008) | 2 lines
Fix whitespace.
........
................
r61725 | martin.v.loewis | 2008-03-22 01:02:41 +0100 (Sa, 22 Mär 2008) | 2 lines
Install lib2to3.
................
2008-03-21 21:07:09 -03:00
|
|
|
def test_import_as(self):
|
|
|
|
b = "from itertools import izip, bar as bang, imap"
|
|
|
|
a = "from itertools import bar as bang"
|
|
|
|
self.check(b, a)
|
|
|
|
|
Merged revisions 72368 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk
................
r72368 | benjamin.peterson | 2009-05-05 18:13:58 -0500 (Tue, 05 May 2009) | 53 lines
Merged revisions 68503,68507,68694,69054,69673,69679-69681,70991,70999,71003,71695 via svnmerge from
svn+ssh://pythondev@svn.python.org/sandbox/trunk/2to3/lib2to3
........
r68503 | benjamin.peterson | 2009-01-10 14:14:49 -0600 (Sat, 10 Jan 2009) | 1 line
use variable
........
r68507 | benjamin.peterson | 2009-01-10 15:13:16 -0600 (Sat, 10 Jan 2009) | 1 line
rewrap
........
r68694 | benjamin.peterson | 2009-01-17 17:55:59 -0600 (Sat, 17 Jan 2009) | 1 line
test for specific node type
........
r69054 | guilherme.polo | 2009-01-28 10:01:54 -0600 (Wed, 28 Jan 2009) | 2 lines
Added mapping for the ttk module.
........
r69673 | benjamin.peterson | 2009-02-16 09:38:22 -0600 (Mon, 16 Feb 2009) | 1 line
fix handling of as imports #5279
........
r69679 | benjamin.peterson | 2009-02-16 11:36:06 -0600 (Mon, 16 Feb 2009) | 1 line
make Base.get_next_sibling() and Base.get_prev_sibling() properties
........
r69680 | benjamin.peterson | 2009-02-16 11:41:48 -0600 (Mon, 16 Feb 2009) | 1 line
normalize docstrings in pytree according to PEP 11
........
r69681 | benjamin.peterson | 2009-02-16 11:43:09 -0600 (Mon, 16 Feb 2009) | 1 line
use a set
........
r70991 | benjamin.peterson | 2009-04-01 15:54:50 -0500 (Wed, 01 Apr 2009) | 1 line
map urllib.urlopen to urllib.request.open #5637
........
r70999 | benjamin.peterson | 2009-04-01 17:36:47 -0500 (Wed, 01 Apr 2009) | 1 line
add very alpha support to 2to3 for running concurrently with multiprocessing
........
r71003 | benjamin.peterson | 2009-04-01 18:10:43 -0500 (Wed, 01 Apr 2009) | 1 line
fix when multiprocessing is not available or used
........
r71695 | benjamin.peterson | 2009-04-17 22:21:29 -0500 (Fri, 17 Apr 2009) | 1 line
refactor multiprocessing support, so it's less hacky to employ and only loads mp when needed
........
................
2009-05-05 20:23:31 -03:00
|
|
|
b = "from itertools import izip as _zip, imap, bar"
|
|
|
|
a = "from itertools import bar"
|
|
|
|
self.check(b, a)
|
|
|
|
|
|
|
|
b = "from itertools import imap as _map"
|
|
|
|
a = ""
|
|
|
|
self.check(b, a)
|
|
|
|
|
|
|
|
b = "from itertools import imap as _map, izip as _zip"
|
|
|
|
a = ""
|
|
|
|
self.check(b, a)
|
|
|
|
|
Merged revisions 61724-61725 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk
................
r61724 | martin.v.loewis | 2008-03-22 01:01:12 +0100 (Sa, 22 Mär 2008) | 49 lines
Merged revisions 61602-61723 via svnmerge from
svn+ssh://pythondev@svn.python.org/sandbox/trunk/2to3/lib2to3
........
r61626 | david.wolever | 2008-03-19 17:19:16 +0100 (Mi, 19 Mär 2008) | 1 line
Added fixer for implicit local imports. See #2414.
........
r61628 | david.wolever | 2008-03-19 17:57:43 +0100 (Mi, 19 Mär 2008) | 1 line
Added a class for tests which should not run if a particular import is found.
........
r61629 | collin.winter | 2008-03-19 17:58:19 +0100 (Mi, 19 Mär 2008) | 1 line
Two more relative import fixes in pgen2.
........
r61635 | david.wolever | 2008-03-19 20:16:03 +0100 (Mi, 19 Mär 2008) | 1 line
Fixed print fixer so it will do the Right Thing when it encounters __future__.print_function. 2to3 gets upset, though, so the tests have been commented out.
........
r61637 | david.wolever | 2008-03-19 21:37:17 +0100 (Mi, 19 Mär 2008) | 3 lines
Added a fixer for itertools imports (from itertools import imap, ifilterfalse --> from itertools import filterfalse)
........
r61645 | david.wolever | 2008-03-19 23:22:35 +0100 (Mi, 19 Mär 2008) | 1 line
SVN is happier when you add the files you create... -_-'
........
r61654 | david.wolever | 2008-03-20 01:09:56 +0100 (Do, 20 Mär 2008) | 1 line
Added an explicit sort order to fixers -- fixes problems like #2427
........
r61664 | david.wolever | 2008-03-20 04:32:40 +0100 (Do, 20 Mär 2008) | 3 lines
Fixes #2428 -- comments are no longer eatten by __future__ fixer.
........
r61673 | david.wolever | 2008-03-20 17:22:40 +0100 (Do, 20 Mär 2008) | 1 line
Added 2to3 node pretty-printer
........
r61679 | david.wolever | 2008-03-20 20:50:42 +0100 (Do, 20 Mär 2008) | 1 line
Made node printing a little bit prettier
........
r61723 | martin.v.loewis | 2008-03-22 00:59:27 +0100 (Sa, 22 Mär 2008) | 2 lines
Fix whitespace.
........
................
r61725 | martin.v.loewis | 2008-03-22 01:02:41 +0100 (Sa, 22 Mär 2008) | 2 lines
Install lib2to3.
................
2008-03-21 21:07:09 -03:00
|
|
|
s = "from itertools import bar as bang"
|
|
|
|
self.unchanged(s)
|
|
|
|
|
|
|
|
def test_ifilter(self):
|
|
|
|
b = "from itertools import ifilterfalse"
|
|
|
|
a = "from itertools import filterfalse"
|
|
|
|
self.check(b, a)
|
|
|
|
|
|
|
|
b = "from itertools import imap, ifilterfalse, foo"
|
|
|
|
a = "from itertools import filterfalse, foo"
|
|
|
|
self.check(b, a)
|
|
|
|
|
|
|
|
b = "from itertools import bar, ifilterfalse, foo"
|
|
|
|
a = "from itertools import bar, filterfalse, foo"
|
|
|
|
self.check(b, a)
|
|
|
|
|
|
|
|
|
|
|
|
def test_unchanged(self):
|
|
|
|
s = "from itertools import foo"
|
|
|
|
self.unchanged(s)
|
|
|
|
|
2009-07-21 09:55:57 -03:00
|
|
|
|
Merged revisions 61724-61725 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk
................
r61724 | martin.v.loewis | 2008-03-22 01:01:12 +0100 (Sa, 22 Mär 2008) | 49 lines
Merged revisions 61602-61723 via svnmerge from
svn+ssh://pythondev@svn.python.org/sandbox/trunk/2to3/lib2to3
........
r61626 | david.wolever | 2008-03-19 17:19:16 +0100 (Mi, 19 Mär 2008) | 1 line
Added fixer for implicit local imports. See #2414.
........
r61628 | david.wolever | 2008-03-19 17:57:43 +0100 (Mi, 19 Mär 2008) | 1 line
Added a class for tests which should not run if a particular import is found.
........
r61629 | collin.winter | 2008-03-19 17:58:19 +0100 (Mi, 19 Mär 2008) | 1 line
Two more relative import fixes in pgen2.
........
r61635 | david.wolever | 2008-03-19 20:16:03 +0100 (Mi, 19 Mär 2008) | 1 line
Fixed print fixer so it will do the Right Thing when it encounters __future__.print_function. 2to3 gets upset, though, so the tests have been commented out.
........
r61637 | david.wolever | 2008-03-19 21:37:17 +0100 (Mi, 19 Mär 2008) | 3 lines
Added a fixer for itertools imports (from itertools import imap, ifilterfalse --> from itertools import filterfalse)
........
r61645 | david.wolever | 2008-03-19 23:22:35 +0100 (Mi, 19 Mär 2008) | 1 line
SVN is happier when you add the files you create... -_-'
........
r61654 | david.wolever | 2008-03-20 01:09:56 +0100 (Do, 20 Mär 2008) | 1 line
Added an explicit sort order to fixers -- fixes problems like #2427
........
r61664 | david.wolever | 2008-03-20 04:32:40 +0100 (Do, 20 Mär 2008) | 3 lines
Fixes #2428 -- comments are no longer eatten by __future__ fixer.
........
r61673 | david.wolever | 2008-03-20 17:22:40 +0100 (Do, 20 Mär 2008) | 1 line
Added 2to3 node pretty-printer
........
r61679 | david.wolever | 2008-03-20 20:50:42 +0100 (Do, 20 Mär 2008) | 1 line
Made node printing a little bit prettier
........
r61723 | martin.v.loewis | 2008-03-22 00:59:27 +0100 (Sa, 22 Mär 2008) | 2 lines
Fix whitespace.
........
................
r61725 | martin.v.loewis | 2008-03-22 01:02:41 +0100 (Sa, 22 Mär 2008) | 2 lines
Install lib2to3.
................
2008-03-21 21:07:09 -03:00
|
|
|
class Test_import(FixerTestCase):
|
|
|
|
fixer = "import"
|
|
|
|
|
|
|
|
def setUp(self):
|
2008-11-24 23:08:21 -04:00
|
|
|
super(Test_import, self).setUp()
|
Merged revisions 61440-61441,61443,61445-61448,61451-61452,61455-61457,61459-61464,61466-61467,61469-61470,61476-61477,61479,61481-61482,61485,61487,61490,61493-61494,61497,61499-61502,61505-61506,61508,61511-61514,61519,61521-61522,61530-61531,61533-61537,61541-61555,61557-61558,61561-61562,61566-61569,61572-61574,61578-61579,61583-61584,61588-61589,61592,61594,61598-61601,61603-61604,61607-61612,61617,61619-61620,61624,61626,61628-61630,61635-61638,61640-61643,61645,61648,61653-61655,61659-61662,61664,61666,61668-61671,61673,61675,61679-61680,61682,61685-61686,61689-61695,61697-61699,61701-61703,61706,61710,61713,61717,61723,61726-61730,61736,61738,61740,61742,61745-61752,61754-61760,61762-61764,61768,61770-61772,61774-61775,61784-61787,61789-61792,61794-61795,61797-61806,61808-61809,61811-61812,61814-61819,61824,61826-61833,61835-61840,61843-61845,61848,61850,61854-61862,61865-61866,61868,61872-61873,61876-61877,61883-61888,61890-61891,61893-61899,61901-61903,61905-61912,61914,61917,61920-61921,61927,61930,61932-61934,61939,61941-61942,61944-61951,61955,61960-61963,61980,61982-61983,61991,61994-61996,62001-62003,62008-62010,62016-62017,62022,62024,62027,62031-62034,62041,62045-62046,62055-62058,62060-62066,62068-62074,62076-62085 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk
................
r62080 | martin.v.loewis | 2008-03-31 07:20:55 +0200 (Mo, 31 Mär 2008) | 9 lines
Merged revisions 61990-62079 via svnmerge from
svn+ssh://pythondev@svn.python.org/sandbox/trunk/2to3/lib2to3
........
r62017 | david.wolever | 2008-03-28 21:54:37 +0100 (Fr, 28 Mär 2008) | 1 line
Fixed an out-of-date comment.
........
................
r62084 | benjamin.peterson | 2008-03-31 23:57:13 +0200 (Mo, 31 Mär 2008) | 2 lines
PyErr_Warn is decrepated. Use PyErr_WarnEx
................
r62085 | neal.norwitz | 2008-04-01 07:40:43 +0200 (Di, 01 Apr 2008) | 4 lines
Be sure to close the file. 2 places were deleting the file, so it was probably
fine, but the last change may be required for the test to pass on Windows.
Should we always close the mmap too?
................
2008-04-01 03:17:46 -03:00
|
|
|
# Need to replace fix_import's exists method
|
Merged revisions 61724-61725 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk
................
r61724 | martin.v.loewis | 2008-03-22 01:01:12 +0100 (Sa, 22 Mär 2008) | 49 lines
Merged revisions 61602-61723 via svnmerge from
svn+ssh://pythondev@svn.python.org/sandbox/trunk/2to3/lib2to3
........
r61626 | david.wolever | 2008-03-19 17:19:16 +0100 (Mi, 19 Mär 2008) | 1 line
Added fixer for implicit local imports. See #2414.
........
r61628 | david.wolever | 2008-03-19 17:57:43 +0100 (Mi, 19 Mär 2008) | 1 line
Added a class for tests which should not run if a particular import is found.
........
r61629 | collin.winter | 2008-03-19 17:58:19 +0100 (Mi, 19 Mär 2008) | 1 line
Two more relative import fixes in pgen2.
........
r61635 | david.wolever | 2008-03-19 20:16:03 +0100 (Mi, 19 Mär 2008) | 1 line
Fixed print fixer so it will do the Right Thing when it encounters __future__.print_function. 2to3 gets upset, though, so the tests have been commented out.
........
r61637 | david.wolever | 2008-03-19 21:37:17 +0100 (Mi, 19 Mär 2008) | 3 lines
Added a fixer for itertools imports (from itertools import imap, ifilterfalse --> from itertools import filterfalse)
........
r61645 | david.wolever | 2008-03-19 23:22:35 +0100 (Mi, 19 Mär 2008) | 1 line
SVN is happier when you add the files you create... -_-'
........
r61654 | david.wolever | 2008-03-20 01:09:56 +0100 (Do, 20 Mär 2008) | 1 line
Added an explicit sort order to fixers -- fixes problems like #2427
........
r61664 | david.wolever | 2008-03-20 04:32:40 +0100 (Do, 20 Mär 2008) | 3 lines
Fixes #2428 -- comments are no longer eatten by __future__ fixer.
........
r61673 | david.wolever | 2008-03-20 17:22:40 +0100 (Do, 20 Mär 2008) | 1 line
Added 2to3 node pretty-printer
........
r61679 | david.wolever | 2008-03-20 20:50:42 +0100 (Do, 20 Mär 2008) | 1 line
Made node printing a little bit prettier
........
r61723 | martin.v.loewis | 2008-03-22 00:59:27 +0100 (Sa, 22 Mär 2008) | 2 lines
Fix whitespace.
........
................
r61725 | martin.v.loewis | 2008-03-22 01:02:41 +0100 (Sa, 22 Mär 2008) | 2 lines
Install lib2to3.
................
2008-03-21 21:07:09 -03:00
|
|
|
# so we can check that it's doing the right thing
|
|
|
|
self.files_checked = []
|
2008-10-04 18:04:36 -03:00
|
|
|
self.present_files = set()
|
Merged revisions 61724-61725 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk
................
r61724 | martin.v.loewis | 2008-03-22 01:01:12 +0100 (Sa, 22 Mär 2008) | 49 lines
Merged revisions 61602-61723 via svnmerge from
svn+ssh://pythondev@svn.python.org/sandbox/trunk/2to3/lib2to3
........
r61626 | david.wolever | 2008-03-19 17:19:16 +0100 (Mi, 19 Mär 2008) | 1 line
Added fixer for implicit local imports. See #2414.
........
r61628 | david.wolever | 2008-03-19 17:57:43 +0100 (Mi, 19 Mär 2008) | 1 line
Added a class for tests which should not run if a particular import is found.
........
r61629 | collin.winter | 2008-03-19 17:58:19 +0100 (Mi, 19 Mär 2008) | 1 line
Two more relative import fixes in pgen2.
........
r61635 | david.wolever | 2008-03-19 20:16:03 +0100 (Mi, 19 Mär 2008) | 1 line
Fixed print fixer so it will do the Right Thing when it encounters __future__.print_function. 2to3 gets upset, though, so the tests have been commented out.
........
r61637 | david.wolever | 2008-03-19 21:37:17 +0100 (Mi, 19 Mär 2008) | 3 lines
Added a fixer for itertools imports (from itertools import imap, ifilterfalse --> from itertools import filterfalse)
........
r61645 | david.wolever | 2008-03-19 23:22:35 +0100 (Mi, 19 Mär 2008) | 1 line
SVN is happier when you add the files you create... -_-'
........
r61654 | david.wolever | 2008-03-20 01:09:56 +0100 (Do, 20 Mär 2008) | 1 line
Added an explicit sort order to fixers -- fixes problems like #2427
........
r61664 | david.wolever | 2008-03-20 04:32:40 +0100 (Do, 20 Mär 2008) | 3 lines
Fixes #2428 -- comments are no longer eatten by __future__ fixer.
........
r61673 | david.wolever | 2008-03-20 17:22:40 +0100 (Do, 20 Mär 2008) | 1 line
Added 2to3 node pretty-printer
........
r61679 | david.wolever | 2008-03-20 20:50:42 +0100 (Do, 20 Mär 2008) | 1 line
Made node printing a little bit prettier
........
r61723 | martin.v.loewis | 2008-03-22 00:59:27 +0100 (Sa, 22 Mär 2008) | 2 lines
Fix whitespace.
........
................
r61725 | martin.v.loewis | 2008-03-22 01:02:41 +0100 (Sa, 22 Mär 2008) | 2 lines
Install lib2to3.
................
2008-03-21 21:07:09 -03:00
|
|
|
self.always_exists = True
|
|
|
|
def fake_exists(name):
|
|
|
|
self.files_checked.append(name)
|
2008-10-04 18:04:36 -03:00
|
|
|
return self.always_exists or (name in self.present_files)
|
Merged revisions 61724-61725 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk
................
r61724 | martin.v.loewis | 2008-03-22 01:01:12 +0100 (Sa, 22 Mär 2008) | 49 lines
Merged revisions 61602-61723 via svnmerge from
svn+ssh://pythondev@svn.python.org/sandbox/trunk/2to3/lib2to3
........
r61626 | david.wolever | 2008-03-19 17:19:16 +0100 (Mi, 19 Mär 2008) | 1 line
Added fixer for implicit local imports. See #2414.
........
r61628 | david.wolever | 2008-03-19 17:57:43 +0100 (Mi, 19 Mär 2008) | 1 line
Added a class for tests which should not run if a particular import is found.
........
r61629 | collin.winter | 2008-03-19 17:58:19 +0100 (Mi, 19 Mär 2008) | 1 line
Two more relative import fixes in pgen2.
........
r61635 | david.wolever | 2008-03-19 20:16:03 +0100 (Mi, 19 Mär 2008) | 1 line
Fixed print fixer so it will do the Right Thing when it encounters __future__.print_function. 2to3 gets upset, though, so the tests have been commented out.
........
r61637 | david.wolever | 2008-03-19 21:37:17 +0100 (Mi, 19 Mär 2008) | 3 lines
Added a fixer for itertools imports (from itertools import imap, ifilterfalse --> from itertools import filterfalse)
........
r61645 | david.wolever | 2008-03-19 23:22:35 +0100 (Mi, 19 Mär 2008) | 1 line
SVN is happier when you add the files you create... -_-'
........
r61654 | david.wolever | 2008-03-20 01:09:56 +0100 (Do, 20 Mär 2008) | 1 line
Added an explicit sort order to fixers -- fixes problems like #2427
........
r61664 | david.wolever | 2008-03-20 04:32:40 +0100 (Do, 20 Mär 2008) | 3 lines
Fixes #2428 -- comments are no longer eatten by __future__ fixer.
........
r61673 | david.wolever | 2008-03-20 17:22:40 +0100 (Do, 20 Mär 2008) | 1 line
Added 2to3 node pretty-printer
........
r61679 | david.wolever | 2008-03-20 20:50:42 +0100 (Do, 20 Mär 2008) | 1 line
Made node printing a little bit prettier
........
r61723 | martin.v.loewis | 2008-03-22 00:59:27 +0100 (Sa, 22 Mär 2008) | 2 lines
Fix whitespace.
........
................
r61725 | martin.v.loewis | 2008-03-22 01:02:41 +0100 (Sa, 22 Mär 2008) | 2 lines
Install lib2to3.
................
2008-03-21 21:07:09 -03:00
|
|
|
|
|
|
|
from ..fixes import fix_import
|
|
|
|
fix_import.exists = fake_exists
|
|
|
|
|
2008-10-04 18:04:36 -03:00
|
|
|
def tearDown(self):
|
|
|
|
from lib2to3.fixes import fix_import
|
|
|
|
fix_import.exists = os.path.exists
|
|
|
|
|
Merged revisions 61724-61725 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk
................
r61724 | martin.v.loewis | 2008-03-22 01:01:12 +0100 (Sa, 22 Mär 2008) | 49 lines
Merged revisions 61602-61723 via svnmerge from
svn+ssh://pythondev@svn.python.org/sandbox/trunk/2to3/lib2to3
........
r61626 | david.wolever | 2008-03-19 17:19:16 +0100 (Mi, 19 Mär 2008) | 1 line
Added fixer for implicit local imports. See #2414.
........
r61628 | david.wolever | 2008-03-19 17:57:43 +0100 (Mi, 19 Mär 2008) | 1 line
Added a class for tests which should not run if a particular import is found.
........
r61629 | collin.winter | 2008-03-19 17:58:19 +0100 (Mi, 19 Mär 2008) | 1 line
Two more relative import fixes in pgen2.
........
r61635 | david.wolever | 2008-03-19 20:16:03 +0100 (Mi, 19 Mär 2008) | 1 line
Fixed print fixer so it will do the Right Thing when it encounters __future__.print_function. 2to3 gets upset, though, so the tests have been commented out.
........
r61637 | david.wolever | 2008-03-19 21:37:17 +0100 (Mi, 19 Mär 2008) | 3 lines
Added a fixer for itertools imports (from itertools import imap, ifilterfalse --> from itertools import filterfalse)
........
r61645 | david.wolever | 2008-03-19 23:22:35 +0100 (Mi, 19 Mär 2008) | 1 line
SVN is happier when you add the files you create... -_-'
........
r61654 | david.wolever | 2008-03-20 01:09:56 +0100 (Do, 20 Mär 2008) | 1 line
Added an explicit sort order to fixers -- fixes problems like #2427
........
r61664 | david.wolever | 2008-03-20 04:32:40 +0100 (Do, 20 Mär 2008) | 3 lines
Fixes #2428 -- comments are no longer eatten by __future__ fixer.
........
r61673 | david.wolever | 2008-03-20 17:22:40 +0100 (Do, 20 Mär 2008) | 1 line
Added 2to3 node pretty-printer
........
r61679 | david.wolever | 2008-03-20 20:50:42 +0100 (Do, 20 Mär 2008) | 1 line
Made node printing a little bit prettier
........
r61723 | martin.v.loewis | 2008-03-22 00:59:27 +0100 (Sa, 22 Mär 2008) | 2 lines
Fix whitespace.
........
................
r61725 | martin.v.loewis | 2008-03-22 01:02:41 +0100 (Sa, 22 Mär 2008) | 2 lines
Install lib2to3.
................
2008-03-21 21:07:09 -03:00
|
|
|
def check_both(self, b, a):
|
|
|
|
self.always_exists = True
|
2008-11-24 23:08:21 -04:00
|
|
|
super(Test_import, self).check(b, a)
|
Merged revisions 61724-61725 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk
................
r61724 | martin.v.loewis | 2008-03-22 01:01:12 +0100 (Sa, 22 Mär 2008) | 49 lines
Merged revisions 61602-61723 via svnmerge from
svn+ssh://pythondev@svn.python.org/sandbox/trunk/2to3/lib2to3
........
r61626 | david.wolever | 2008-03-19 17:19:16 +0100 (Mi, 19 Mär 2008) | 1 line
Added fixer for implicit local imports. See #2414.
........
r61628 | david.wolever | 2008-03-19 17:57:43 +0100 (Mi, 19 Mär 2008) | 1 line
Added a class for tests which should not run if a particular import is found.
........
r61629 | collin.winter | 2008-03-19 17:58:19 +0100 (Mi, 19 Mär 2008) | 1 line
Two more relative import fixes in pgen2.
........
r61635 | david.wolever | 2008-03-19 20:16:03 +0100 (Mi, 19 Mär 2008) | 1 line
Fixed print fixer so it will do the Right Thing when it encounters __future__.print_function. 2to3 gets upset, though, so the tests have been commented out.
........
r61637 | david.wolever | 2008-03-19 21:37:17 +0100 (Mi, 19 Mär 2008) | 3 lines
Added a fixer for itertools imports (from itertools import imap, ifilterfalse --> from itertools import filterfalse)
........
r61645 | david.wolever | 2008-03-19 23:22:35 +0100 (Mi, 19 Mär 2008) | 1 line
SVN is happier when you add the files you create... -_-'
........
r61654 | david.wolever | 2008-03-20 01:09:56 +0100 (Do, 20 Mär 2008) | 1 line
Added an explicit sort order to fixers -- fixes problems like #2427
........
r61664 | david.wolever | 2008-03-20 04:32:40 +0100 (Do, 20 Mär 2008) | 3 lines
Fixes #2428 -- comments are no longer eatten by __future__ fixer.
........
r61673 | david.wolever | 2008-03-20 17:22:40 +0100 (Do, 20 Mär 2008) | 1 line
Added 2to3 node pretty-printer
........
r61679 | david.wolever | 2008-03-20 20:50:42 +0100 (Do, 20 Mär 2008) | 1 line
Made node printing a little bit prettier
........
r61723 | martin.v.loewis | 2008-03-22 00:59:27 +0100 (Sa, 22 Mär 2008) | 2 lines
Fix whitespace.
........
................
r61725 | martin.v.loewis | 2008-03-22 01:02:41 +0100 (Sa, 22 Mär 2008) | 2 lines
Install lib2to3.
................
2008-03-21 21:07:09 -03:00
|
|
|
self.always_exists = False
|
2008-11-24 23:08:21 -04:00
|
|
|
super(Test_import, self).unchanged(b)
|
Merged revisions 61724-61725 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk
................
r61724 | martin.v.loewis | 2008-03-22 01:01:12 +0100 (Sa, 22 Mär 2008) | 49 lines
Merged revisions 61602-61723 via svnmerge from
svn+ssh://pythondev@svn.python.org/sandbox/trunk/2to3/lib2to3
........
r61626 | david.wolever | 2008-03-19 17:19:16 +0100 (Mi, 19 Mär 2008) | 1 line
Added fixer for implicit local imports. See #2414.
........
r61628 | david.wolever | 2008-03-19 17:57:43 +0100 (Mi, 19 Mär 2008) | 1 line
Added a class for tests which should not run if a particular import is found.
........
r61629 | collin.winter | 2008-03-19 17:58:19 +0100 (Mi, 19 Mär 2008) | 1 line
Two more relative import fixes in pgen2.
........
r61635 | david.wolever | 2008-03-19 20:16:03 +0100 (Mi, 19 Mär 2008) | 1 line
Fixed print fixer so it will do the Right Thing when it encounters __future__.print_function. 2to3 gets upset, though, so the tests have been commented out.
........
r61637 | david.wolever | 2008-03-19 21:37:17 +0100 (Mi, 19 Mär 2008) | 3 lines
Added a fixer for itertools imports (from itertools import imap, ifilterfalse --> from itertools import filterfalse)
........
r61645 | david.wolever | 2008-03-19 23:22:35 +0100 (Mi, 19 Mär 2008) | 1 line
SVN is happier when you add the files you create... -_-'
........
r61654 | david.wolever | 2008-03-20 01:09:56 +0100 (Do, 20 Mär 2008) | 1 line
Added an explicit sort order to fixers -- fixes problems like #2427
........
r61664 | david.wolever | 2008-03-20 04:32:40 +0100 (Do, 20 Mär 2008) | 3 lines
Fixes #2428 -- comments are no longer eatten by __future__ fixer.
........
r61673 | david.wolever | 2008-03-20 17:22:40 +0100 (Do, 20 Mär 2008) | 1 line
Added 2to3 node pretty-printer
........
r61679 | david.wolever | 2008-03-20 20:50:42 +0100 (Do, 20 Mär 2008) | 1 line
Made node printing a little bit prettier
........
r61723 | martin.v.loewis | 2008-03-22 00:59:27 +0100 (Sa, 22 Mär 2008) | 2 lines
Fix whitespace.
........
................
r61725 | martin.v.loewis | 2008-03-22 01:02:41 +0100 (Sa, 22 Mär 2008) | 2 lines
Install lib2to3.
................
2008-03-21 21:07:09 -03:00
|
|
|
|
|
|
|
def test_files_checked(self):
|
|
|
|
def p(path):
|
|
|
|
# Takes a unix path and returns a path with correct separators
|
2008-10-04 18:04:36 -03:00
|
|
|
return os.path.pathsep.join(path.split("/"))
|
Merged revisions 61724-61725 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk
................
r61724 | martin.v.loewis | 2008-03-22 01:01:12 +0100 (Sa, 22 Mär 2008) | 49 lines
Merged revisions 61602-61723 via svnmerge from
svn+ssh://pythondev@svn.python.org/sandbox/trunk/2to3/lib2to3
........
r61626 | david.wolever | 2008-03-19 17:19:16 +0100 (Mi, 19 Mär 2008) | 1 line
Added fixer for implicit local imports. See #2414.
........
r61628 | david.wolever | 2008-03-19 17:57:43 +0100 (Mi, 19 Mär 2008) | 1 line
Added a class for tests which should not run if a particular import is found.
........
r61629 | collin.winter | 2008-03-19 17:58:19 +0100 (Mi, 19 Mär 2008) | 1 line
Two more relative import fixes in pgen2.
........
r61635 | david.wolever | 2008-03-19 20:16:03 +0100 (Mi, 19 Mär 2008) | 1 line
Fixed print fixer so it will do the Right Thing when it encounters __future__.print_function. 2to3 gets upset, though, so the tests have been commented out.
........
r61637 | david.wolever | 2008-03-19 21:37:17 +0100 (Mi, 19 Mär 2008) | 3 lines
Added a fixer for itertools imports (from itertools import imap, ifilterfalse --> from itertools import filterfalse)
........
r61645 | david.wolever | 2008-03-19 23:22:35 +0100 (Mi, 19 Mär 2008) | 1 line
SVN is happier when you add the files you create... -_-'
........
r61654 | david.wolever | 2008-03-20 01:09:56 +0100 (Do, 20 Mär 2008) | 1 line
Added an explicit sort order to fixers -- fixes problems like #2427
........
r61664 | david.wolever | 2008-03-20 04:32:40 +0100 (Do, 20 Mär 2008) | 3 lines
Fixes #2428 -- comments are no longer eatten by __future__ fixer.
........
r61673 | david.wolever | 2008-03-20 17:22:40 +0100 (Do, 20 Mär 2008) | 1 line
Added 2to3 node pretty-printer
........
r61679 | david.wolever | 2008-03-20 20:50:42 +0100 (Do, 20 Mär 2008) | 1 line
Made node printing a little bit prettier
........
r61723 | martin.v.loewis | 2008-03-22 00:59:27 +0100 (Sa, 22 Mär 2008) | 2 lines
Fix whitespace.
........
................
r61725 | martin.v.loewis | 2008-03-22 01:02:41 +0100 (Sa, 22 Mär 2008) | 2 lines
Install lib2to3.
................
2008-03-21 21:07:09 -03:00
|
|
|
|
|
|
|
self.always_exists = False
|
2008-10-04 18:04:36 -03:00
|
|
|
self.present_files = set(['__init__.py'])
|
2009-07-21 09:55:57 -03:00
|
|
|
expected_extensions = ('.py', os.path.sep, '.pyc', '.so', '.sl', '.pyd')
|
Merged revisions 61724-61725 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk
................
r61724 | martin.v.loewis | 2008-03-22 01:01:12 +0100 (Sa, 22 Mär 2008) | 49 lines
Merged revisions 61602-61723 via svnmerge from
svn+ssh://pythondev@svn.python.org/sandbox/trunk/2to3/lib2to3
........
r61626 | david.wolever | 2008-03-19 17:19:16 +0100 (Mi, 19 Mär 2008) | 1 line
Added fixer for implicit local imports. See #2414.
........
r61628 | david.wolever | 2008-03-19 17:57:43 +0100 (Mi, 19 Mär 2008) | 1 line
Added a class for tests which should not run if a particular import is found.
........
r61629 | collin.winter | 2008-03-19 17:58:19 +0100 (Mi, 19 Mär 2008) | 1 line
Two more relative import fixes in pgen2.
........
r61635 | david.wolever | 2008-03-19 20:16:03 +0100 (Mi, 19 Mär 2008) | 1 line
Fixed print fixer so it will do the Right Thing when it encounters __future__.print_function. 2to3 gets upset, though, so the tests have been commented out.
........
r61637 | david.wolever | 2008-03-19 21:37:17 +0100 (Mi, 19 Mär 2008) | 3 lines
Added a fixer for itertools imports (from itertools import imap, ifilterfalse --> from itertools import filterfalse)
........
r61645 | david.wolever | 2008-03-19 23:22:35 +0100 (Mi, 19 Mär 2008) | 1 line
SVN is happier when you add the files you create... -_-'
........
r61654 | david.wolever | 2008-03-20 01:09:56 +0100 (Do, 20 Mär 2008) | 1 line
Added an explicit sort order to fixers -- fixes problems like #2427
........
r61664 | david.wolever | 2008-03-20 04:32:40 +0100 (Do, 20 Mär 2008) | 3 lines
Fixes #2428 -- comments are no longer eatten by __future__ fixer.
........
r61673 | david.wolever | 2008-03-20 17:22:40 +0100 (Do, 20 Mär 2008) | 1 line
Added 2to3 node pretty-printer
........
r61679 | david.wolever | 2008-03-20 20:50:42 +0100 (Do, 20 Mär 2008) | 1 line
Made node printing a little bit prettier
........
r61723 | martin.v.loewis | 2008-03-22 00:59:27 +0100 (Sa, 22 Mär 2008) | 2 lines
Fix whitespace.
........
................
r61725 | martin.v.loewis | 2008-03-22 01:02:41 +0100 (Sa, 22 Mär 2008) | 2 lines
Install lib2to3.
................
2008-03-21 21:07:09 -03:00
|
|
|
names_to_test = (p("/spam/eggs.py"), "ni.py", p("../../shrubbery.py"))
|
|
|
|
|
|
|
|
for name in names_to_test:
|
|
|
|
self.files_checked = []
|
|
|
|
self.filename = name
|
|
|
|
self.unchanged("import jam")
|
|
|
|
|
2008-10-04 18:04:36 -03:00
|
|
|
if os.path.dirname(name):
|
|
|
|
name = os.path.dirname(name) + '/jam'
|
|
|
|
else:
|
|
|
|
name = 'jam'
|
Merged revisions 61724-61725 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk
................
r61724 | martin.v.loewis | 2008-03-22 01:01:12 +0100 (Sa, 22 Mär 2008) | 49 lines
Merged revisions 61602-61723 via svnmerge from
svn+ssh://pythondev@svn.python.org/sandbox/trunk/2to3/lib2to3
........
r61626 | david.wolever | 2008-03-19 17:19:16 +0100 (Mi, 19 Mär 2008) | 1 line
Added fixer for implicit local imports. See #2414.
........
r61628 | david.wolever | 2008-03-19 17:57:43 +0100 (Mi, 19 Mär 2008) | 1 line
Added a class for tests which should not run if a particular import is found.
........
r61629 | collin.winter | 2008-03-19 17:58:19 +0100 (Mi, 19 Mär 2008) | 1 line
Two more relative import fixes in pgen2.
........
r61635 | david.wolever | 2008-03-19 20:16:03 +0100 (Mi, 19 Mär 2008) | 1 line
Fixed print fixer so it will do the Right Thing when it encounters __future__.print_function. 2to3 gets upset, though, so the tests have been commented out.
........
r61637 | david.wolever | 2008-03-19 21:37:17 +0100 (Mi, 19 Mär 2008) | 3 lines
Added a fixer for itertools imports (from itertools import imap, ifilterfalse --> from itertools import filterfalse)
........
r61645 | david.wolever | 2008-03-19 23:22:35 +0100 (Mi, 19 Mär 2008) | 1 line
SVN is happier when you add the files you create... -_-'
........
r61654 | david.wolever | 2008-03-20 01:09:56 +0100 (Do, 20 Mär 2008) | 1 line
Added an explicit sort order to fixers -- fixes problems like #2427
........
r61664 | david.wolever | 2008-03-20 04:32:40 +0100 (Do, 20 Mär 2008) | 3 lines
Fixes #2428 -- comments are no longer eatten by __future__ fixer.
........
r61673 | david.wolever | 2008-03-20 17:22:40 +0100 (Do, 20 Mär 2008) | 1 line
Added 2to3 node pretty-printer
........
r61679 | david.wolever | 2008-03-20 20:50:42 +0100 (Do, 20 Mär 2008) | 1 line
Made node printing a little bit prettier
........
r61723 | martin.v.loewis | 2008-03-22 00:59:27 +0100 (Sa, 22 Mär 2008) | 2 lines
Fix whitespace.
........
................
r61725 | martin.v.loewis | 2008-03-22 01:02:41 +0100 (Sa, 22 Mär 2008) | 2 lines
Install lib2to3.
................
2008-03-21 21:07:09 -03:00
|
|
|
expected_checks = set(name + ext for ext in expected_extensions)
|
2008-10-04 18:04:36 -03:00
|
|
|
expected_checks.add("__init__.py")
|
|
|
|
|
|
|
|
self.assertEqual(set(self.files_checked), expected_checks)
|
Merged revisions 61724-61725 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk
................
r61724 | martin.v.loewis | 2008-03-22 01:01:12 +0100 (Sa, 22 Mär 2008) | 49 lines
Merged revisions 61602-61723 via svnmerge from
svn+ssh://pythondev@svn.python.org/sandbox/trunk/2to3/lib2to3
........
r61626 | david.wolever | 2008-03-19 17:19:16 +0100 (Mi, 19 Mär 2008) | 1 line
Added fixer for implicit local imports. See #2414.
........
r61628 | david.wolever | 2008-03-19 17:57:43 +0100 (Mi, 19 Mär 2008) | 1 line
Added a class for tests which should not run if a particular import is found.
........
r61629 | collin.winter | 2008-03-19 17:58:19 +0100 (Mi, 19 Mär 2008) | 1 line
Two more relative import fixes in pgen2.
........
r61635 | david.wolever | 2008-03-19 20:16:03 +0100 (Mi, 19 Mär 2008) | 1 line
Fixed print fixer so it will do the Right Thing when it encounters __future__.print_function. 2to3 gets upset, though, so the tests have been commented out.
........
r61637 | david.wolever | 2008-03-19 21:37:17 +0100 (Mi, 19 Mär 2008) | 3 lines
Added a fixer for itertools imports (from itertools import imap, ifilterfalse --> from itertools import filterfalse)
........
r61645 | david.wolever | 2008-03-19 23:22:35 +0100 (Mi, 19 Mär 2008) | 1 line
SVN is happier when you add the files you create... -_-'
........
r61654 | david.wolever | 2008-03-20 01:09:56 +0100 (Do, 20 Mär 2008) | 1 line
Added an explicit sort order to fixers -- fixes problems like #2427
........
r61664 | david.wolever | 2008-03-20 04:32:40 +0100 (Do, 20 Mär 2008) | 3 lines
Fixes #2428 -- comments are no longer eatten by __future__ fixer.
........
r61673 | david.wolever | 2008-03-20 17:22:40 +0100 (Do, 20 Mär 2008) | 1 line
Added 2to3 node pretty-printer
........
r61679 | david.wolever | 2008-03-20 20:50:42 +0100 (Do, 20 Mär 2008) | 1 line
Made node printing a little bit prettier
........
r61723 | martin.v.loewis | 2008-03-22 00:59:27 +0100 (Sa, 22 Mär 2008) | 2 lines
Fix whitespace.
........
................
r61725 | martin.v.loewis | 2008-03-22 01:02:41 +0100 (Sa, 22 Mär 2008) | 2 lines
Install lib2to3.
................
2008-03-21 21:07:09 -03:00
|
|
|
|
2008-10-04 18:04:36 -03:00
|
|
|
def test_not_in_package(self):
|
|
|
|
s = "import bar"
|
|
|
|
self.always_exists = False
|
|
|
|
self.present_files = set(["bar.py"])
|
|
|
|
self.unchanged(s)
|
|
|
|
|
|
|
|
def test_in_package(self):
|
|
|
|
b = "import bar"
|
|
|
|
a = "from . import bar"
|
|
|
|
self.always_exists = False
|
|
|
|
self.present_files = set(["__init__.py", "bar.py"])
|
|
|
|
self.check(b, a)
|
|
|
|
|
2009-07-21 09:55:57 -03:00
|
|
|
def test_import_from_package(self):
|
|
|
|
b = "import bar"
|
|
|
|
a = "from . import bar"
|
|
|
|
self.always_exists = False
|
2009-07-21 10:13:16 -03:00
|
|
|
self.present_files = set(["__init__.py", "bar" + os.path.sep])
|
2009-07-21 09:55:57 -03:00
|
|
|
self.check(b, a)
|
|
|
|
|
2008-10-04 18:04:36 -03:00
|
|
|
def test_comments_and_indent(self):
|
|
|
|
b = "import bar # Foo"
|
|
|
|
a = "from . import bar # Foo"
|
|
|
|
self.check(b, a)
|
Merged revisions 61724-61725 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk
................
r61724 | martin.v.loewis | 2008-03-22 01:01:12 +0100 (Sa, 22 Mär 2008) | 49 lines
Merged revisions 61602-61723 via svnmerge from
svn+ssh://pythondev@svn.python.org/sandbox/trunk/2to3/lib2to3
........
r61626 | david.wolever | 2008-03-19 17:19:16 +0100 (Mi, 19 Mär 2008) | 1 line
Added fixer for implicit local imports. See #2414.
........
r61628 | david.wolever | 2008-03-19 17:57:43 +0100 (Mi, 19 Mär 2008) | 1 line
Added a class for tests which should not run if a particular import is found.
........
r61629 | collin.winter | 2008-03-19 17:58:19 +0100 (Mi, 19 Mär 2008) | 1 line
Two more relative import fixes in pgen2.
........
r61635 | david.wolever | 2008-03-19 20:16:03 +0100 (Mi, 19 Mär 2008) | 1 line
Fixed print fixer so it will do the Right Thing when it encounters __future__.print_function. 2to3 gets upset, though, so the tests have been commented out.
........
r61637 | david.wolever | 2008-03-19 21:37:17 +0100 (Mi, 19 Mär 2008) | 3 lines
Added a fixer for itertools imports (from itertools import imap, ifilterfalse --> from itertools import filterfalse)
........
r61645 | david.wolever | 2008-03-19 23:22:35 +0100 (Mi, 19 Mär 2008) | 1 line
SVN is happier when you add the files you create... -_-'
........
r61654 | david.wolever | 2008-03-20 01:09:56 +0100 (Do, 20 Mär 2008) | 1 line
Added an explicit sort order to fixers -- fixes problems like #2427
........
r61664 | david.wolever | 2008-03-20 04:32:40 +0100 (Do, 20 Mär 2008) | 3 lines
Fixes #2428 -- comments are no longer eatten by __future__ fixer.
........
r61673 | david.wolever | 2008-03-20 17:22:40 +0100 (Do, 20 Mär 2008) | 1 line
Added 2to3 node pretty-printer
........
r61679 | david.wolever | 2008-03-20 20:50:42 +0100 (Do, 20 Mär 2008) | 1 line
Made node printing a little bit prettier
........
r61723 | martin.v.loewis | 2008-03-22 00:59:27 +0100 (Sa, 22 Mär 2008) | 2 lines
Fix whitespace.
........
................
r61725 | martin.v.loewis | 2008-03-22 01:02:41 +0100 (Sa, 22 Mär 2008) | 2 lines
Install lib2to3.
................
2008-03-21 21:07:09 -03:00
|
|
|
|
|
|
|
def test_from(self):
|
2008-03-23 21:50:58 -03:00
|
|
|
b = "from foo import bar, baz"
|
|
|
|
a = "from .foo import bar, baz"
|
|
|
|
self.check_both(b, a)
|
|
|
|
|
Merged revisions 61724-61725 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk
................
r61724 | martin.v.loewis | 2008-03-22 01:01:12 +0100 (Sa, 22 Mär 2008) | 49 lines
Merged revisions 61602-61723 via svnmerge from
svn+ssh://pythondev@svn.python.org/sandbox/trunk/2to3/lib2to3
........
r61626 | david.wolever | 2008-03-19 17:19:16 +0100 (Mi, 19 Mär 2008) | 1 line
Added fixer for implicit local imports. See #2414.
........
r61628 | david.wolever | 2008-03-19 17:57:43 +0100 (Mi, 19 Mär 2008) | 1 line
Added a class for tests which should not run if a particular import is found.
........
r61629 | collin.winter | 2008-03-19 17:58:19 +0100 (Mi, 19 Mär 2008) | 1 line
Two more relative import fixes in pgen2.
........
r61635 | david.wolever | 2008-03-19 20:16:03 +0100 (Mi, 19 Mär 2008) | 1 line
Fixed print fixer so it will do the Right Thing when it encounters __future__.print_function. 2to3 gets upset, though, so the tests have been commented out.
........
r61637 | david.wolever | 2008-03-19 21:37:17 +0100 (Mi, 19 Mär 2008) | 3 lines
Added a fixer for itertools imports (from itertools import imap, ifilterfalse --> from itertools import filterfalse)
........
r61645 | david.wolever | 2008-03-19 23:22:35 +0100 (Mi, 19 Mär 2008) | 1 line
SVN is happier when you add the files you create... -_-'
........
r61654 | david.wolever | 2008-03-20 01:09:56 +0100 (Do, 20 Mär 2008) | 1 line
Added an explicit sort order to fixers -- fixes problems like #2427
........
r61664 | david.wolever | 2008-03-20 04:32:40 +0100 (Do, 20 Mär 2008) | 3 lines
Fixes #2428 -- comments are no longer eatten by __future__ fixer.
........
r61673 | david.wolever | 2008-03-20 17:22:40 +0100 (Do, 20 Mär 2008) | 1 line
Added 2to3 node pretty-printer
........
r61679 | david.wolever | 2008-03-20 20:50:42 +0100 (Do, 20 Mär 2008) | 1 line
Made node printing a little bit prettier
........
r61723 | martin.v.loewis | 2008-03-22 00:59:27 +0100 (Sa, 22 Mär 2008) | 2 lines
Fix whitespace.
........
................
r61725 | martin.v.loewis | 2008-03-22 01:02:41 +0100 (Sa, 22 Mär 2008) | 2 lines
Install lib2to3.
................
2008-03-21 21:07:09 -03:00
|
|
|
b = "from foo import bar"
|
|
|
|
a = "from .foo import bar"
|
|
|
|
self.check_both(b, a)
|
|
|
|
|
Merged revisions 67180 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk
................
r67180 | benjamin.peterson | 2008-11-10 16:11:12 -0600 (Mon, 10 Nov 2008) | 29 lines
Merged revisions 66985,67170,67173,67177-67179 via svnmerge from
svn+ssh://pythondev@svn.python.org/sandbox/trunk/2to3/lib2to3
........
r66985 | benjamin.peterson | 2008-10-20 16:43:46 -0500 (Mon, 20 Oct 2008) | 1 line
no need to use nested try, except, finally
........
r67170 | benjamin.peterson | 2008-11-08 12:28:31 -0600 (Sat, 08 Nov 2008) | 1 line
fix #4271: fix_imports didn't recognize imports with parenthesis (ie from x import (a, b))
........
r67173 | benjamin.peterson | 2008-11-08 17:42:08 -0600 (Sat, 08 Nov 2008) | 1 line
consolidate test
........
r67177 | benjamin.peterson | 2008-11-09 21:52:52 -0600 (Sun, 09 Nov 2008) | 1 line
let the metclass fixer handle complex assignments in the class body gracefully
........
r67178 | benjamin.peterson | 2008-11-10 15:26:43 -0600 (Mon, 10 Nov 2008) | 1 line
the metaclass fixers shouldn't die when bases are not a simple name
........
r67179 | benjamin.peterson | 2008-11-10 15:29:58 -0600 (Mon, 10 Nov 2008) | 1 line
allow the fix_import pattern to catch from imports with parenthesis
........
................
2008-11-10 18:21:33 -04:00
|
|
|
b = "from foo import (bar, baz)"
|
|
|
|
a = "from .foo import (bar, baz)"
|
|
|
|
self.check_both(b, a)
|
|
|
|
|
Merged revisions 61724-61725 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk
................
r61724 | martin.v.loewis | 2008-03-22 01:01:12 +0100 (Sa, 22 Mär 2008) | 49 lines
Merged revisions 61602-61723 via svnmerge from
svn+ssh://pythondev@svn.python.org/sandbox/trunk/2to3/lib2to3
........
r61626 | david.wolever | 2008-03-19 17:19:16 +0100 (Mi, 19 Mär 2008) | 1 line
Added fixer for implicit local imports. See #2414.
........
r61628 | david.wolever | 2008-03-19 17:57:43 +0100 (Mi, 19 Mär 2008) | 1 line
Added a class for tests which should not run if a particular import is found.
........
r61629 | collin.winter | 2008-03-19 17:58:19 +0100 (Mi, 19 Mär 2008) | 1 line
Two more relative import fixes in pgen2.
........
r61635 | david.wolever | 2008-03-19 20:16:03 +0100 (Mi, 19 Mär 2008) | 1 line
Fixed print fixer so it will do the Right Thing when it encounters __future__.print_function. 2to3 gets upset, though, so the tests have been commented out.
........
r61637 | david.wolever | 2008-03-19 21:37:17 +0100 (Mi, 19 Mär 2008) | 3 lines
Added a fixer for itertools imports (from itertools import imap, ifilterfalse --> from itertools import filterfalse)
........
r61645 | david.wolever | 2008-03-19 23:22:35 +0100 (Mi, 19 Mär 2008) | 1 line
SVN is happier when you add the files you create... -_-'
........
r61654 | david.wolever | 2008-03-20 01:09:56 +0100 (Do, 20 Mär 2008) | 1 line
Added an explicit sort order to fixers -- fixes problems like #2427
........
r61664 | david.wolever | 2008-03-20 04:32:40 +0100 (Do, 20 Mär 2008) | 3 lines
Fixes #2428 -- comments are no longer eatten by __future__ fixer.
........
r61673 | david.wolever | 2008-03-20 17:22:40 +0100 (Do, 20 Mär 2008) | 1 line
Added 2to3 node pretty-printer
........
r61679 | david.wolever | 2008-03-20 20:50:42 +0100 (Do, 20 Mär 2008) | 1 line
Made node printing a little bit prettier
........
r61723 | martin.v.loewis | 2008-03-22 00:59:27 +0100 (Sa, 22 Mär 2008) | 2 lines
Fix whitespace.
........
................
r61725 | martin.v.loewis | 2008-03-22 01:02:41 +0100 (Sa, 22 Mär 2008) | 2 lines
Install lib2to3.
................
2008-03-21 21:07:09 -03:00
|
|
|
def test_dotted_from(self):
|
|
|
|
b = "from green.eggs import ham"
|
|
|
|
a = "from .green.eggs import ham"
|
|
|
|
self.check_both(b, a)
|
|
|
|
|
|
|
|
def test_from_as(self):
|
|
|
|
b = "from green.eggs import ham as spam"
|
|
|
|
a = "from .green.eggs import ham as spam"
|
|
|
|
self.check_both(b, a)
|
|
|
|
|
|
|
|
def test_import(self):
|
|
|
|
b = "import foo"
|
2008-03-23 21:50:58 -03:00
|
|
|
a = "from . import foo"
|
|
|
|
self.check_both(b, a)
|
|
|
|
|
|
|
|
b = "import foo, bar"
|
|
|
|
a = "from . import foo, bar"
|
Merged revisions 61724-61725 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk
................
r61724 | martin.v.loewis | 2008-03-22 01:01:12 +0100 (Sa, 22 Mär 2008) | 49 lines
Merged revisions 61602-61723 via svnmerge from
svn+ssh://pythondev@svn.python.org/sandbox/trunk/2to3/lib2to3
........
r61626 | david.wolever | 2008-03-19 17:19:16 +0100 (Mi, 19 Mär 2008) | 1 line
Added fixer for implicit local imports. See #2414.
........
r61628 | david.wolever | 2008-03-19 17:57:43 +0100 (Mi, 19 Mär 2008) | 1 line
Added a class for tests which should not run if a particular import is found.
........
r61629 | collin.winter | 2008-03-19 17:58:19 +0100 (Mi, 19 Mär 2008) | 1 line
Two more relative import fixes in pgen2.
........
r61635 | david.wolever | 2008-03-19 20:16:03 +0100 (Mi, 19 Mär 2008) | 1 line
Fixed print fixer so it will do the Right Thing when it encounters __future__.print_function. 2to3 gets upset, though, so the tests have been commented out.
........
r61637 | david.wolever | 2008-03-19 21:37:17 +0100 (Mi, 19 Mär 2008) | 3 lines
Added a fixer for itertools imports (from itertools import imap, ifilterfalse --> from itertools import filterfalse)
........
r61645 | david.wolever | 2008-03-19 23:22:35 +0100 (Mi, 19 Mär 2008) | 1 line
SVN is happier when you add the files you create... -_-'
........
r61654 | david.wolever | 2008-03-20 01:09:56 +0100 (Do, 20 Mär 2008) | 1 line
Added an explicit sort order to fixers -- fixes problems like #2427
........
r61664 | david.wolever | 2008-03-20 04:32:40 +0100 (Do, 20 Mär 2008) | 3 lines
Fixes #2428 -- comments are no longer eatten by __future__ fixer.
........
r61673 | david.wolever | 2008-03-20 17:22:40 +0100 (Do, 20 Mär 2008) | 1 line
Added 2to3 node pretty-printer
........
r61679 | david.wolever | 2008-03-20 20:50:42 +0100 (Do, 20 Mär 2008) | 1 line
Made node printing a little bit prettier
........
r61723 | martin.v.loewis | 2008-03-22 00:59:27 +0100 (Sa, 22 Mär 2008) | 2 lines
Fix whitespace.
........
................
r61725 | martin.v.loewis | 2008-03-22 01:02:41 +0100 (Sa, 22 Mär 2008) | 2 lines
Install lib2to3.
................
2008-03-21 21:07:09 -03:00
|
|
|
self.check_both(b, a)
|
|
|
|
|
Merged revisions 68197 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk
................
r68197 | benjamin.peterson | 2009-01-03 10:34:02 -0600 (Sat, 03 Jan 2009) | 55 lines
Merged revisions 67900-67901,67919,67928,67984,67991-67993,68106-68108,68110 via svnmerge from
svn+ssh://pythondev@svn.python.org/sandbox/trunk/2to3/lib2to3
........
r67900 | benjamin.peterson | 2008-12-22 14:02:45 -0600 (Mon, 22 Dec 2008) | 4 lines
fix_execfile: wrap the open(fn).read() call in compile(), so the filename is preserved
also add unittests for the fixer
........
r67901 | benjamin.peterson | 2008-12-22 14:09:55 -0600 (Mon, 22 Dec 2008) | 1 line
remove unused import
........
r67919 | benjamin.peterson | 2008-12-23 13:12:22 -0600 (Tue, 23 Dec 2008) | 1 line
copy permission bits from the backup to the original
........
r67928 | benjamin.peterson | 2008-12-26 20:49:30 -0600 (Fri, 26 Dec 2008) | 1 line
don't be so idiot about multiple local imports in fix_import; still won't handle absolute and local imports on the same line
........
r67984 | benjamin.peterson | 2008-12-28 09:55:16 -0600 (Sun, 28 Dec 2008) | 1 line
don't need loop
........
r67991 | benjamin.peterson | 2008-12-28 14:30:26 -0600 (Sun, 28 Dec 2008) | 1 line
actually call finish_tree()
........
r67992 | benjamin.peterson | 2008-12-28 14:34:47 -0600 (Sun, 28 Dec 2008) | 1 line
remove useless test
........
r67993 | benjamin.peterson | 2008-12-28 15:04:32 -0600 (Sun, 28 Dec 2008) | 1 line
update pyk3's test grammar
........
r68106 | benjamin.peterson | 2008-12-31 11:53:58 -0600 (Wed, 31 Dec 2008) | 1 line
#2734 don't convert every instance of long (eg if it's an attribute)
........
r68107 | benjamin.peterson | 2008-12-31 11:55:10 -0600 (Wed, 31 Dec 2008) | 1 line
add another test
........
r68108 | benjamin.peterson | 2008-12-31 12:00:12 -0600 (Wed, 31 Dec 2008) | 1 line
don't change long even if it's the only argument name
........
r68110 | benjamin.peterson | 2008-12-31 14:13:26 -0600 (Wed, 31 Dec 2008) | 1 line
remove unused import
........
................
2009-01-03 12:53:14 -04:00
|
|
|
b = "import foo, bar, x"
|
|
|
|
a = "from . import foo, bar, x"
|
|
|
|
self.check_both(b, a)
|
|
|
|
|
|
|
|
b = "import x, y, z"
|
|
|
|
a = "from . import x, y, z"
|
|
|
|
self.check_both(b, a)
|
|
|
|
|
2008-11-24 23:08:21 -04:00
|
|
|
def test_import_as(self):
|
|
|
|
b = "import foo as x"
|
|
|
|
a = "from . import foo as x"
|
|
|
|
self.check_both(b, a)
|
|
|
|
|
Merged revisions 68197 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk
................
r68197 | benjamin.peterson | 2009-01-03 10:34:02 -0600 (Sat, 03 Jan 2009) | 55 lines
Merged revisions 67900-67901,67919,67928,67984,67991-67993,68106-68108,68110 via svnmerge from
svn+ssh://pythondev@svn.python.org/sandbox/trunk/2to3/lib2to3
........
r67900 | benjamin.peterson | 2008-12-22 14:02:45 -0600 (Mon, 22 Dec 2008) | 4 lines
fix_execfile: wrap the open(fn).read() call in compile(), so the filename is preserved
also add unittests for the fixer
........
r67901 | benjamin.peterson | 2008-12-22 14:09:55 -0600 (Mon, 22 Dec 2008) | 1 line
remove unused import
........
r67919 | benjamin.peterson | 2008-12-23 13:12:22 -0600 (Tue, 23 Dec 2008) | 1 line
copy permission bits from the backup to the original
........
r67928 | benjamin.peterson | 2008-12-26 20:49:30 -0600 (Fri, 26 Dec 2008) | 1 line
don't be so idiot about multiple local imports in fix_import; still won't handle absolute and local imports on the same line
........
r67984 | benjamin.peterson | 2008-12-28 09:55:16 -0600 (Sun, 28 Dec 2008) | 1 line
don't need loop
........
r67991 | benjamin.peterson | 2008-12-28 14:30:26 -0600 (Sun, 28 Dec 2008) | 1 line
actually call finish_tree()
........
r67992 | benjamin.peterson | 2008-12-28 14:34:47 -0600 (Sun, 28 Dec 2008) | 1 line
remove useless test
........
r67993 | benjamin.peterson | 2008-12-28 15:04:32 -0600 (Sun, 28 Dec 2008) | 1 line
update pyk3's test grammar
........
r68106 | benjamin.peterson | 2008-12-31 11:53:58 -0600 (Wed, 31 Dec 2008) | 1 line
#2734 don't convert every instance of long (eg if it's an attribute)
........
r68107 | benjamin.peterson | 2008-12-31 11:55:10 -0600 (Wed, 31 Dec 2008) | 1 line
add another test
........
r68108 | benjamin.peterson | 2008-12-31 12:00:12 -0600 (Wed, 31 Dec 2008) | 1 line
don't change long even if it's the only argument name
........
r68110 | benjamin.peterson | 2008-12-31 14:13:26 -0600 (Wed, 31 Dec 2008) | 1 line
remove unused import
........
................
2009-01-03 12:53:14 -04:00
|
|
|
b = "import a as b, b as c, c as d"
|
|
|
|
a = "from . import a as b, b as c, c as d"
|
|
|
|
self.check_both(b, a)
|
|
|
|
|
|
|
|
def test_local_and_absolute(self):
|
|
|
|
self.always_exists = False
|
|
|
|
self.present_files = set(["foo.py", "__init__.py"])
|
|
|
|
|
|
|
|
s = "import foo, bar"
|
|
|
|
self.warns_unchanged(s, "absolute and local imports together")
|
|
|
|
|
Merged revisions 61724-61725 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk
................
r61724 | martin.v.loewis | 2008-03-22 01:01:12 +0100 (Sa, 22 Mär 2008) | 49 lines
Merged revisions 61602-61723 via svnmerge from
svn+ssh://pythondev@svn.python.org/sandbox/trunk/2to3/lib2to3
........
r61626 | david.wolever | 2008-03-19 17:19:16 +0100 (Mi, 19 Mär 2008) | 1 line
Added fixer for implicit local imports. See #2414.
........
r61628 | david.wolever | 2008-03-19 17:57:43 +0100 (Mi, 19 Mär 2008) | 1 line
Added a class for tests which should not run if a particular import is found.
........
r61629 | collin.winter | 2008-03-19 17:58:19 +0100 (Mi, 19 Mär 2008) | 1 line
Two more relative import fixes in pgen2.
........
r61635 | david.wolever | 2008-03-19 20:16:03 +0100 (Mi, 19 Mär 2008) | 1 line
Fixed print fixer so it will do the Right Thing when it encounters __future__.print_function. 2to3 gets upset, though, so the tests have been commented out.
........
r61637 | david.wolever | 2008-03-19 21:37:17 +0100 (Mi, 19 Mär 2008) | 3 lines
Added a fixer for itertools imports (from itertools import imap, ifilterfalse --> from itertools import filterfalse)
........
r61645 | david.wolever | 2008-03-19 23:22:35 +0100 (Mi, 19 Mär 2008) | 1 line
SVN is happier when you add the files you create... -_-'
........
r61654 | david.wolever | 2008-03-20 01:09:56 +0100 (Do, 20 Mär 2008) | 1 line
Added an explicit sort order to fixers -- fixes problems like #2427
........
r61664 | david.wolever | 2008-03-20 04:32:40 +0100 (Do, 20 Mär 2008) | 3 lines
Fixes #2428 -- comments are no longer eatten by __future__ fixer.
........
r61673 | david.wolever | 2008-03-20 17:22:40 +0100 (Do, 20 Mär 2008) | 1 line
Added 2to3 node pretty-printer
........
r61679 | david.wolever | 2008-03-20 20:50:42 +0100 (Do, 20 Mär 2008) | 1 line
Made node printing a little bit prettier
........
r61723 | martin.v.loewis | 2008-03-22 00:59:27 +0100 (Sa, 22 Mär 2008) | 2 lines
Fix whitespace.
........
................
r61725 | martin.v.loewis | 2008-03-22 01:02:41 +0100 (Sa, 22 Mär 2008) | 2 lines
Install lib2to3.
................
2008-03-21 21:07:09 -03:00
|
|
|
def test_dotted_import(self):
|
|
|
|
b = "import foo.bar"
|
2008-03-23 21:50:58 -03:00
|
|
|
a = "from . import foo.bar"
|
Merged revisions 61724-61725 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk
................
r61724 | martin.v.loewis | 2008-03-22 01:01:12 +0100 (Sa, 22 Mär 2008) | 49 lines
Merged revisions 61602-61723 via svnmerge from
svn+ssh://pythondev@svn.python.org/sandbox/trunk/2to3/lib2to3
........
r61626 | david.wolever | 2008-03-19 17:19:16 +0100 (Mi, 19 Mär 2008) | 1 line
Added fixer for implicit local imports. See #2414.
........
r61628 | david.wolever | 2008-03-19 17:57:43 +0100 (Mi, 19 Mär 2008) | 1 line
Added a class for tests which should not run if a particular import is found.
........
r61629 | collin.winter | 2008-03-19 17:58:19 +0100 (Mi, 19 Mär 2008) | 1 line
Two more relative import fixes in pgen2.
........
r61635 | david.wolever | 2008-03-19 20:16:03 +0100 (Mi, 19 Mär 2008) | 1 line
Fixed print fixer so it will do the Right Thing when it encounters __future__.print_function. 2to3 gets upset, though, so the tests have been commented out.
........
r61637 | david.wolever | 2008-03-19 21:37:17 +0100 (Mi, 19 Mär 2008) | 3 lines
Added a fixer for itertools imports (from itertools import imap, ifilterfalse --> from itertools import filterfalse)
........
r61645 | david.wolever | 2008-03-19 23:22:35 +0100 (Mi, 19 Mär 2008) | 1 line
SVN is happier when you add the files you create... -_-'
........
r61654 | david.wolever | 2008-03-20 01:09:56 +0100 (Do, 20 Mär 2008) | 1 line
Added an explicit sort order to fixers -- fixes problems like #2427
........
r61664 | david.wolever | 2008-03-20 04:32:40 +0100 (Do, 20 Mär 2008) | 3 lines
Fixes #2428 -- comments are no longer eatten by __future__ fixer.
........
r61673 | david.wolever | 2008-03-20 17:22:40 +0100 (Do, 20 Mär 2008) | 1 line
Added 2to3 node pretty-printer
........
r61679 | david.wolever | 2008-03-20 20:50:42 +0100 (Do, 20 Mär 2008) | 1 line
Made node printing a little bit prettier
........
r61723 | martin.v.loewis | 2008-03-22 00:59:27 +0100 (Sa, 22 Mär 2008) | 2 lines
Fix whitespace.
........
................
r61725 | martin.v.loewis | 2008-03-22 01:02:41 +0100 (Sa, 22 Mär 2008) | 2 lines
Install lib2to3.
................
2008-03-21 21:07:09 -03:00
|
|
|
self.check_both(b, a)
|
|
|
|
|
|
|
|
def test_dotted_import_as(self):
|
|
|
|
b = "import foo.bar as bang"
|
2008-03-23 21:50:58 -03:00
|
|
|
a = "from . import foo.bar as bang"
|
Merged revisions 61724-61725 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk
................
r61724 | martin.v.loewis | 2008-03-22 01:01:12 +0100 (Sa, 22 Mär 2008) | 49 lines
Merged revisions 61602-61723 via svnmerge from
svn+ssh://pythondev@svn.python.org/sandbox/trunk/2to3/lib2to3
........
r61626 | david.wolever | 2008-03-19 17:19:16 +0100 (Mi, 19 Mär 2008) | 1 line
Added fixer for implicit local imports. See #2414.
........
r61628 | david.wolever | 2008-03-19 17:57:43 +0100 (Mi, 19 Mär 2008) | 1 line
Added a class for tests which should not run if a particular import is found.
........
r61629 | collin.winter | 2008-03-19 17:58:19 +0100 (Mi, 19 Mär 2008) | 1 line
Two more relative import fixes in pgen2.
........
r61635 | david.wolever | 2008-03-19 20:16:03 +0100 (Mi, 19 Mär 2008) | 1 line
Fixed print fixer so it will do the Right Thing when it encounters __future__.print_function. 2to3 gets upset, though, so the tests have been commented out.
........
r61637 | david.wolever | 2008-03-19 21:37:17 +0100 (Mi, 19 Mär 2008) | 3 lines
Added a fixer for itertools imports (from itertools import imap, ifilterfalse --> from itertools import filterfalse)
........
r61645 | david.wolever | 2008-03-19 23:22:35 +0100 (Mi, 19 Mär 2008) | 1 line
SVN is happier when you add the files you create... -_-'
........
r61654 | david.wolever | 2008-03-20 01:09:56 +0100 (Do, 20 Mär 2008) | 1 line
Added an explicit sort order to fixers -- fixes problems like #2427
........
r61664 | david.wolever | 2008-03-20 04:32:40 +0100 (Do, 20 Mär 2008) | 3 lines
Fixes #2428 -- comments are no longer eatten by __future__ fixer.
........
r61673 | david.wolever | 2008-03-20 17:22:40 +0100 (Do, 20 Mär 2008) | 1 line
Added 2to3 node pretty-printer
........
r61679 | david.wolever | 2008-03-20 20:50:42 +0100 (Do, 20 Mär 2008) | 1 line
Made node printing a little bit prettier
........
r61723 | martin.v.loewis | 2008-03-22 00:59:27 +0100 (Sa, 22 Mär 2008) | 2 lines
Fix whitespace.
........
................
r61725 | martin.v.loewis | 2008-03-22 01:02:41 +0100 (Sa, 22 Mär 2008) | 2 lines
Install lib2to3.
................
2008-03-21 21:07:09 -03:00
|
|
|
self.check_both(b, a)
|
|
|
|
|
2008-07-19 11:19:28 -03:00
|
|
|
def test_prefix(self):
|
|
|
|
b = """
|
|
|
|
# prefix
|
|
|
|
import foo.bar
|
|
|
|
"""
|
|
|
|
a = """
|
|
|
|
# prefix
|
|
|
|
from . import foo.bar
|
|
|
|
"""
|
|
|
|
self.check_both(b, a)
|
|
|
|
|
Merged revisions 66887,66891,66902-66903,66905-66906,66911-66913,66922,66927-66928,66936,66939-66940,66962,66964,66973 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk
................
r66887 | benjamin.peterson | 2008-10-13 16:51:40 -0500 (Mon, 13 Oct 2008) | 1 line
document how to disable fixers
................
r66891 | amaury.forgeotdarc | 2008-10-14 16:47:22 -0500 (Tue, 14 Oct 2008) | 5 lines
#4122: On Windows, Py_UNICODE_ISSPACE cannot be used in an extension module:
compilation fails with "undefined reference to _Py_ascii_whitespace"
Will backport to 2.6.
................
r66902 | skip.montanaro | 2008-10-15 06:49:10 -0500 (Wed, 15 Oct 2008) | 1 line
easter egg
................
r66903 | benjamin.peterson | 2008-10-15 15:34:09 -0500 (Wed, 15 Oct 2008) | 1 line
don't recurse into directories that start with '.'
................
r66905 | benjamin.peterson | 2008-10-15 16:05:55 -0500 (Wed, 15 Oct 2008) | 1 line
support the optional line argument for idle
................
r66906 | benjamin.peterson | 2008-10-15 16:58:46 -0500 (Wed, 15 Oct 2008) | 1 line
add a much requested newline
................
r66911 | benjamin.peterson | 2008-10-15 18:10:28 -0500 (Wed, 15 Oct 2008) | 41 lines
Merged revisions 66805,66841,66860,66884-66886,66893,66907,66910 via svnmerge from
svn+ssh://pythondev@svn.python.org/sandbox/trunk/2to3/lib2to3
........
r66805 | benjamin.peterson | 2008-10-04 20:11:02 -0500 (Sat, 04 Oct 2008) | 1 line
mention what the fixes directory is for
........
r66841 | benjamin.peterson | 2008-10-07 17:48:12 -0500 (Tue, 07 Oct 2008) | 1 line
use assertFalse and assertTrue
........
r66860 | benjamin.peterson | 2008-10-08 16:05:07 -0500 (Wed, 08 Oct 2008) | 1 line
instead of abusing the pattern matcher, use start_tree to find a next binding
........
r66884 | benjamin.peterson | 2008-10-13 15:50:30 -0500 (Mon, 13 Oct 2008) | 1 line
don't print tokens to stdout when -v is given
........
r66885 | benjamin.peterson | 2008-10-13 16:28:57 -0500 (Mon, 13 Oct 2008) | 1 line
add the -x option to disable fixers
........
r66886 | benjamin.peterson | 2008-10-13 16:33:53 -0500 (Mon, 13 Oct 2008) | 1 line
cut down on some crud
........
r66893 | benjamin.peterson | 2008-10-14 17:16:54 -0500 (Tue, 14 Oct 2008) | 1 line
add an optional set literal fixer
........
r66907 | benjamin.peterson | 2008-10-15 16:59:41 -0500 (Wed, 15 Oct 2008) | 1 line
don't write backup files by default
........
r66910 | benjamin.peterson | 2008-10-15 17:43:10 -0500 (Wed, 15 Oct 2008) | 1 line
add the -n option; it stops backupfiles from being written
........
................
r66912 | hirokazu.yamamoto | 2008-10-16 01:25:25 -0500 (Thu, 16 Oct 2008) | 2 lines
removed unused _PyUnicode_FromFileSystemEncodedObject.
made win32_chdir, win32_wchdir static.
................
r66913 | benjamin.peterson | 2008-10-16 13:52:14 -0500 (Thu, 16 Oct 2008) | 1 line
document that deque indexing is O(n) #4123
................
r66922 | benjamin.peterson | 2008-10-16 14:40:14 -0500 (Thu, 16 Oct 2008) | 1 line
use new showwarnings signature for idle #3391
................
r66927 | andrew.kuchling | 2008-10-16 15:15:47 -0500 (Thu, 16 Oct 2008) | 1 line
Fix wording (2.6.1 backport candidate)
................
r66928 | georg.brandl | 2008-10-16 15:20:56 -0500 (Thu, 16 Oct 2008) | 2 lines
Add more TOC to the whatsnew index page.
................
r66936 | georg.brandl | 2008-10-16 16:20:15 -0500 (Thu, 16 Oct 2008) | 2 lines
#4131: FF3 doesn't write cookies.txt files.
................
r66939 | georg.brandl | 2008-10-16 16:36:39 -0500 (Thu, 16 Oct 2008) | 2 lines
part of #4012: kill off old name "processing".
................
r66940 | georg.brandl | 2008-10-16 16:38:48 -0500 (Thu, 16 Oct 2008) | 2 lines
#4083: add "as" to except handler grammar as per PEP 3110.
................
r66962 | benjamin.peterson | 2008-10-17 15:01:01 -0500 (Fri, 17 Oct 2008) | 1 line
clarify CALL_FUNCTION #4141
................
r66964 | georg.brandl | 2008-10-17 16:41:49 -0500 (Fri, 17 Oct 2008) | 2 lines
Fix duplicate word.
................
r66973 | armin.ronacher | 2008-10-19 03:27:43 -0500 (Sun, 19 Oct 2008) | 3 lines
Fixed #4067 by implementing _attributes and _fields for the AST root node.
................
2008-10-19 11:07:49 -03:00
|
|
|
|
|
|
|
class Test_set_literal(FixerTestCase):
|
|
|
|
|
|
|
|
fixer = "set_literal"
|
|
|
|
|
|
|
|
def test_basic(self):
|
|
|
|
b = """set([1, 2, 3])"""
|
|
|
|
a = """{1, 2, 3}"""
|
|
|
|
self.check(b, a)
|
|
|
|
|
|
|
|
b = """set((1, 2, 3))"""
|
|
|
|
a = """{1, 2, 3}"""
|
|
|
|
self.check(b, a)
|
|
|
|
|
|
|
|
b = """set((1,))"""
|
|
|
|
a = """{1}"""
|
|
|
|
self.check(b, a)
|
|
|
|
|
|
|
|
b = """set([1])"""
|
|
|
|
self.check(b, a)
|
|
|
|
|
|
|
|
b = """set((a, b))"""
|
|
|
|
a = """{a, b}"""
|
|
|
|
self.check(b, a)
|
|
|
|
|
|
|
|
b = """set([a, b])"""
|
|
|
|
self.check(b, a)
|
|
|
|
|
|
|
|
b = """set((a*234, f(args=23)))"""
|
|
|
|
a = """{a*234, f(args=23)}"""
|
|
|
|
self.check(b, a)
|
|
|
|
|
|
|
|
b = """set([a*23, f(23)])"""
|
|
|
|
a = """{a*23, f(23)}"""
|
|
|
|
self.check(b, a)
|
|
|
|
|
|
|
|
b = """set([a-234**23])"""
|
|
|
|
a = """{a-234**23}"""
|
|
|
|
self.check(b, a)
|
|
|
|
|
|
|
|
def test_listcomps(self):
|
|
|
|
b = """set([x for x in y])"""
|
|
|
|
a = """{x for x in y}"""
|
|
|
|
self.check(b, a)
|
|
|
|
|
|
|
|
b = """set([x for x in y if x == m])"""
|
|
|
|
a = """{x for x in y if x == m}"""
|
|
|
|
self.check(b, a)
|
|
|
|
|
|
|
|
b = """set([x for x in y for a in b])"""
|
|
|
|
a = """{x for x in y for a in b}"""
|
|
|
|
self.check(b, a)
|
|
|
|
|
|
|
|
b = """set([f(x) - 23 for x in y])"""
|
|
|
|
a = """{f(x) - 23 for x in y}"""
|
|
|
|
self.check(b, a)
|
|
|
|
|
|
|
|
def test_whitespace(self):
|
|
|
|
b = """set( [1, 2])"""
|
|
|
|
a = """{1, 2}"""
|
|
|
|
self.check(b, a)
|
|
|
|
|
|
|
|
b = """set([1 , 2])"""
|
|
|
|
a = """{1 , 2}"""
|
|
|
|
self.check(b, a)
|
|
|
|
|
|
|
|
b = """set([ 1 ])"""
|
|
|
|
a = """{ 1 }"""
|
|
|
|
self.check(b, a)
|
|
|
|
|
|
|
|
b = """set( [1] )"""
|
|
|
|
a = """{1}"""
|
|
|
|
self.check(b, a)
|
|
|
|
|
|
|
|
b = """set([ 1, 2 ])"""
|
|
|
|
a = """{ 1, 2 }"""
|
|
|
|
self.check(b, a)
|
|
|
|
|
|
|
|
b = """set([x for x in y ])"""
|
|
|
|
a = """{x for x in y }"""
|
|
|
|
self.check(b, a)
|
|
|
|
|
|
|
|
b = """set(
|
|
|
|
[1, 2]
|
|
|
|
)
|
|
|
|
"""
|
|
|
|
a = """{1, 2}\n"""
|
|
|
|
self.check(b, a)
|
|
|
|
|
|
|
|
def test_comments(self):
|
|
|
|
b = """set((1, 2)) # Hi"""
|
|
|
|
a = """{1, 2} # Hi"""
|
|
|
|
self.check(b, a)
|
|
|
|
|
|
|
|
# This isn't optimal behavior, but the fixer is optional.
|
|
|
|
b = """
|
|
|
|
# Foo
|
|
|
|
set( # Bar
|
|
|
|
(1, 2)
|
|
|
|
)
|
|
|
|
"""
|
|
|
|
a = """
|
|
|
|
# Foo
|
|
|
|
{1, 2}
|
|
|
|
"""
|
|
|
|
self.check(b, a)
|
|
|
|
|
|
|
|
def test_unchanged(self):
|
|
|
|
s = """set()"""
|
|
|
|
self.unchanged(s)
|
|
|
|
|
|
|
|
s = """set(a)"""
|
|
|
|
self.unchanged(s)
|
|
|
|
|
|
|
|
s = """set(a, b, c)"""
|
|
|
|
self.unchanged(s)
|
|
|
|
|
|
|
|
# Don't transform generators because they might have to be lazy.
|
|
|
|
s = """set(x for x in y)"""
|
|
|
|
self.unchanged(s)
|
|
|
|
|
|
|
|
s = """set(x for x in y if z)"""
|
|
|
|
self.unchanged(s)
|
|
|
|
|
|
|
|
s = """set(a*823-23**2 + f(23))"""
|
|
|
|
self.unchanged(s)
|
|
|
|
|
|
|
|
|
2008-09-01 16:56:06 -03:00
|
|
|
class Test_sys_exc(FixerTestCase):
|
|
|
|
fixer = "sys_exc"
|
|
|
|
|
|
|
|
def test_0(self):
|
|
|
|
b = "sys.exc_type"
|
|
|
|
a = "sys.exc_info()[0]"
|
|
|
|
self.check(b, a)
|
|
|
|
|
|
|
|
def test_1(self):
|
|
|
|
b = "sys.exc_value"
|
|
|
|
a = "sys.exc_info()[1]"
|
|
|
|
self.check(b, a)
|
|
|
|
|
|
|
|
def test_2(self):
|
|
|
|
b = "sys.exc_traceback"
|
|
|
|
a = "sys.exc_info()[2]"
|
|
|
|
self.check(b, a)
|
|
|
|
|
|
|
|
def test_3(self):
|
|
|
|
b = "sys.exc_type # Foo"
|
|
|
|
a = "sys.exc_info()[0] # Foo"
|
|
|
|
self.check(b, a)
|
|
|
|
|
|
|
|
def test_4(self):
|
|
|
|
b = "sys. exc_type"
|
|
|
|
a = "sys. exc_info()[0]"
|
|
|
|
self.check(b, a)
|
|
|
|
|
|
|
|
def test_5(self):
|
|
|
|
b = "sys .exc_type"
|
|
|
|
a = "sys .exc_info()[0]"
|
|
|
|
self.check(b, a)
|
|
|
|
|
|
|
|
|
|
|
|
class Test_paren(FixerTestCase):
|
|
|
|
fixer = "paren"
|
|
|
|
|
|
|
|
def test_0(self):
|
|
|
|
b = """[i for i in 1, 2 ]"""
|
|
|
|
a = """[i for i in (1, 2) ]"""
|
|
|
|
self.check(b, a)
|
|
|
|
|
|
|
|
def test_1(self):
|
|
|
|
b = """[i for i in 1, 2, ]"""
|
|
|
|
a = """[i for i in (1, 2,) ]"""
|
|
|
|
self.check(b, a)
|
|
|
|
|
|
|
|
def test_2(self):
|
|
|
|
b = """[i for i in 1, 2 ]"""
|
|
|
|
a = """[i for i in (1, 2) ]"""
|
|
|
|
self.check(b, a)
|
|
|
|
|
|
|
|
def test_3(self):
|
|
|
|
b = """[i for i in 1, 2 if i]"""
|
|
|
|
a = """[i for i in (1, 2) if i]"""
|
|
|
|
self.check(b, a)
|
|
|
|
|
|
|
|
def test_4(self):
|
|
|
|
b = """[i for i in 1, 2 ]"""
|
|
|
|
a = """[i for i in (1, 2) ]"""
|
|
|
|
self.check(b, a)
|
|
|
|
|
|
|
|
def test_5(self):
|
|
|
|
b = """(i for i in 1, 2)"""
|
|
|
|
a = """(i for i in (1, 2))"""
|
|
|
|
self.check(b, a)
|
|
|
|
|
|
|
|
def test_6(self):
|
|
|
|
b = """(i for i in 1 ,2 if i)"""
|
|
|
|
a = """(i for i in (1 ,2) if i)"""
|
|
|
|
self.check(b, a)
|
|
|
|
|
|
|
|
def test_unchanged_0(self):
|
|
|
|
s = """[i for i in (1, 2)]"""
|
|
|
|
self.unchanged(s)
|
|
|
|
|
|
|
|
def test_unchanged_1(self):
|
|
|
|
s = """[i for i in foo()]"""
|
|
|
|
self.unchanged(s)
|
|
|
|
|
|
|
|
def test_unchanged_2(self):
|
|
|
|
s = """[i for i in (1, 2) if nothing]"""
|
|
|
|
self.unchanged(s)
|
|
|
|
|
|
|
|
def test_unchanged_3(self):
|
|
|
|
s = """(i for i in (1, 2))"""
|
|
|
|
self.unchanged(s)
|
|
|
|
|
|
|
|
def test_unchanged_4(self):
|
|
|
|
s = """[i for i in m]"""
|
|
|
|
self.unchanged(s)
|
|
|
|
|
2008-09-13 15:37:09 -03:00
|
|
|
class Test_metaclass(FixerTestCase):
|
|
|
|
|
|
|
|
fixer = 'metaclass'
|
|
|
|
|
|
|
|
def test_unchanged(self):
|
|
|
|
self.unchanged("class X(): pass")
|
|
|
|
self.unchanged("class X(object): pass")
|
|
|
|
self.unchanged("class X(object1, object2): pass")
|
|
|
|
self.unchanged("class X(object1, object2, object3): pass")
|
|
|
|
self.unchanged("class X(metaclass=Meta): pass")
|
|
|
|
self.unchanged("class X(b, arg=23, metclass=Meta): pass")
|
|
|
|
self.unchanged("class X(b, arg=23, metaclass=Meta, other=42): pass")
|
|
|
|
|
|
|
|
s = """
|
|
|
|
class X:
|
|
|
|
def __metaclass__(self): pass
|
|
|
|
"""
|
|
|
|
self.unchanged(s)
|
|
|
|
|
Merged revisions 67180 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk
................
r67180 | benjamin.peterson | 2008-11-10 16:11:12 -0600 (Mon, 10 Nov 2008) | 29 lines
Merged revisions 66985,67170,67173,67177-67179 via svnmerge from
svn+ssh://pythondev@svn.python.org/sandbox/trunk/2to3/lib2to3
........
r66985 | benjamin.peterson | 2008-10-20 16:43:46 -0500 (Mon, 20 Oct 2008) | 1 line
no need to use nested try, except, finally
........
r67170 | benjamin.peterson | 2008-11-08 12:28:31 -0600 (Sat, 08 Nov 2008) | 1 line
fix #4271: fix_imports didn't recognize imports with parenthesis (ie from x import (a, b))
........
r67173 | benjamin.peterson | 2008-11-08 17:42:08 -0600 (Sat, 08 Nov 2008) | 1 line
consolidate test
........
r67177 | benjamin.peterson | 2008-11-09 21:52:52 -0600 (Sun, 09 Nov 2008) | 1 line
let the metclass fixer handle complex assignments in the class body gracefully
........
r67178 | benjamin.peterson | 2008-11-10 15:26:43 -0600 (Mon, 10 Nov 2008) | 1 line
the metaclass fixers shouldn't die when bases are not a simple name
........
r67179 | benjamin.peterson | 2008-11-10 15:29:58 -0600 (Mon, 10 Nov 2008) | 1 line
allow the fix_import pattern to catch from imports with parenthesis
........
................
2008-11-10 18:21:33 -04:00
|
|
|
s = """
|
|
|
|
class X:
|
|
|
|
a[23] = 74
|
|
|
|
"""
|
|
|
|
self.unchanged(s)
|
|
|
|
|
2008-09-13 15:37:09 -03:00
|
|
|
def test_comments(self):
|
|
|
|
b = """
|
|
|
|
class X:
|
|
|
|
# hi
|
|
|
|
__metaclass__ = AppleMeta
|
|
|
|
"""
|
|
|
|
a = """
|
|
|
|
class X(metaclass=AppleMeta):
|
|
|
|
# hi
|
|
|
|
pass
|
|
|
|
"""
|
|
|
|
self.check(b, a)
|
|
|
|
|
|
|
|
b = """
|
|
|
|
class X:
|
|
|
|
__metaclass__ = Meta
|
|
|
|
# Bedtime!
|
|
|
|
"""
|
|
|
|
a = """
|
|
|
|
class X(metaclass=Meta):
|
|
|
|
pass
|
|
|
|
# Bedtime!
|
|
|
|
"""
|
|
|
|
self.check(b, a)
|
|
|
|
|
|
|
|
def test_meta(self):
|
|
|
|
# no-parent class, odd body
|
|
|
|
b = """
|
|
|
|
class X():
|
|
|
|
__metaclass__ = Q
|
|
|
|
pass
|
|
|
|
"""
|
|
|
|
a = """
|
|
|
|
class X(metaclass=Q):
|
|
|
|
pass
|
|
|
|
"""
|
|
|
|
self.check(b, a)
|
|
|
|
|
|
|
|
# one parent class, no body
|
|
|
|
b = """class X(object): __metaclass__ = Q"""
|
|
|
|
a = """class X(object, metaclass=Q): pass"""
|
|
|
|
self.check(b, a)
|
|
|
|
|
|
|
|
|
|
|
|
# one parent, simple body
|
|
|
|
b = """
|
|
|
|
class X(object):
|
|
|
|
__metaclass__ = Meta
|
|
|
|
bar = 7
|
|
|
|
"""
|
|
|
|
a = """
|
|
|
|
class X(object, metaclass=Meta):
|
|
|
|
bar = 7
|
|
|
|
"""
|
|
|
|
self.check(b, a)
|
|
|
|
|
|
|
|
b = """
|
|
|
|
class X:
|
|
|
|
__metaclass__ = Meta; x = 4; g = 23
|
|
|
|
"""
|
|
|
|
a = """
|
|
|
|
class X(metaclass=Meta):
|
|
|
|
x = 4; g = 23
|
|
|
|
"""
|
|
|
|
self.check(b, a)
|
|
|
|
|
|
|
|
# one parent, simple body, __metaclass__ last
|
|
|
|
b = """
|
|
|
|
class X(object):
|
|
|
|
bar = 7
|
|
|
|
__metaclass__ = Meta
|
|
|
|
"""
|
|
|
|
a = """
|
|
|
|
class X(object, metaclass=Meta):
|
|
|
|
bar = 7
|
|
|
|
"""
|
|
|
|
self.check(b, a)
|
|
|
|
|
|
|
|
# redefining __metaclass__
|
|
|
|
b = """
|
|
|
|
class X():
|
|
|
|
__metaclass__ = A
|
|
|
|
__metaclass__ = B
|
|
|
|
bar = 7
|
|
|
|
"""
|
|
|
|
a = """
|
|
|
|
class X(metaclass=B):
|
|
|
|
bar = 7
|
|
|
|
"""
|
|
|
|
self.check(b, a)
|
|
|
|
|
|
|
|
# multiple inheritance, simple body
|
|
|
|
b = """
|
|
|
|
class X(clsA, clsB):
|
|
|
|
__metaclass__ = Meta
|
|
|
|
bar = 7
|
|
|
|
"""
|
|
|
|
a = """
|
|
|
|
class X(clsA, clsB, metaclass=Meta):
|
|
|
|
bar = 7
|
|
|
|
"""
|
|
|
|
self.check(b, a)
|
|
|
|
|
|
|
|
# keywords in the class statement
|
|
|
|
b = """class m(a, arg=23): __metaclass__ = Meta"""
|
|
|
|
a = """class m(a, arg=23, metaclass=Meta): pass"""
|
|
|
|
self.check(b, a)
|
|
|
|
|
Merged revisions 67180 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk
................
r67180 | benjamin.peterson | 2008-11-10 16:11:12 -0600 (Mon, 10 Nov 2008) | 29 lines
Merged revisions 66985,67170,67173,67177-67179 via svnmerge from
svn+ssh://pythondev@svn.python.org/sandbox/trunk/2to3/lib2to3
........
r66985 | benjamin.peterson | 2008-10-20 16:43:46 -0500 (Mon, 20 Oct 2008) | 1 line
no need to use nested try, except, finally
........
r67170 | benjamin.peterson | 2008-11-08 12:28:31 -0600 (Sat, 08 Nov 2008) | 1 line
fix #4271: fix_imports didn't recognize imports with parenthesis (ie from x import (a, b))
........
r67173 | benjamin.peterson | 2008-11-08 17:42:08 -0600 (Sat, 08 Nov 2008) | 1 line
consolidate test
........
r67177 | benjamin.peterson | 2008-11-09 21:52:52 -0600 (Sun, 09 Nov 2008) | 1 line
let the metclass fixer handle complex assignments in the class body gracefully
........
r67178 | benjamin.peterson | 2008-11-10 15:26:43 -0600 (Mon, 10 Nov 2008) | 1 line
the metaclass fixers shouldn't die when bases are not a simple name
........
r67179 | benjamin.peterson | 2008-11-10 15:29:58 -0600 (Mon, 10 Nov 2008) | 1 line
allow the fix_import pattern to catch from imports with parenthesis
........
................
2008-11-10 18:21:33 -04:00
|
|
|
b = """
|
|
|
|
class X(expression(2 + 4)):
|
|
|
|
__metaclass__ = Meta
|
|
|
|
"""
|
|
|
|
a = """
|
|
|
|
class X(expression(2 + 4), metaclass=Meta):
|
|
|
|
pass
|
|
|
|
"""
|
|
|
|
self.check(b, a)
|
|
|
|
|
|
|
|
b = """
|
|
|
|
class X(expression(2 + 4), x**4):
|
|
|
|
__metaclass__ = Meta
|
|
|
|
"""
|
|
|
|
a = """
|
|
|
|
class X(expression(2 + 4), x**4, metaclass=Meta):
|
|
|
|
pass
|
|
|
|
"""
|
|
|
|
self.check(b, a)
|
|
|
|
|
2008-11-24 23:08:21 -04:00
|
|
|
b = """
|
|
|
|
class X:
|
|
|
|
__metaclass__ = Meta
|
|
|
|
save.py = 23
|
|
|
|
"""
|
|
|
|
a = """
|
|
|
|
class X(metaclass=Meta):
|
|
|
|
save.py = 23
|
|
|
|
"""
|
|
|
|
self.check(b, a)
|
|
|
|
|
2008-03-19 02:04:44 -03:00
|
|
|
|
2008-10-04 18:04:36 -03:00
|
|
|
class Test_getcwdu(FixerTestCase):
|
|
|
|
|
|
|
|
fixer = 'getcwdu'
|
|
|
|
|
|
|
|
def test_basic(self):
|
|
|
|
b = """os.getcwdu"""
|
|
|
|
a = """os.getcwd"""
|
|
|
|
self.check(b, a)
|
|
|
|
|
|
|
|
b = """os.getcwdu()"""
|
|
|
|
a = """os.getcwd()"""
|
|
|
|
self.check(b, a)
|
|
|
|
|
|
|
|
b = """meth = os.getcwdu"""
|
|
|
|
a = """meth = os.getcwd"""
|
|
|
|
self.check(b, a)
|
|
|
|
|
|
|
|
b = """os.getcwdu(args)"""
|
|
|
|
a = """os.getcwd(args)"""
|
|
|
|
self.check(b, a)
|
|
|
|
|
|
|
|
def test_comment(self):
|
|
|
|
b = """os.getcwdu() # Foo"""
|
|
|
|
a = """os.getcwd() # Foo"""
|
|
|
|
self.check(b, a)
|
|
|
|
|
|
|
|
def test_unchanged(self):
|
|
|
|
s = """os.getcwd()"""
|
|
|
|
self.unchanged(s)
|
|
|
|
|
|
|
|
s = """getcwdu()"""
|
|
|
|
self.unchanged(s)
|
|
|
|
|
|
|
|
s = """os.getcwdb()"""
|
|
|
|
self.unchanged(s)
|
|
|
|
|
|
|
|
def test_indentation(self):
|
|
|
|
b = """
|
|
|
|
if 1:
|
|
|
|
os.getcwdu()
|
|
|
|
"""
|
|
|
|
a = """
|
|
|
|
if 1:
|
|
|
|
os.getcwd()
|
|
|
|
"""
|
|
|
|
self.check(b, a)
|
|
|
|
|
|
|
|
def test_multilation(self):
|
|
|
|
b = """os .getcwdu()"""
|
|
|
|
a = """os .getcwd()"""
|
|
|
|
self.check(b, a)
|
|
|
|
|
|
|
|
b = """os. getcwdu"""
|
|
|
|
a = """os. getcwd"""
|
|
|
|
self.check(b, a)
|
|
|
|
|
|
|
|
b = """os.getcwdu ( )"""
|
|
|
|
a = """os.getcwd ( )"""
|
|
|
|
self.check(b, a)
|
2009-07-21 09:55:57 -03:00
|
|
|
|
|
|
|
|
|
|
|
class Test_operator(FixerTestCase):
|
|
|
|
|
|
|
|
fixer = "operator"
|
|
|
|
|
|
|
|
def test_operator_isCallable(self):
|
|
|
|
b = "operator.isCallable(x)"
|
|
|
|
a = "hasattr(x, '__call__')"
|
|
|
|
self.check(b, a)
|
|
|
|
|
|
|
|
def test_operator_sequenceIncludes(self):
|
|
|
|
b = "operator.sequenceIncludes(x, y)"
|
|
|
|
a = "operator.contains(x, y)"
|
|
|
|
self.check(b, a)
|
|
|
|
|
|
|
|
def test_bare_isCallable(self):
|
|
|
|
s = "isCallable(x)"
|
|
|
|
self.warns_unchanged(s, "You should use hasattr(x, '__call__') here.")
|
|
|
|
|
|
|
|
def test_bare_sequenceIncludes(self):
|
|
|
|
s = "sequenceIncludes(x, y)"
|
|
|
|
self.warns_unchanged(s, "You should use operator.contains here.")
|