@@ -273,7 +273,6 @@ class InitConfigTests(EmbeddingTestsMixin, unittest.TestCase):
273273 UNTESTED_CORE_CONFIG = (
274274 # FIXME: untested core configuration variables
275275 'dll_path' ,
276- 'executable' ,
277276 'module_search_paths' ,
278277 )
279278 # Mark config which should be get by get_default_config()
@@ -310,7 +309,7 @@ class InitConfigTests(EmbeddingTestsMixin, unittest.TestCase):
310309 'filesystem_errors' : GET_DEFAULT_CONFIG ,
311310
312311 'pycache_prefix' : None ,
313- 'program_name' : './_testembed' ,
312+ 'program_name' : GET_DEFAULT_CONFIG ,
314313 'argv' : ["" ],
315314 'program' : '' ,
316315
@@ -319,6 +318,7 @@ class InitConfigTests(EmbeddingTestsMixin, unittest.TestCase):
319318
320319 'module_search_path_env' : None ,
321320 'home' : None ,
321+ 'executable' : GET_DEFAULT_CONFIG ,
322322
323323 'prefix' : GET_DEFAULT_CONFIG ,
324324 'base_prefix' : GET_DEFAULT_CONFIG ,
@@ -404,7 +404,7 @@ def main_xoptions(self, xoptions_list):
404404 xoptions [opt ] = True
405405 return xoptions
406406
407- def get_expected_config (self , expected , env ):
407+ def get_expected_config (self , expected , env , add_path = None ):
408408 expected = dict (self .DEFAULT_CORE_CONFIG , ** expected )
409409
410410 code = textwrap .dedent ('''
@@ -420,6 +420,7 @@ def get_expected_config(self, expected, env):
420420 'base_exec_prefix': sys.base_exec_prefix,
421421 'filesystem_encoding': sys.getfilesystemencoding(),
422422 'filesystem_errors': sys.getfilesystemencodeerrors(),
423+ 'module_search_paths': sys.path,
423424 }
424425
425426 data = json.dumps(data)
@@ -447,20 +448,38 @@ def get_expected_config(self, expected, env):
447448 except json .JSONDecodeError :
448449 self .fail (f"fail to decode stdout: { stdout !r} " )
449450
451+ if expected ['executable' ] is self .GET_DEFAULT_CONFIG :
452+ if sys .platform == 'win32' :
453+ expected ['executable' ] = self .test_exe
454+ else :
455+ if expected ['program_name' ] is not self .GET_DEFAULT_CONFIG :
456+ expected ['executable' ] = os .path .abspath (expected ['program_name' ])
457+ else :
458+ expected ['executable' ] = os .path .join (os .getcwd (), '_testembed' )
459+ if expected ['program_name' ] is self .GET_DEFAULT_CONFIG :
460+ expected ['program_name' ] = './_testembed'
461+
450462 for key , value in expected .items ():
451463 if value is self .GET_DEFAULT_CONFIG :
452464 expected [key ] = config [key ]
465+ expected ['module_search_paths' ] = config ['module_search_paths' ]
453466 return expected
454467
455468 def check_pre_config (self , config , expected ):
456469 pre_config = dict (config ['pre_config' ])
457470 core_config = dict (config ['core_config' ])
458471 self .assertEqual (pre_config , expected )
459472
460- def check_core_config (self , config , expected ):
473+ def check_core_config (self , config , expected , add_path = None ):
461474 core_config = dict (config ['core_config' ])
475+ if add_path is not None :
476+ paths = [* expected ['module_search_paths' ], add_path ]
477+ if not paths [0 ]:
478+ del paths [0 ]
479+ self .assertEqual (core_config ['module_search_paths' ], paths )
462480 for key in self .UNTESTED_CORE_CONFIG :
463481 core_config .pop (key , None )
482+ expected .pop (key , None )
464483 self .assertEqual (core_config , expected )
465484
466485 def check_global_config (self , config ):
@@ -485,7 +504,7 @@ def check_global_config(self, config):
485504
486505 self .assertEqual (config ['global_config' ], expected )
487506
488- def check_config (self , testname , expected_config , expected_preconfig ):
507+ def check_config (self , testname , expected_config , expected_preconfig , add_path = None ):
489508 env = dict (os .environ )
490509 # Remove PYTHON* environment variables to get deterministic environment
491510 for key in list (env ):
@@ -504,13 +523,13 @@ def check_config(self, testname, expected_config, expected_preconfig):
504523 self .fail (f"fail to decode stdout: { out !r} " )
505524
506525 expected_preconfig = dict (self .DEFAULT_PRE_CONFIG , ** expected_preconfig )
507- expected_config = self .get_expected_config (expected_config , env )
526+ expected_config = self .get_expected_config (expected_config , env , add_path )
508527 for key in self .COPY_PRE_CONFIG :
509528 if key not in expected_preconfig :
510529 expected_preconfig [key ] = expected_config [key ]
511530
512531 self .check_pre_config (config , expected_preconfig )
513- self .check_core_config (config , expected_config )
532+ self .check_core_config (config , expected_config , add_path )
514533 self .check_global_config (config )
515534
516535 def test_init_default_config (self ):
@@ -665,6 +684,15 @@ def test_preinit_isolated2(self):
665684 }
666685 self .check_config ("preinit_isolated2" , config , preconfig )
667686
687+ def test_init_read_set (self ):
688+ preconfig = {}
689+ core_config = {
690+ 'program_name' : './init_read_set' ,
691+ 'executable' : 'my_executable' ,
692+ }
693+ self .check_config ("init_read_set" , core_config , preconfig ,
694+ add_path = "init_read_set_path" )
695+
668696
669697if __name__ == "__main__" :
670698 unittest .main ()
0 commit comments