1 parent 480a7ce commit b2f19b8Copy full SHA for b2f19b8
1 file changed
tests/basics/builtin_compile.py
@@ -1,21 +1,29 @@
1
# test compile builtin
2
3
-try:
4
- compile
5
-except NameError:
6
- print("SKIP")
7
- import sys
8
- sys.exit()
+def have_compile():
+ try:
+ compile
+ return True
+ except NameError:
+ return False
9
+
10
+# global variable for compiled code to access
11
+x = 1
12
-c = compile("print(x)", "file", "exec")
13
+def test():
14
+ c = compile("print(x)", "file", "exec")
15
16
17
+ exec(c)
18
19
+ print("NameError")
20
21
exec(c)
- print("NameError")
22
-x = 1
-exec(c)
23
+ exec(c, {"x":2})
24
+ exec(c, {}, {"x":3})
25
-exec(c, {"x":2})
-exec(c, {}, {"x":3})
26
+if have_compile():
27
+ test()
28
+else:
29
+ print("SKIP")
0 commit comments