+++ /dev/null
-\r
-import unittest\r
-from test import test_support\r
-import textwrap\r
-\r
-class ComplexArgsTestCase(unittest.TestCase):\r
-\r
- def check(self, func, expected, *args):\r
- self.assertEqual(func(*args), expected)\r
-\r
- # These functions are tested below as lambdas too. If you add a\r
- # function test, also add a similar lambda test.\r
-\r
- # Functions are wrapped in "exec" statements in order to\r
- # silence Py3k warnings.\r
-\r
- def test_func_parens_no_unpacking(self):\r
- exec textwrap.dedent("""\r
- def f(((((x))))): return x\r
- self.check(f, 1, 1)\r
- # Inner parens are elided, same as: f(x,)\r
- def f(((x)),): return x\r
- self.check(f, 2, 2)\r
- """)\r
-\r
- def test_func_1(self):\r
- exec textwrap.dedent("""\r
- def f(((((x),)))): return x\r
- self.check(f, 3, (3,))\r
- def f(((((x)),))): return x\r
- self.check(f, 4, (4,))\r
- def f(((((x))),)): return x\r
- self.check(f, 5, (5,))\r
- def f(((x),)): return x\r
- self.check(f, 6, (6,))\r
- """)\r
-\r
- def test_func_2(self):\r
- exec textwrap.dedent("""\r
- def f(((((x)),),)): return x\r
- self.check(f, 2, ((2,),))\r
- """)\r
-\r
- def test_func_3(self):\r
- exec textwrap.dedent("""\r
- def f((((((x)),),),)): return x\r
- self.check(f, 3, (((3,),),))\r
- """)\r
-\r
- def test_func_complex(self):\r
- exec textwrap.dedent("""\r
- def f((((((x)),),),), a, b, c): return x, a, b, c\r
- self.check(f, (3, 9, 8, 7), (((3,),),), 9, 8, 7)\r
-\r
- def f(((((((x)),)),),), a, b, c): return x, a, b, c\r
- self.check(f, (3, 9, 8, 7), (((3,),),), 9, 8, 7)\r
-\r
- def f(a, b, c, ((((((x)),)),),)): return a, b, c, x\r
- self.check(f, (9, 8, 7, 3), 9, 8, 7, (((3,),),))\r
- """)\r
-\r
- # Duplicate the tests above, but for lambda. If you add a lambda test,\r
- # also add a similar function test above.\r
-\r
- def test_lambda_parens_no_unpacking(self):\r
- exec textwrap.dedent("""\r
- f = lambda (((((x))))): x\r
- self.check(f, 1, 1)\r
- # Inner parens are elided, same as: f(x,)\r
- f = lambda ((x)),: x\r
- self.check(f, 2, 2)\r
- """)\r
-\r
- def test_lambda_1(self):\r
- exec textwrap.dedent("""\r
- f = lambda (((((x),)))): x\r
- self.check(f, 3, (3,))\r
- f = lambda (((((x)),))): x\r
- self.check(f, 4, (4,))\r
- f = lambda (((((x))),)): x\r
- self.check(f, 5, (5,))\r
- f = lambda (((x),)): x\r
- self.check(f, 6, (6,))\r
- """)\r
-\r
- def test_lambda_2(self):\r
- exec textwrap.dedent("""\r
- f = lambda (((((x)),),)): x\r
- self.check(f, 2, ((2,),))\r
- """)\r
-\r
- def test_lambda_3(self):\r
- exec textwrap.dedent("""\r
- f = lambda ((((((x)),),),)): x\r
- self.check(f, 3, (((3,),),))\r
- """)\r
-\r
- def test_lambda_complex(self):\r
- exec textwrap.dedent("""\r
- f = lambda (((((x)),),),), a, b, c: (x, a, b, c)\r
- self.check(f, (3, 9, 8, 7), (((3,),),), 9, 8, 7)\r
-\r
- f = lambda ((((((x)),)),),), a, b, c: (x, a, b, c)\r
- self.check(f, (3, 9, 8, 7), (((3,),),), 9, 8, 7)\r
-\r
- f = lambda a, b, c, ((((((x)),)),),): (a, b, c, x)\r
- self.check(f, (9, 8, 7, 3), 9, 8, 7, (((3,),),))\r
- """)\r
-\r
-\r
-def test_main():\r
- with test_support.check_py3k_warnings(\r
- ("tuple parameter unpacking has been removed", SyntaxWarning),\r
- ("parenthesized argument names are invalid", SyntaxWarning)):\r
- test_support.run_unittest(ComplexArgsTestCase)\r
-\r
-if __name__ == "__main__":\r
- test_main()\r