38
38
# SOFTWARE.
39
39
40
40
import sys
41
- from . import CPyExtTestCase , CPyExtFunction , CPyExtFunctionOutVars , unhandled_error_compare , GRAALPYTHON
41
+
42
+ from . import CPyExtTestCase , CPyExtFunction , unhandled_error_compare
43
+
42
44
__dir__ = __file__ .rpartition ("/" )[0 ]
43
-
44
- #python_run_test_result = None
45
45
46
- def _reference_run_string (args ):
46
+
47
+ # python_run_test_result = None
48
+
49
+ def _reference_run_string (args ):
47
50
if not isinstance (args [2 ], dict ):
48
51
if sys .version_info .minor >= 6 :
49
52
raise SystemError
50
53
else :
51
54
raise TypeError
52
- if not isinstance (args [3 ], dict ):
55
+ if not isinstance (args [3 ], dict ):
53
56
raise TypeError
54
57
return None
55
58
59
+
56
60
def _run_string_compare (x , y ):
57
61
res = unhandled_error_compare (x , y )
58
- if (isinstance (x , Exception )):
62
+ if (isinstance (x , Exception )):
59
63
return res
60
-
64
+
61
65
global python_run_test_result
62
66
pr = python_run_test_result
63
67
res = res and pr == 42
64
68
python_run_test_result = None
65
69
if not res :
66
70
assert False , "python_run_test_result is %s" % pr
67
71
return res
68
-
72
+
73
+
69
74
class TestPythonRun (CPyExtTestCase ):
70
-
75
+
71
76
def compile_module (self , name ):
72
77
type (self ).mro ()[1 ].__dict__ ["test_%s" % name ].create_module (name )
73
78
super (TestPythonRun , self ).compile_module (name )
74
-
79
+
75
80
test_PyRun_StringFlags = CPyExtFunction (
76
81
_reference_run_string ,
77
82
lambda : (
78
83
("globals().update({'python_run_test_result':42})" , 256 , globals (), locals (), 0 ),
79
- ("globals().update({'python_run_test_result':42})" , 256 , 'globals()' , locals (), 0 ),
80
- ("globals().update({'python_run_test_result':42})" , 256 , globals (), 'locals()' , 0 ),
84
+ ("globals().update({'python_run_test_result':42})" , 256 , 'globals()' , locals (), 0 ),
85
+ ("globals().update({'python_run_test_result':42})" , 256 , globals (), 'locals()' , 0 ),
81
86
),
82
87
resultspec = "O" ,
83
88
argspec = 'siOOk' ,
@@ -117,17 +122,27 @@ def compile_module(self, name):
117
122
258 : "eval"
118
123
}[args [2 ]],
119
124
flags = args [3 ],
120
- optimize = args [4 ],
125
+ _feature_version = args [4 ],
126
+ optimize = args [5 ],
121
127
),
122
128
lambda : (
123
- ("1 + 2" , "foo.py" , 256 , 0 , - 1 ),
124
- ("1 + 2" , "foo.py" , 257 , 0 , 1 ),
125
- ("1 + 2" , "foo.py" , 258 , 0 , 2 ),
126
- ("x = 2" , "foo.py" , 258 , 0 , 0 ),
129
+ ("1 + 2" , "foo.py" , 256 , 0 , 0 , - 1 ),
130
+ ("1 + 2" , "foo.py" , 257 , 0 , 0 , 1 ),
131
+ ("1 + 2" , "foo.py" , 258 , 0 , 0 , 2 ),
132
+ ("x = 2" , "foo.py" , 258 , 0 , 0 , 0 ),
127
133
),
134
+ code = """
135
+ PyObject* wrap_Py_CompileStringExFlags(const char *str, const char *filename_str, int start, int cf_flags,
136
+ int cf_feature_version, int optimize) {
137
+ PyCompilerFlags flags = {cf_flags, cf_feature_version};
138
+ return Py_CompileStringExFlags(str, filename_str, start, &flags, optimize);
139
+ }
140
+ """ ,
141
+ callfunction = 'wrap_Py_CompileStringExFlags' ,
128
142
resultspec = "O" ,
129
- argspec = 'ssiii' ,
130
- arguments = ["char* source" , "char* filename" , "int type" , "PyCompilerFlags* flags" , "int optimize" ],
143
+ argspec = 'ssiiii' ,
144
+ arguments = ["char* source" , "char* filename" , "int type" , "int cf_flags" , "int cf_feature_version" ,
145
+ "int optimize" ],
131
146
cmpfunc = unhandled_error_compare
132
147
)
133
148
@@ -141,16 +156,26 @@ def compile_module(self, name):
141
156
258 : "eval"
142
157
}[args [2 ]],
143
158
flags = args [3 ],
144
- optimize = args [4 ],
159
+ _feature_version = args [4 ],
160
+ optimize = args [5 ],
145
161
),
146
162
lambda : (
147
- ("1 + 2" , "foo.py" , 256 , 0 , - 1 ),
148
- ("1 + 2" , "foo.py" , 257 , 0 , 1 ),
149
- ("1 + 2" , "foo.py" , 258 , 0 , 2 ),
150
- ("x = 2" , "foo.py" , 258 , 0 , 0 ),
163
+ ("1 + 2" , "foo.py" , 256 , 0 , 0 , - 1 ),
164
+ ("1 + 2" , "foo.py" , 257 , 0 , 0 , 1 ),
165
+ ("1 + 2" , "foo.py" , 258 , 0 , 0 , 2 ),
166
+ ("x = 2" , "foo.py" , 258 , 0 , 0 , 0 ),
151
167
),
168
+ code = """
169
+ PyObject* wrap_Py_CompileStringObject(const char *str, PyObject *filename, int start, int cf_flags,
170
+ int cf_feature_version, int optimize) {
171
+ PyCompilerFlags flags = {cf_flags, cf_feature_version};
172
+ return Py_CompileStringObject(str, filename, start, &flags, optimize);
173
+ }
174
+ """ ,
175
+ callfunction = 'wrap_Py_CompileStringObject' ,
152
176
resultspec = "O" ,
153
- argspec = 'sOiii' ,
154
- arguments = ["char* source" , "PyObject* filename" , "int type" , "PyCompilerFlags* flags" , "int optimize" ],
177
+ argspec = 'sOiiii' ,
178
+ arguments = ["char* source" , "PyObject* filename" , "int type" , "int cf_flags" , "int cf_feature_version" ,
179
+ "int optimize" ],
155
180
cmpfunc = unhandled_error_compare
156
181
)
0 commit comments