diff options
Diffstat (limited to 'Lib/lib2to3/tests')
-rw-r--r-- | Lib/lib2to3/tests/test_all_fixers.py | 4 | ||||
-rwxr-xr-x | Lib/lib2to3/tests/test_fixers.py | 55 | ||||
-rw-r--r-- | Lib/lib2to3/tests/test_parser.py | 6 |
3 files changed, 57 insertions, 8 deletions
diff --git a/Lib/lib2to3/tests/test_all_fixers.py b/Lib/lib2to3/tests/test_all_fixers.py index 8ef222d..61bcc54 100644 --- a/Lib/lib2to3/tests/test_all_fixers.py +++ b/Lib/lib2to3/tests/test_all_fixers.py @@ -16,10 +16,8 @@ from . import support class Test_all(support.TestCase): def setUp(self): - options = {"print_function" : False} - self.refactor = support.get_refactorer(options=options) + self.refactor = support.get_refactorer() def test_all_project_files(self): for filepath in support.all_project_files(): - print("Fixing %s..." % filepath) self.refactor.refactor_file(filepath) 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 diff --git a/Lib/lib2to3/tests/test_parser.py b/Lib/lib2to3/tests/test_parser.py index 08e7bdc..7e649da 100644 --- a/Lib/lib2to3/tests/test_parser.py +++ b/Lib/lib2to3/tests/test_parser.py @@ -147,7 +147,6 @@ class TestParserIdempotency(support.TestCase): def test_all_project_files(self): for filepath in support.all_project_files(): - print("Parsing %s..." % filepath) with open(filepath, "rb") as fp: encoding = tokenize.detect_encoding(fp.readline)[0] fp.seek(0) @@ -161,6 +160,11 @@ class TestParserIdempotency(support.TestCase): if diff(filepath, new): self.fail("Idempotency failed: %s" % filepath) + def test_extended_unpacking(self): + driver.parse_string("a, *b, c = x\n") + driver.parse_string("[*a, b] = x\n") + driver.parse_string("(z, *y, w) = m\n") + driver.parse_string("for *z, m in d: pass\n") class TestLiterals(GrammarTest): |