@@ -269,12 +269,6 @@ class InitConfigTests(EmbeddingTestsMixin, unittest.TestCase):
269
269
maxDiff = 4096
270
270
UTF8_MODE_ERRORS = ('surrogatepass' if MS_WINDOWS else 'surrogateescape' )
271
271
272
- # core config
273
- UNTESTED_CORE_CONFIG = (
274
- # FIXME: untested core configuration variables
275
- 'dll_path' ,
276
- 'module_search_paths' ,
277
- )
278
272
# Mark config which should be get by get_default_config()
279
273
GET_DEFAULT_CONFIG = object ()
280
274
DEFAULT_PRE_CONFIG = {
@@ -324,6 +318,7 @@ class InitConfigTests(EmbeddingTestsMixin, unittest.TestCase):
324
318
'base_prefix' : GET_DEFAULT_CONFIG ,
325
319
'exec_prefix' : GET_DEFAULT_CONFIG ,
326
320
'base_exec_prefix' : GET_DEFAULT_CONFIG ,
321
+ 'module_search_paths' : GET_DEFAULT_CONFIG ,
327
322
328
323
'site_import' : 1 ,
329
324
'bytes_warning' : 0 ,
@@ -354,6 +349,7 @@ class InitConfigTests(EmbeddingTestsMixin, unittest.TestCase):
354
349
'legacy_windows_fs_encoding' : 0 ,
355
350
})
356
351
DEFAULT_CORE_CONFIG .update ({
352
+ 'dll_path' : GET_DEFAULT_CONFIG ,
357
353
'legacy_windows_stdio' : 0 ,
358
354
})
359
355
@@ -410,7 +406,10 @@ def get_expected_config(self, expected, env, add_path=None):
410
406
code = textwrap .dedent ('''
411
407
import json
412
408
import sys
409
+ import _testinternalcapi
413
410
411
+ configs = _testinternalcapi.get_configs()
412
+ core_config = configs['core_config']
414
413
data = {
415
414
'stdio_encoding': sys.stdout.encoding,
416
415
'stdio_errors': sys.stdout.errors,
@@ -420,8 +419,10 @@ def get_expected_config(self, expected, env, add_path=None):
420
419
'base_exec_prefix': sys.base_exec_prefix,
421
420
'filesystem_encoding': sys.getfilesystemencoding(),
422
421
'filesystem_errors': sys.getfilesystemencodeerrors(),
423
- 'module_search_paths': sys.path ,
422
+ 'module_search_paths': core_config['module_search_paths'] ,
424
423
}
424
+ if sys.platform == 'win32':
425
+ data['dll_path'] = core_config['dll_path']
425
426
426
427
data = json.dumps(data)
427
428
data = data.encode('utf-8')
@@ -431,7 +432,7 @@ def get_expected_config(self, expected, env, add_path=None):
431
432
432
433
# Use -S to not import the site module: get the proper configuration
433
434
# when test_embed is run from a venv (bpo-35313)
434
- args = ( sys .executable , '-S' , '-c' , code )
435
+ args = [ sys .executable , '-S' , '-c' , code ]
435
436
env = dict (env )
436
437
if not expected ['isolated' ]:
437
438
env ['PYTHONCOERCECLOCALE' ] = '0'
@@ -462,24 +463,18 @@ def get_expected_config(self, expected, env, add_path=None):
462
463
for key , value in expected .items ():
463
464
if value is self .GET_DEFAULT_CONFIG :
464
465
expected [key ] = config [key ]
465
- expected ['module_search_paths' ] = config ['module_search_paths' ]
466
+
467
+ if add_path is not None :
468
+ expected ['module_search_paths' ].append (add_path )
466
469
return expected
467
470
468
471
def check_pre_config (self , config , expected ):
469
472
pre_config = dict (config ['pre_config' ])
470
473
core_config = dict (config ['core_config' ])
471
474
self .assertEqual (pre_config , expected )
472
475
473
- def check_core_config (self , config , expected , add_path = None ):
476
+ def check_core_config (self , config , expected ):
474
477
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 )
480
- for key in self .UNTESTED_CORE_CONFIG :
481
- core_config .pop (key , None )
482
- expected .pop (key , None )
483
478
self .assertEqual (core_config , expected )
484
479
485
480
def check_global_config (self , config ):
@@ -529,7 +524,7 @@ def check_config(self, testname, expected_config, expected_preconfig, add_path=N
529
524
expected_preconfig [key ] = expected_config [key ]
530
525
531
526
self .check_pre_config (config , expected_preconfig )
532
- self .check_core_config (config , expected_config , add_path )
527
+ self .check_core_config (config , expected_config )
533
528
self .check_global_config (config )
534
529
535
530
def test_init_default_config (self ):
@@ -693,6 +688,18 @@ def test_init_read_set(self):
693
688
self .check_config ("init_read_set" , core_config , preconfig ,
694
689
add_path = "init_read_set_path" )
695
690
691
+ def test_run_main_config (self ):
692
+ preconfig = {}
693
+ code = ('import _testinternalcapi, json; '
694
+ 'print(json.dumps(_testinternalcapi.get_configs()))' )
695
+ core_config = {
696
+ 'argv' : ['-c' , 'arg2' ],
697
+ 'program' : 'python3' ,
698
+ 'program_name' : './python3' ,
699
+ 'run_command' : code + '\n ' ,
700
+ }
701
+ self .check_config ("run_main_config" , core_config , preconfig )
702
+
696
703
697
704
if __name__ == "__main__" :
698
705
unittest .main ()
0 commit comments