2014-10-25 17:07:09 -04:00
|
|
|
# test compile builtin
|
|
|
|
|
2014-10-26 11:38:28 -04:00
|
|
|
def have_compile():
|
|
|
|
try:
|
|
|
|
compile
|
|
|
|
return True
|
|
|
|
except NameError:
|
|
|
|
return False
|
|
|
|
|
|
|
|
# global variable for compiled code to access
|
|
|
|
x = 1
|
2014-10-25 17:07:09 -04:00
|
|
|
|
2014-10-26 11:38:28 -04:00
|
|
|
def test():
|
|
|
|
c = compile("print(x)", "file", "exec")
|
|
|
|
|
|
|
|
try:
|
|
|
|
exec(c)
|
|
|
|
except NameError:
|
|
|
|
print("NameError")
|
2014-10-25 17:07:09 -04:00
|
|
|
|
|
|
|
exec(c)
|
|
|
|
|
2014-10-26 11:38:28 -04:00
|
|
|
exec(c, {"x":2})
|
|
|
|
exec(c, {}, {"x":3})
|
2014-10-25 17:07:09 -04:00
|
|
|
|
2014-10-26 11:38:28 -04:00
|
|
|
if have_compile():
|
|
|
|
test()
|
|
|
|
else:
|
|
|
|
print("SKIP")
|