Fredrik Lundh | f785042 | 2001-01-17 21:51:36 +0000 | [diff] [blame] | 1 | from test_support import verbose, TestFailed |
Peter Schneider-Kamp | fdee0f0 | 2000-07-25 22:15:45 +0000 | [diff] [blame] | 2 | |
| 3 | if verbose: |
Jeremy Hylton | 047e2c9 | 2001-01-19 03:25:56 +0000 | [diff] [blame] | 4 | print 'Running tests on argument handling' |
Peter Schneider-Kamp | fdee0f0 | 2000-07-25 22:15:45 +0000 | [diff] [blame] | 5 | |
| 6 | try: |
Jeremy Hylton | 121b6eb | 2001-02-19 23:53:42 +0000 | [diff] [blame] | 7 | exec 'def f(a, a): pass' |
Peter Schneider-Kamp | fdee0f0 | 2000-07-25 22:15:45 +0000 | [diff] [blame] | 8 | raise TestFailed, "duplicate arguments" |
| 9 | except SyntaxError: |
| 10 | pass |
| 11 | |
| 12 | try: |
Jeremy Hylton | 121b6eb | 2001-02-19 23:53:42 +0000 | [diff] [blame] | 13 | exec 'def f(a = 0, a = 1): pass' |
Peter Schneider-Kamp | fdee0f0 | 2000-07-25 22:15:45 +0000 | [diff] [blame] | 14 | raise TestFailed, "duplicate keyword arguments" |
| 15 | except SyntaxError: |
| 16 | pass |
Jeremy Hylton | 047e2c9 | 2001-01-19 03:25:56 +0000 | [diff] [blame] | 17 | |
| 18 | try: |
Jeremy Hylton | 121b6eb | 2001-02-19 23:53:42 +0000 | [diff] [blame] | 19 | exec 'def f(a): global a; a = 1' |
Jeremy Hylton | 047e2c9 | 2001-01-19 03:25:56 +0000 | [diff] [blame] | 20 | raise TestFailed, "variable is global and local" |
| 21 | except SyntaxError: |
| 22 | pass |
Jeremy Hylton | 121b6eb | 2001-02-19 23:53:42 +0000 | [diff] [blame] | 23 | |
| 24 | print "testing complex args" |
| 25 | |
| 26 | def comp_args((a, b)): |
Tim Peters | 0009c4e | 2001-02-21 07:29:48 +0000 | [diff] [blame] | 27 | print a,b |
Jeremy Hylton | 121b6eb | 2001-02-19 23:53:42 +0000 | [diff] [blame] | 28 | |
| 29 | comp_args((1, 2)) |
| 30 | |
| 31 | def comp_args((a, b)=(3, 4)): |
| 32 | print a, b |
| 33 | |
| 34 | comp_args((1, 2)) |
| 35 | comp_args() |
| 36 | |
| 37 | def comp_args(a, (b, c)): |
| 38 | print a, b, c |
| 39 | |
| 40 | comp_args(1, (2, 3)) |
| 41 | |
| 42 | def comp_args(a=2, (b, c)=(3, 4)): |
| 43 | print a, b, c |
| 44 | |
| 45 | comp_args(1, (2, 3)) |
| 46 | comp_args() |
| 47 | |
| 48 | try: |
| 49 | exec 'def f(a=1, (b, c)): pass' |
| 50 | raise TestFailed, "non-default args after default" |
| 51 | except SyntaxError: |
| 52 | pass |