@@ -635,16 +635,19 @@ def check_global_config(self, configs):
635635 self .assertEqual (configs ['global_config' ], expected )
636636
637637 def check_all_configs (self , testname , expected_config = None ,
638- expected_preconfig = None , modify_path_cb = None , stderr = None ,
639- * , api , env = None , ignore_stderr = False , cwd = None ):
638+ expected_preconfig = None , modify_path_cb = None ,
639+ stderr = None , * , api , preconfig_api = None ,
640+ env = None , ignore_stderr = False , cwd = None ):
640641 new_env = remove_python_envvars ()
641642 if env is not None :
642643 new_env .update (env )
643644 env = new_env
644645
645- if api == API_ISOLATED :
646+ if preconfig_api is None :
647+ preconfig_api = api
648+ if preconfig_api == API_ISOLATED :
646649 default_preconfig = self .PRE_CONFIG_ISOLATED
647- elif api == API_PYTHON :
650+ elif preconfig_api == API_PYTHON :
648651 default_preconfig = self .PRE_CONFIG_PYTHON
649652 else :
650653 default_preconfig = self .PRE_CONFIG_COMPAT
@@ -1002,8 +1005,21 @@ def test_init_dont_parse_argv(self):
10021005 self .check_all_configs ("test_init_dont_parse_argv" , config , pre_config ,
10031006 api = API_PYTHON )
10041007
1008+ def default_program_name (self , config ):
1009+ if MS_WINDOWS :
1010+ program_name = 'python'
1011+ executable = self .test_exe
1012+ else :
1013+ program_name = 'python3'
1014+ executable = shutil .which (program_name ) or ''
1015+ config .update ({
1016+ 'program_name' : program_name ,
1017+ 'base_executable' : executable ,
1018+ 'executable' : executable ,
1019+ })
1020+
10051021 def test_init_setpath (self ):
1006- # Test Py_SetProgramName() + Py_SetPath()
1022+ # Test Py_SetPath()
10071023 config = self ._get_expected_config ()
10081024 paths = config ['config' ]['module_search_paths' ]
10091025
@@ -1014,11 +1030,38 @@ def test_init_setpath(self):
10141030 'exec_prefix' : '' ,
10151031 'base_exec_prefix' : '' ,
10161032 }
1033+ self .default_program_name (config )
10171034 env = {'TESTPATH' : os .path .pathsep .join (paths )}
10181035 self .check_all_configs ("test_init_setpath" , config ,
10191036 api = API_COMPAT , env = env ,
10201037 ignore_stderr = True )
10211038
1039+ def test_init_setpath_config (self ):
1040+ # Test Py_SetPath() with PyConfig
1041+ config = self ._get_expected_config ()
1042+ paths = config ['config' ]['module_search_paths' ]
1043+
1044+ config = {
1045+ # set by Py_SetPath()
1046+ 'module_search_paths' : paths ,
1047+ 'prefix' : '' ,
1048+ 'base_prefix' : '' ,
1049+ 'exec_prefix' : '' ,
1050+ 'base_exec_prefix' : '' ,
1051+ # overriden by PyConfig
1052+ 'program_name' : 'conf_program_name' ,
1053+ 'base_executable' : 'conf_executable' ,
1054+ 'executable' : 'conf_executable' ,
1055+ }
1056+ env = {'TESTPATH' : os .path .pathsep .join (paths )}
1057+ # Py_SetPath() preinitialized Python using the compat API,
1058+ # so we need preconfig_api=API_COMPAT.
1059+ self .check_all_configs ("test_init_setpath_config" , config ,
1060+ api = API_PYTHON ,
1061+ preconfig_api = API_COMPAT ,
1062+ env = env ,
1063+ ignore_stderr = True )
1064+
10221065 def module_search_paths (self , prefix = None , exec_prefix = None ):
10231066 config = self ._get_expected_config ()
10241067 if prefix is None :
@@ -1067,8 +1110,7 @@ def tmpdir_with_python(self):
10671110 yield tmpdir
10681111
10691112 def test_init_setpythonhome (self ):
1070- # Test Py_SetPythonHome(home) + PYTHONPATH env var
1071- # + Py_SetProgramName()
1113+ # Test Py_SetPythonHome(home) with PYTHONPATH env var
10721114 config = self ._get_expected_config ()
10731115 paths = config ['config' ]['module_search_paths' ]
10741116 paths_str = os .path .pathsep .join (paths )
@@ -1095,7 +1137,8 @@ def test_init_setpythonhome(self):
10951137 'base_exec_prefix' : exec_prefix ,
10961138 'pythonpath_env' : paths_str ,
10971139 }
1098- env = {'TESTHOME' : home , 'TESTPATH' : paths_str }
1140+ self .default_program_name (config )
1141+ env = {'TESTHOME' : home , 'PYTHONPATH' : paths_str }
10991142 self .check_all_configs ("test_init_setpythonhome" , config ,
11001143 api = API_COMPAT , env = env )
11011144
0 commit comments