3 from test
import test_support
5 class ComplexArgsTestCase(unittest
.TestCase
):
7 def check(self
, func
, expected
, *args
):
8 self
.assertEqual(func(*args
), expected
)
10 # These functions are tested below as lambdas too. If you add a function test,
11 # also add a similar lambda test.
13 def test_func_parens_no_unpacking(self
):
14 def f(((((x
))))): return x
16 # Inner parens are elided, same as: f(x,)
17 def f(((x
)),): return x
20 def test_func_1(self
):
21 def f(((((x
),)))): return x
22 self
.check(f
, 3, (3,))
23 def f(((((x
)),))): return x
24 self
.check(f
, 4, (4,))
25 def f(((((x
))),)): return x
26 self
.check(f
, 5, (5,))
27 def f(((x
),)): return x
28 self
.check(f
, 6, (6,))
30 def test_func_2(self
):
31 def f(((((x
)),),)): return x
32 self
.check(f
, 2, ((2,),))
34 def test_func_3(self
):
35 def f((((((x
)),),),)): return x
36 self
.check(f
, 3, (((3,),),))
38 def test_func_complex(self
):
39 def f((((((x
)),),),), a
, b
, c
): return x
, a
, b
, c
40 self
.check(f
, (3, 9, 8, 7), (((3,),),), 9, 8, 7)
42 def f(((((((x
)),)),),), a
, b
, c
): return x
, a
, b
, c
43 self
.check(f
, (3, 9, 8, 7), (((3,),),), 9, 8, 7)
45 def f(a
, b
, c
, ((((((x
)),)),),)): return a
, b
, c
, x
46 self
.check(f
, (9, 8, 7, 3), 9, 8, 7, (((3,),),))
48 # Duplicate the tests above, but for lambda. If you add a lambda test,
49 # also add a similar function test above.
51 def test_lambda_parens_no_unpacking(self
):
52 f
= lambda (((((x
))))): x
54 # Inner parens are elided, same as: f(x,)
58 def test_lambda_1(self
):
59 f
= lambda (((((x
),)))): x
60 self
.check(f
, 3, (3,))
61 f
= lambda (((((x
)),))): x
62 self
.check(f
, 4, (4,))
63 f
= lambda (((((x
))),)): x
64 self
.check(f
, 5, (5,))
65 f
= lambda (((x
),)): x
66 self
.check(f
, 6, (6,))
68 def test_lambda_2(self
):
69 f
= lambda (((((x
)),),)): x
70 self
.check(f
, 2, ((2,),))
72 def test_lambda_3(self
):
73 f
= lambda ((((((x
)),),),)): x
74 self
.check(f
, 3, (((3,),),))
76 def test_lambda_complex(self
):
77 f
= lambda (((((x
)),),),), a
, b
, c
: (x
, a
, b
, c
)
78 self
.check(f
, (3, 9, 8, 7), (((3,),),), 9, 8, 7)
80 f
= lambda ((((((x
)),)),),), a
, b
, c
: (x
, a
, b
, c
)
81 self
.check(f
, (3, 9, 8, 7), (((3,),),), 9, 8, 7)
83 f
= lambda a
, b
, c
, ((((((x
)),)),),): (a
, b
, c
, x
)
84 self
.check(f
, (9, 8, 7, 3), 9, 8, 7, (((3,),),))
88 test_support
.run_unittest(ComplexArgsTestCase
)
90 if __name__
== "__main__":