summaryrefslogtreecommitdiffstats
path: root/Lib/lib2to3/tests/test_fixers.py
diff options
context:
space:
mode:
Diffstat (limited to 'Lib/lib2to3/tests/test_fixers.py')
-rwxr-xr-xLib/lib2to3/tests/test_fixers.py55
1 files changed, 51 insertions, 4 deletions
diff --git a/Lib/lib2to3/tests/test_fixers.py b/Lib/lib2to3/tests/test_fixers.py
index d8218d3..2a39359 100755
--- a/Lib/lib2to3/tests/test_fixers.py
+++ b/Lib/lib2to3/tests/test_fixers.py
@@ -339,6 +339,12 @@ class Test_reduce(FixerTestCase):
a = "from functools import reduce\nreduce(a, b, c)"
self.check(b, a)
+ 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)
+
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)"
@@ -2834,6 +2840,11 @@ class Test_map(FixerTestCase):
a = """x = list(map(f, 'abc')) # foo"""
self.check(b, a)
+ 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")
+
def test_map_basic(self):
b = """x = map(f, 'abc')"""
a = """x = list(map(f, 'abc'))"""
@@ -2847,10 +2858,6 @@ class Test_map(FixerTestCase):
a = """x = list('abc')"""
self.check(b, a)
- b = """x = map(None, 'abc', 'def')"""
- a = """x = list(map(None, 'abc', 'def'))"""
- 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)
@@ -3238,6 +3245,46 @@ class Test_idioms(FixerTestCase):
"""
self.check(b, a)
+ 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)
+
def test_sort_simple_expr(self):
b = """
v = t