micropython/tests/basics/builtin_compile.py

30 wiersze
432 B
Python
Czysty Zwykły widok Historia

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