summaryrefslogtreecommitdiffstats
path: root/Lib/test/test_compile.py
blob: 0276ba6bee620fc6ca7005cb711a737f7277ec08 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
from test_support import verbose, TestFailed

if verbose:
    print 'Running tests on argument handling'

try:
    exec 'def f(a, a): pass'
    raise TestFailed, "duplicate arguments"
except SyntaxError:
    pass

try:
    exec 'def f(a = 0, a = 1): pass'
    raise TestFailed, "duplicate keyword arguments"
except SyntaxError:
    pass

try:
    exec 'def f(a): global a; a = 1'
    raise TestFailed, "variable is global and local"
except SyntaxError:
    pass

print "testing complex args"

def comp_args((a, b)):
    print a,b

comp_args((1, 2))

def comp_args((a, b)=(3, 4)):
    print a, b

comp_args((1, 2))
comp_args()

def comp_args(a, (b, c)):
    print a, b, c

comp_args(1, (2, 3))

def comp_args(a=2, (b, c)=(3, 4)):
    print a, b, c

comp_args(1, (2, 3))
comp_args()

try:
    exec 'def f(a=1, (b, c)): pass'
    raise TestFailed, "non-default args after default"
except SyntaxError:
    pass

if verbose:
    print "testing bad float literals"

def expect_error(s):
    try:
        eval(s)
        raise TestFailed("%r accepted" % s)
    except SyntaxError:
        pass

expect_error("2e")
expect_error("2.0e+")
expect_error("1e-")
expect_error("3-4e/21")