summaryrefslogtreecommitdiffstatshomepage
path: root/tests/basics/builtin_compile.py
blob: ef3ff014d49af580711bfea5a09405582a8d4388 (plain) (blame)
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
# test compile builtin

def have_compile():
    try:
        compile
        return True
    except NameError:
        return False

# global variable for compiled code to access
x = 1

def test():
    c = compile("print(x)", "file", "exec")

    try:
        exec(c)
    except NameError:
        print("NameError")

    exec(c)

    exec(c, {"x":2})
    exec(c, {}, {"x":3})

if have_compile():
    test()
else:
    print("SKIP")