2424@support .requires_venv_with_pip ()
2525@support .requires_subprocess ()
2626@support .requires_resource ('cpu' )
27- class TestCPPExt (unittest .TestCase ):
27+ class BaseTests :
28+ TEST_INTERNAL_C_API = False
29+
2830 def test_build (self ):
2931 self .check_build ('_testcppext' )
3032
31- def test_build_cpp03 (self ):
32- # In public docs, we say C API is compatible with C++11. However,
33- # in practice we do maintain C++03 compatibility in public headers.
34- # Please ask the C API WG before adding a new C++11-only feature.
35- self .check_build ('_testcpp03ext' , std = 'c++03' )
36-
37- @support .requires_gil_enabled ('incompatible with Free Threading' )
38- def test_build_limited_cpp03 (self ):
39- self .check_build ('_test_limited_cpp03ext' , std = 'c++03' , limited = True )
40-
41- @unittest .skipIf (support .MS_WINDOWS , "MSVC doesn't support /std:c++11" )
42- def test_build_cpp11 (self ):
43- self .check_build ('_testcpp11ext' , std = 'c++11' )
44-
45- # Only test C++14 on MSVC.
46- # On s390x RHEL7, GCC 4.8.5 doesn't support C++14.
47- @unittest .skipIf (not support .MS_WINDOWS , "need Windows" )
48- def test_build_cpp14 (self ):
49- self .check_build ('_testcpp14ext' , std = 'c++14' )
50-
51- @support .requires_gil_enabled ('incompatible with Free Threading' )
52- def test_build_limited (self ):
53- self .check_build ('_testcppext_limited' , limited = True )
54-
5533 def check_build (self , extension_name , std = None , limited = False ):
5634 venv_dir = 'env'
5735 with support .setup_venv_with_pip_setuptools (venv_dir ) as python_exe :
@@ -71,6 +49,7 @@ def run_cmd(operation, cmd):
7149 if limited :
7250 env ['CPYTHON_TEST_LIMITED' ] = '1'
7351 env ['CPYTHON_TEST_EXT_NAME' ] = extension_name
52+ env ['TEST_INTERNAL_C_API' ] = str (int (self .TEST_INTERNAL_C_API ))
7453 if support .verbose :
7554 print ('Run:' , ' ' .join (map (shlex .quote , cmd )))
7655 subprocess .run (cmd , check = True , env = env )
@@ -111,5 +90,35 @@ def run_cmd(operation, cmd):
11190 run_cmd ('Import' , cmd )
11291
11392
93+ class TestPublicCAPI (BaseTests , unittest .TestCase ):
94+ @support .requires_gil_enabled ('incompatible with Free Threading' )
95+ def test_build_limited_cpp03 (self ):
96+ self .check_build ('_test_limited_cpp03ext' , std = 'c++03' , limited = True )
97+
98+ @support .requires_gil_enabled ('incompatible with Free Threading' )
99+ def test_build_limited (self ):
100+ self .check_build ('_testcppext_limited' , limited = True )
101+
102+ def test_build_cpp03 (self ):
103+ # In public docs, we say C API is compatible with C++11. However,
104+ # in practice we do maintain C++03 compatibility in public headers.
105+ # Please ask the C API WG before adding a new C++11-only feature.
106+ self .check_build ('_testcpp03ext' , std = 'c++03' )
107+
108+ @unittest .skipIf (support .MS_WINDOWS , "MSVC doesn't support /std:c++11" )
109+ def test_build_cpp11 (self ):
110+ self .check_build ('_testcpp11ext' , std = 'c++11' )
111+
112+ # Only test C++14 on MSVC.
113+ # On s390x RHEL7, GCC 4.8.5 doesn't support C++14.
114+ @unittest .skipIf (not support .MS_WINDOWS , "need Windows" )
115+ def test_build_cpp14 (self ):
116+ self .check_build ('_testcpp14ext' , std = 'c++14' )
117+
118+
119+ class TestInteralCAPI (BaseTests , unittest .TestCase ):
120+ TEST_INTERNAL_C_API = True
121+
122+
114123if __name__ == "__main__" :
115124 unittest .main ()
0 commit comments