23
23
from utils import run_command , command_stdout
24
24
25
25
26
- # C++ is only supported on Python 3.6 and newer
27
- TEST_CPP = (sys .version_info >= (3 , 6 ))
26
+ TESTS = [
27
+ ("test_pythoncapi_compat_cext" , "C" ),
28
+ ("test_pythoncapi_compat_cppext" , "C++" ),
29
+ ("test_pythoncapi_compat_cpp03ext" , "C++03" ),
30
+ ("test_pythoncapi_compat_cpp11ext" , "C++11" ),
31
+ ]
32
+
28
33
VERBOSE = False
29
34
30
35
@@ -42,15 +47,10 @@ def display_title(title):
42
47
43
48
44
49
def build_ext ():
45
- if TEST_CPP :
46
- display_title ("Build the C and C++ extensions" )
47
- else :
48
- display_title ("Build the C extension" )
50
+ display_title ("Build test extensions" )
49
51
if os .path .exists ("build" ):
50
52
shutil .rmtree ("build" )
51
53
cmd = [sys .executable , "setup.py" , "build" ]
52
- if TEST_CPP :
53
- cmd .append ('--build-cppext' )
54
54
if VERBOSE :
55
55
run_command (cmd )
56
56
print ()
@@ -98,15 +98,42 @@ def _check_refleak(test_func, verbose):
98
98
raise AssertionError ("refcnt leak, diff: %s" % diff )
99
99
100
100
101
- def run_tests (module_name ):
102
- if "cppext" in module_name :
103
- lang = "C++"
101
+ def python_version ():
102
+ ver = sys .version_info
103
+ build = 'debug' if hasattr (sys , 'gettotalrefcount' ) else 'release'
104
+ if hasattr (sys , 'implementation' ):
105
+ python_impl = sys .implementation .name
106
+ if python_impl == 'cpython' :
107
+ python_impl = 'CPython'
108
+ elif python_impl == 'pypy' :
109
+ python_impl = 'PyPy'
104
110
else :
105
- lang = "C"
111
+ if "PyPy" in sys .version :
112
+ python_impl = "PyPy"
113
+ else :
114
+ python_impl = 'Python'
115
+ return "%s %s.%s (%s build)" % (python_impl , ver .major , ver .minor , build )
116
+
117
+
118
+ def run_tests (module_name , lang ):
106
119
title = "Test %s (%s)" % (module_name , lang )
107
120
display_title (title )
108
121
109
- testmod = import_tests (module_name )
122
+ try :
123
+ testmod = import_tests (module_name )
124
+ except ImportError :
125
+ # The C extension must always be available
126
+ if lang == "C" :
127
+ raise
128
+
129
+ if VERBOSE :
130
+ print ("%s: skip %s, missing %s extension"
131
+ % (python_version (), lang , module_name ))
132
+ print ()
133
+ return
134
+
135
+ if VERBOSE and hasattr (testmod , "__cplusplus" ):
136
+ print ("__cplusplus: %s" % testmod .__cplusplus )
110
137
111
138
check_refleak = hasattr (sys , 'gettotalrefcount' )
112
139
@@ -125,21 +152,8 @@ def test_func():
125
152
if VERBOSE :
126
153
print ()
127
154
128
- ver = sys .version_info
129
- build = 'debug' if hasattr (sys , 'gettotalrefcount' ) else 'release'
130
155
msg = "%s %s tests succeeded!" % (len (tests ), lang )
131
- if hasattr (sys , 'implementation' ):
132
- python_impl = sys .implementation .name
133
- if python_impl == 'cpython' :
134
- python_impl = 'CPython'
135
- elif python_impl == 'pypy' :
136
- python_impl = 'PyPy'
137
- else :
138
- if "PyPy" in sys .version :
139
- python_impl = "PyPy"
140
- else :
141
- python_impl = 'Python'
142
- msg = "%s %s.%s (%s build): %s" % (python_impl , ver .major , ver .minor , build , msg )
156
+ msg = "%s: %s" % (python_version (), msg )
143
157
if check_refleak :
144
158
msg = "%s (no reference leak detected)" % msg
145
159
print (msg )
@@ -150,9 +164,8 @@ def main():
150
164
VERBOSE = ("-v" in sys .argv [1 :] or "--verbose" in sys .argv [1 :])
151
165
152
166
# Implementing PyFrame_GetLocals() and PyCode_GetCode() require the
153
- # internal C API in Python 3.11 alpha versions. Skip also Python 3.11b1
154
- # which has issues with C++ casts: _Py_CAST() macro.
155
- if 0x30b0000 <= sys .hexversion <= 0x30b00b1 :
167
+ # internal C API in Python 3.11 alpha versions.
168
+ if 0x30b0000 <= sys .hexversion < 0x30b00b1 :
156
169
version = sys .version .split ()[0 ]
157
170
print ("SKIP TESTS: Python %s is not supported" % version )
158
171
return
@@ -166,9 +179,8 @@ def main():
166
179
167
180
build_ext ()
168
181
169
- run_tests ("test_pythoncapi_compat_cext" )
170
- if TEST_CPP :
171
- run_tests ("test_pythoncapi_compat_cppext" )
182
+ for module_name , lang in TESTS :
183
+ run_tests (module_name , lang )
172
184
173
185
174
186
if __name__ == "__main__" :
0 commit comments