@@ -471,6 +471,31 @@ class InitConfigTests(EmbeddingTestsMixin, unittest.TestCase):
471471 ('Py_LegacyWindowsStdioFlag' , 'legacy_windows_stdio' ),
472472 ))
473473
474+ # path config
475+ if MS_WINDOWS :
476+ PATH_CONFIG = {
477+ 'isolated' : - 1 ,
478+ 'site_import' : - 1 ,
479+ 'python3_dll' : GET_DEFAULT_CONFIG ,
480+ }
481+ else :
482+ PATH_CONFIG = {}
483+ # other keys are copied by COPY_PATH_CONFIG
484+
485+ COPY_PATH_CONFIG = [
486+ # Copy core config to global config for expected values
487+ 'prefix' ,
488+ 'exec_prefix' ,
489+ 'program_name' ,
490+ 'home' ,
491+ # program_full_path and module_search_path are copied indirectly from
492+ # the core configuration in check_path_config().
493+ ]
494+ if MS_WINDOWS :
495+ COPY_PATH_CONFIG .extend ((
496+ 'base_executable' ,
497+ ))
498+
474499 EXPECTED_CONFIG = None
475500
476501 @classmethod
@@ -535,7 +560,8 @@ def _get_expected_config(self):
535560 configs [config_key ] = config
536561 return configs
537562
538- def get_expected_config (self , expected_preconfig , expected , env , api ,
563+ def get_expected_config (self , expected_preconfig , expected ,
564+ expected_pathconfig , env , api ,
539565 modify_path_cb = None ):
540566 cls = self .__class__
541567 configs = self ._get_expected_config ()
@@ -545,6 +571,11 @@ def get_expected_config(self, expected_preconfig, expected, env, api,
545571 if value is self .GET_DEFAULT_CONFIG :
546572 expected_preconfig [key ] = pre_config [key ]
547573
574+ path_config = configs ['path_config' ]
575+ for key , value in expected_pathconfig .items ():
576+ if value is self .GET_DEFAULT_CONFIG :
577+ expected_pathconfig [key ] = path_config [key ]
578+
548579 if not expected_preconfig ['configure_locale' ] or api == API_COMPAT :
549580 # there is no easy way to get the locale encoding before
550581 # setlocale(LC_CTYPE, "") is called: don't test encodings
@@ -637,8 +668,19 @@ def check_global_config(self, configs):
637668
638669 self .assertEqual (configs ['global_config' ], expected )
639670
671+ def check_path_config (self , configs , expected ):
672+ config = configs ['config' ]
673+
674+ for key in self .COPY_PATH_CONFIG :
675+ expected [key ] = config [key ]
676+ expected ['module_search_path' ] = os .path .pathsep .join (config ['module_search_paths' ])
677+ expected ['program_full_path' ] = config ['executable' ]
678+
679+ self .assertEqual (configs ['path_config' ], expected )
680+
640681 def check_all_configs (self , testname , expected_config = None ,
641- expected_preconfig = None , modify_path_cb = None ,
682+ expected_preconfig = None , expected_pathconfig = None ,
683+ modify_path_cb = None ,
642684 stderr = None , * , api , preconfig_api = None ,
643685 env = None , ignore_stderr = False , cwd = None ):
644686 new_env = remove_python_envvars ()
@@ -657,9 +699,14 @@ def check_all_configs(self, testname, expected_config=None,
657699 if expected_preconfig is None :
658700 expected_preconfig = {}
659701 expected_preconfig = dict (default_preconfig , ** expected_preconfig )
702+
660703 if expected_config is None :
661704 expected_config = {}
662705
706+ if expected_pathconfig is None :
707+ expected_pathconfig = {}
708+ expected_pathconfig = dict (self .PATH_CONFIG , ** expected_pathconfig )
709+
663710 if api == API_PYTHON :
664711 default_config = self .CONFIG_PYTHON
665712 elif api == API_ISOLATED :
@@ -669,7 +716,9 @@ def check_all_configs(self, testname, expected_config=None,
669716 expected_config = dict (default_config , ** expected_config )
670717
671718 self .get_expected_config (expected_preconfig ,
672- expected_config , env ,
719+ expected_config ,
720+ expected_pathconfig ,
721+ env ,
673722 api , modify_path_cb )
674723
675724 out , err = self .run_embedded_interpreter (testname ,
@@ -686,6 +735,7 @@ def check_all_configs(self, testname, expected_config=None,
686735 self .check_pre_config (configs , expected_preconfig )
687736 self .check_config (configs , expected_config )
688737 self .check_global_config (configs )
738+ self .check_path_config (configs , expected_pathconfig )
689739 return configs
690740
691741 def test_init_default_config (self ):
@@ -1258,22 +1308,24 @@ def test_init_pyvenv_cfg(self):
12581308 'executable' : executable ,
12591309 'module_search_paths' : paths ,
12601310 }
1311+ path_config = {}
12611312 if MS_WINDOWS :
12621313 config ['base_prefix' ] = pyvenv_home
12631314 config ['prefix' ] = pyvenv_home
1264- env = self .copy_paths_by_env (config )
1265- actual = self .check_all_configs ("test_init_compat_config" , config ,
1266- api = API_COMPAT , env = env ,
1267- ignore_stderr = True , cwd = tmpdir )
1268- if MS_WINDOWS :
1269- self .assertEqual (
1270- actual ['windows' ]['python3_dll' ],
1271- os .path .join (
1272- tmpdir ,
1273- os .path .basename (self .EXPECTED_CONFIG ['windows' ]['python3_dll' ])
1274- )
1275- )
12761315
1316+ ver = sys .version_info
1317+ dll = f'python{ ver .major } '
1318+ if debug_build (executable ):
1319+ dll += '_d'
1320+ dll += '.DLL'
1321+ dll = os .path .join (os .path .dirname (executable ), dll )
1322+ path_config ['python3_dll' ] = dll
1323+
1324+ env = self .copy_paths_by_env (config )
1325+ self .check_all_configs ("test_init_compat_config" , config ,
1326+ expected_pathconfig = path_config ,
1327+ api = API_COMPAT , env = env ,
1328+ ignore_stderr = True , cwd = tmpdir )
12771329
12781330 def test_global_pathconfig (self ):
12791331 # Test C API functions getting the path configuration:
0 commit comments