@@ -272,12 +272,19 @@ class InitConfigTests(EmbeddingTestsMixin, unittest.TestCase):
272272 'allocator' : None ,
273273 'coerce_c_locale' : 0 ,
274274 'coerce_c_locale_warn' : 0 ,
275- 'dev_mode' : 0 ,
276- 'isolated' : 0 ,
277- 'use_environment' : 1 ,
278275 'utf8_mode' : 0 ,
279276 }
277+ COPY_PRE_CONFIG = [
278+ 'dev_mode' ,
279+ 'isolated' ,
280+ 'use_environment' ,
281+ ]
282+
280283 DEFAULT_CORE_CONFIG = {
284+ 'isolated' : 0 ,
285+ 'use_environment' : 1 ,
286+ 'dev_mode' : 0 ,
287+
281288 'install_signal_handlers' : 1 ,
282289 'use_hash_seed' : 0 ,
283290 'hash_seed' : 0 ,
@@ -363,8 +370,6 @@ class InitConfigTests(EmbeddingTestsMixin, unittest.TestCase):
363370 '_Py_HasFileSystemDefaultEncodeErrors' : 0 ,
364371 }
365372 COPY_GLOBAL_PRE_CONFIG = [
366- ('Py_IgnoreEnvironmentFlag' , 'use_environment' , True ),
367- ('Py_IsolatedFlag' , 'isolated' ),
368373 ('Py_UTF8Mode' , 'utf8_mode' ),
369374 ]
370375 COPY_GLOBAL_CONFIG = [
@@ -376,8 +381,10 @@ class InitConfigTests(EmbeddingTestsMixin, unittest.TestCase):
376381 ('Py_FileSystemDefaultEncodeErrors' , 'filesystem_errors' ),
377382 ('Py_FileSystemDefaultEncoding' , 'filesystem_encoding' ),
378383 ('Py_FrozenFlag' , '_frozen' ),
384+ ('Py_IgnoreEnvironmentFlag' , 'use_environment' , True ),
379385 ('Py_InspectFlag' , 'inspect' ),
380386 ('Py_InteractiveFlag' , 'interactive' ),
387+ ('Py_IsolatedFlag' , 'isolated' ),
381388 ('Py_NoSiteFlag' , 'site_import' , True ),
382389 ('Py_NoUserSiteDirectory' , 'user_site_directory' , True ),
383390 ('Py_OptimizeFlag' , 'optimization_level' ),
@@ -415,7 +422,7 @@ def check_main_config(self, config):
415422 expected ['xoptions' ] = self .main_xoptions (core_config ['xoptions' ])
416423 self .assertEqual (main_config , expected )
417424
418- def get_expected_config (self , expected , expected_preconfig , env ):
425+ def get_expected_config (self , expected , env ):
419426 expected = dict (self .DEFAULT_CORE_CONFIG , ** expected )
420427
421428 code = textwrap .dedent ('''
@@ -443,7 +450,7 @@ def get_expected_config(self, expected, expected_preconfig, env):
443450 # when test_embed is run from a venv (bpo-35313)
444451 args = (sys .executable , '-S' , '-c' , code )
445452 env = dict (env )
446- if not expected_preconfig ['isolated' ]:
453+ if not expected ['isolated' ]:
447454 env ['PYTHONCOERCECLOCALE' ] = '0'
448455 env ['PYTHONUTF8' ] = '0'
449456 proc = subprocess .run (args , env = env ,
@@ -509,7 +516,10 @@ def check_config(self, testname, expected_config, expected_preconfig):
509516 config = json .loads (out )
510517
511518 expected_preconfig = dict (self .DEFAULT_PRE_CONFIG , ** expected_preconfig )
512- expected_config = self .get_expected_config (expected_config , expected_preconfig , env )
519+ expected_config = self .get_expected_config (expected_config , env )
520+ for key in self .COPY_PRE_CONFIG :
521+ if key not in expected_preconfig :
522+ expected_preconfig [key ] = expected_config [key ]
513523
514524 self .check_core_config (config , expected_config )
515525 self .check_pre_config (config , expected_preconfig )
@@ -617,35 +627,36 @@ def test_init_env(self):
617627
618628 def test_init_env_dev_mode (self ):
619629 preconfig = dict (self .INIT_ENV_PRECONFIG ,
620- allocator = 'debug' ,
621- dev_mode = 1 )
630+ allocator = 'debug' )
622631 config = dict (self .INIT_ENV_CONFIG ,
623632 dev_mode = 1 )
624633 self .check_config ("init_env_dev_mode" , config , preconfig )
625634
626- def test_init_env_dev_mode (self ):
635+ def test_init_env_dev_mode_alloc (self ):
627636 preconfig = dict (self .INIT_ENV_PRECONFIG ,
628- allocator = 'malloc' ,
629- dev_mode = 1 )
630- config = dict ( self . INIT_ENV_CONFIG )
637+ allocator = 'malloc' )
638+ config = dict ( self . INIT_ENV_CONFIG ,
639+ dev_mode = 1 )
631640 self .check_config ("init_env_dev_mode_alloc" , config , preconfig )
632641
633642 def test_init_dev_mode (self ):
634643 preconfig = {
635644 'allocator' : 'debug' ,
636- 'dev_mode' : 1 ,
637645 }
638646 config = {
639647 'faulthandler' : 1 ,
648+ 'dev_mode' : 1 ,
640649 }
641650 self .check_config ("init_dev_mode" , config , preconfig )
642651
643652 def test_init_isolated (self ):
644653 preconfig = {
645- 'isolated' : 1 ,
646- 'use_environment' : 0 ,
654+ 'isolated' : 0 ,
655+ 'use_environment' : 1 ,
647656 }
648657 config = {
658+ 'isolated' : 1 ,
659+ 'use_environment' : 0 ,
649660 'user_site_directory' : 0 ,
650661 }
651662 self .check_config ("init_isolated" , config , preconfig )
0 commit comments