blob: 17d35006ea5fc710c9c37151cb1e7d1c9a5730dd [file] [log] [blame]
Fredrik Lundhf7850422001-01-17 21:51:36 +00001from test_support import verbose, TestFailed
Peter Schneider-Kampfdee0f02000-07-25 22:15:45 +00002
3if verbose:
Jeremy Hylton047e2c92001-01-19 03:25:56 +00004 print 'Running tests on argument handling'
Peter Schneider-Kampfdee0f02000-07-25 22:15:45 +00005
6try:
Jeremy Hylton121b6eb2001-02-19 23:53:42 +00007 exec 'def f(a, a): pass'
Peter Schneider-Kampfdee0f02000-07-25 22:15:45 +00008 raise TestFailed, "duplicate arguments"
9except SyntaxError:
10 pass
11
12try:
Jeremy Hylton121b6eb2001-02-19 23:53:42 +000013 exec 'def f(a = 0, a = 1): pass'
Peter Schneider-Kampfdee0f02000-07-25 22:15:45 +000014 raise TestFailed, "duplicate keyword arguments"
15except SyntaxError:
16 pass
Jeremy Hylton047e2c92001-01-19 03:25:56 +000017
18try:
Jeremy Hylton121b6eb2001-02-19 23:53:42 +000019 exec 'def f(a): global a; a = 1'
Jeremy Hylton047e2c92001-01-19 03:25:56 +000020 raise TestFailed, "variable is global and local"
21except SyntaxError:
22 pass
Jeremy Hylton121b6eb2001-02-19 23:53:42 +000023
24print "testing complex args"
25
26def comp_args((a, b)):
Tim Peters0009c4e2001-02-21 07:29:48 +000027 print a,b
Jeremy Hylton121b6eb2001-02-19 23:53:42 +000028
29comp_args((1, 2))
30
31def comp_args((a, b)=(3, 4)):
32 print a, b
33
34comp_args((1, 2))
35comp_args()
36
37def comp_args(a, (b, c)):
38 print a, b, c
39
40comp_args(1, (2, 3))
41
42def comp_args(a=2, (b, c)=(3, 4)):
43 print a, b, c
44
45comp_args(1, (2, 3))
46comp_args()
47
48try:
49 exec 'def f(a=1, (b, c)): pass'
50 raise TestFailed, "non-default args after default"
51except SyntaxError:
52 pass