mirror of
https://github.com/python/cpython.git
synced 2025-09-10 10:47:34 +00:00
Merged revisions 61988-61990 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk ................ r61988 | martin.v.loewis | 2008-03-28 06:25:36 +0100 (Fr, 28 Mär 2008) | 2 lines Disable test that depends on #2412 being fixed. ................ r61989 | martin.v.loewis | 2008-03-28 06:26:10 +0100 (Fr, 28 Mär 2008) | 2 lines Run 2to3 tests. ................ r61990 | martin.v.loewis | 2008-03-28 06:27:44 +0100 (Fr, 28 Mär 2008) | 13 lines Merged revisions 61825-61989 via svnmerge from svn+ssh://pythondev@svn.python.org/sandbox/trunk/2to3/lib2to3 ........ r61899 | collin.winter | 2008-03-25 17:53:41 +0100 (Di, 25 Mär 2008) | 1 line Add a missing explicit fixer to test_all_fixers. ........ r61983 | collin.winter | 2008-03-28 03:19:46 +0100 (Fr, 28 Mär 2008) | 2 lines Fix http://bugs.python.org/issue2453: support empty excepts in fix_except. ........ ................
This commit is contained in:
parent
ba4af493a5
commit
51d1864eae
4 changed files with 92 additions and 6 deletions
|
@ -37,15 +37,18 @@ class FixExcept(basefix.BaseFix):
|
||||||
|
|
||||||
PATTERN = """
|
PATTERN = """
|
||||||
try_stmt< 'try' ':' suite
|
try_stmt< 'try' ':' suite
|
||||||
cleanup=((except_clause ':' suite)+ ['else' ':' suite]
|
cleanup=(except_clause ':' suite)+
|
||||||
['finally' ':' suite]
|
tail=(['except' ':' suite]
|
||||||
| 'finally' ':' suite) >
|
['else' ':' suite]
|
||||||
|
['finally' ':' suite]) >
|
||||||
"""
|
"""
|
||||||
|
|
||||||
def transform(self, node, results):
|
def transform(self, node, results):
|
||||||
syms = self.syms
|
syms = self.syms
|
||||||
|
|
||||||
try_cleanup = [ch.clone() for ch in results['cleanup']]
|
tail = [n.clone() for n in results["tail"]]
|
||||||
|
|
||||||
|
try_cleanup = [ch.clone() for ch in results["cleanup"]]
|
||||||
for except_clause, e_suite in find_excepts(try_cleanup):
|
for except_clause, e_suite in find_excepts(try_cleanup):
|
||||||
if len(except_clause.children) == 4:
|
if len(except_clause.children) == 4:
|
||||||
(E, comma, N) = except_clause.children[1:4]
|
(E, comma, N) = except_clause.children[1:4]
|
||||||
|
@ -85,5 +88,5 @@ class FixExcept(basefix.BaseFix):
|
||||||
N.set_prefix(" ")
|
N.set_prefix(" ")
|
||||||
|
|
||||||
#TODO(cwinter) fix this when children becomes a smart list
|
#TODO(cwinter) fix this when children becomes a smart list
|
||||||
children = [c.clone() for c in node.children[:3]] + try_cleanup
|
children = [c.clone() for c in node.children[:3]] + try_cleanup + tail
|
||||||
return pytree.Node(node.type, children)
|
return pytree.Node(node.type, children)
|
||||||
|
|
|
@ -27,7 +27,7 @@ class Options:
|
||||||
|
|
||||||
class Test_all(support.TestCase):
|
class Test_all(support.TestCase):
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
options = Options(fix=["all", "idioms", "ws_comma"],
|
options = Options(fix=["all", "idioms", "ws_comma", "buffer"],
|
||||||
print_function=False)
|
print_function=False)
|
||||||
self.refactor = refactor.RefactoringTool(options)
|
self.refactor = refactor.RefactoringTool(options)
|
||||||
|
|
||||||
|
|
|
@ -435,6 +435,8 @@ class Test_print(FixerTestCase):
|
||||||
# is fixed so it won't crash when it sees print(x=y).
|
# is fixed so it won't crash when it sees print(x=y).
|
||||||
# When #2412 is fixed, the try/except block can be taken
|
# When #2412 is fixed, the try/except block can be taken
|
||||||
# out and the tests can be run like normal.
|
# out and the tests can be run like normal.
|
||||||
|
# MvL: disable entirely for now, so that it doesn't print to stdout
|
||||||
|
return
|
||||||
try:
|
try:
|
||||||
s = "from __future__ import print_function\n"\
|
s = "from __future__ import print_function\n"\
|
||||||
"print('Hai!', end=' ')"
|
"print('Hai!', end=' ')"
|
||||||
|
@ -679,6 +681,72 @@ class Test_except(FixerTestCase):
|
||||||
pass"""
|
pass"""
|
||||||
self.check(b, a)
|
self.check(b, a)
|
||||||
|
|
||||||
|
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)
|
||||||
|
|
||||||
# These should not be touched:
|
# These should not be touched:
|
||||||
|
|
||||||
def test_unchanged_1(self):
|
def test_unchanged_1(self):
|
||||||
|
|
15
Lib/test/test_lib2to3.py
Normal file
15
Lib/test/test_lib2to3.py
Normal file
|
@ -0,0 +1,15 @@
|
||||||
|
# Skipping test_parser and test_all_fixers
|
||||||
|
# because of running
|
||||||
|
from lib2to3.tests import test_fixers, test_pytree, test_util
|
||||||
|
import unittest
|
||||||
|
from test.test_support import run_unittest
|
||||||
|
|
||||||
|
def suite():
|
||||||
|
tests = unittest.TestSuite()
|
||||||
|
loader = unittest.TestLoader()
|
||||||
|
for m in (test_fixers,test_pytree,test_util):
|
||||||
|
tests.addTests(loader.loadTestsFromModule(m))
|
||||||
|
return tests
|
||||||
|
|
||||||
|
def test_main():
|
||||||
|
run_unittest(suite())
|
Loading…
Add table
Add a link
Reference in a new issue