1212from test import support
1313
1414
15- SOURCE = os .path .join (os .path .dirname (__file__ ), 'extension.c' )
15+ SOURCES = [
16+ os .path .join (os .path .dirname (__file__ ), 'extension.c' ),
17+ ]
1618SETUP = os .path .join (os .path .dirname (__file__ ), 'setup.py' )
1719
1820
2830@support .requires_venv_with_pip ()
2931@support .requires_subprocess ()
3032@support .requires_resource ('cpu' )
31- class TestExt (unittest .TestCase ):
33+ class BaseTests :
34+ TEST_INTERNAL_C_API = False
35+
3236 # Default build with no options
3337 def test_build (self ):
3438 self .check_build ('_test_cext' )
3539
36- def test_build_c11 (self ):
37- self .check_build ('_test_c11_cext' , std = 'c11' )
38-
39- @unittest .skipIf (support .MS_WINDOWS , "MSVC doesn't support /std:c99" )
40- def test_build_c99 (self ):
41- # In public docs, we say C API is compatible with C11. However,
42- # in practice we do maintain C99 compatibility in public headers.
43- # Please ask the C API WG before adding a new C11-only feature.
44- self .check_build ('_test_c99_cext' , std = 'c99' )
45-
46- @support .requires_gil_enabled ('incompatible with Free Threading' )
47- def test_build_limited (self ):
48- self .check_build ('_test_limited_cext' , limited = True )
49-
50- @support .requires_gil_enabled ('broken for now with Free Threading' )
51- def test_build_limited_c11 (self ):
52- self .check_build ('_test_limited_c11_cext' , limited = True , std = 'c11' )
53-
5440 def check_build (self , extension_name , std = None , limited = False ):
5541 venv_dir = 'env'
5642 with support .setup_venv_with_pip_setuptools (venv_dir ) as python_exe :
@@ -61,7 +47,9 @@ def _check_build(self, extension_name, python_exe, std, limited):
6147 pkg_dir = 'pkg'
6248 os .mkdir (pkg_dir )
6349 shutil .copy (SETUP , os .path .join (pkg_dir , os .path .basename (SETUP )))
64- shutil .copy (SOURCE , os .path .join (pkg_dir , os .path .basename (SOURCE )))
50+ for source in SOURCES :
51+ dest = os .path .join (pkg_dir , os .path .basename (source ))
52+ shutil .copy (source , dest )
6553
6654 def run_cmd (operation , cmd ):
6755 env = os .environ .copy ()
@@ -70,6 +58,7 @@ def run_cmd(operation, cmd):
7058 if limited :
7159 env ['CPYTHON_TEST_LIMITED' ] = '1'
7260 env ['CPYTHON_TEST_EXT_NAME' ] = extension_name
61+ env ['TEST_INTERNAL_C_API' ] = str (int (self .TEST_INTERNAL_C_API ))
7362 if support .verbose :
7463 print ('Run:' , ' ' .join (map (shlex .quote , cmd )))
7564 subprocess .run (cmd , check = True , env = env )
@@ -110,5 +99,29 @@ def run_cmd(operation, cmd):
11099 run_cmd ('Import' , cmd )
111100
112101
102+ class TestPublicCAPI (BaseTests , unittest .TestCase ):
103+ @support .requires_gil_enabled ('incompatible with Free Threading' )
104+ def test_build_limited (self ):
105+ self .check_build ('_test_limited_cext' , limited = True )
106+
107+ @support .requires_gil_enabled ('broken for now with Free Threading' )
108+ def test_build_limited_c11 (self ):
109+ self .check_build ('_test_limited_c11_cext' , limited = True , std = 'c11' )
110+
111+ def test_build_c11 (self ):
112+ self .check_build ('_test_c11_cext' , std = 'c11' )
113+
114+ @unittest .skipIf (support .MS_WINDOWS , "MSVC doesn't support /std:c99" )
115+ def test_build_c99 (self ):
116+ # In public docs, we say C API is compatible with C11. However,
117+ # in practice we do maintain C99 compatibility in public headers.
118+ # Please ask the C API WG before adding a new C11-only feature.
119+ self .check_build ('_test_c99_cext' , std = 'c99' )
120+
121+
122+ class TestInteralCAPI (BaseTests , unittest .TestCase ):
123+ TEST_INTERNAL_C_API = True
124+
125+
113126if __name__ == "__main__" :
114127 unittest .main ()
0 commit comments