@@ -285,6 +285,16 @@ class InitConfigTests(EmbeddingTestsMixin, unittest.TestCase):
285285 'coerce_c_locale_warn' : 0 ,
286286 'utf8_mode' : 0 ,
287287 }
288+ ISOLATED_PRE_CONFIG = dict (DEFAULT_PRE_CONFIG ,
289+ configure_locale = 0 ,
290+ isolated = 1 ,
291+ use_environment = 0 ,
292+ utf8_mode = 0 ,
293+ dev_mode = 0 ,
294+ )
295+ if MS_WINDOWS :
296+ ISOLATED_PRE_CONFIG ['legacy_windows_fs_encoding' ] = 0
297+
288298 COPY_PRE_CONFIG = [
289299 'dev_mode' ,
290300 'isolated' ,
@@ -363,6 +373,24 @@ class InitConfigTests(EmbeddingTestsMixin, unittest.TestCase):
363373 'legacy_windows_stdio' : 0 ,
364374 })
365375
376+ PYTHON_CORE_CONFIG = dict (DEFAULT_CORE_CONFIG ,
377+ configure_c_stdio = 1 ,
378+ parse_argv = 1 ,
379+ )
380+ ISOLATED_CORE_CONFIG = dict (DEFAULT_CORE_CONFIG ,
381+ isolated = 1 ,
382+ use_environment = 0 ,
383+ user_site_directory = 0 ,
384+ dev_mode = 0 ,
385+ install_signal_handlers = 0 ,
386+ use_hash_seed = 0 ,
387+ faulthandler = 0 ,
388+ tracemalloc = 0 ,
389+ pathconfig_warnings = 0 ,
390+ )
391+ if MS_WINDOWS :
392+ ISOLATED_CORE_CONFIG ['legacy_windows_stdio' ] = 0
393+
366394 # global config
367395 DEFAULT_GLOBAL_CONFIG = {
368396 'Py_HasFileSystemDefaultEncoding' : 0 ,
@@ -410,8 +438,15 @@ def main_xoptions(self, xoptions_list):
410438 xoptions [opt ] = True
411439 return xoptions
412440
413- def get_expected_config (self , expected_preconfig , expected , env , add_path = None ):
414- expected = dict (self .DEFAULT_CORE_CONFIG , ** expected )
441+ def get_expected_config (self , expected_preconfig , expected , env , api ,
442+ add_path = None ):
443+ if api == "python" :
444+ default_config = self .PYTHON_CORE_CONFIG
445+ elif api == "isolated" :
446+ default_config = self .ISOLATED_CORE_CONFIG
447+ else :
448+ default_config = self .DEFAULT_CORE_CONFIG
449+ expected = dict (default_config , ** expected )
415450
416451 code = textwrap .dedent ('''
417452 import json
@@ -521,8 +556,8 @@ def check_global_config(self, config):
521556
522557 self .assertEqual (config ['global_config' ], expected )
523558
524- def check_config (self , testname , expected_config , expected_preconfig ,
525- add_path = None , stderr = None ):
559+ def check_config (self , testname , expected_config = None , expected_preconfig = None ,
560+ add_path = None , stderr = None , api = "default" ):
526561 env = dict (os .environ )
527562 # Remove PYTHON* environment variables to get deterministic environment
528563 for key in list (env ):
@@ -533,8 +568,18 @@ def check_config(self, testname, expected_config, expected_preconfig,
533568 env ['PYTHONCOERCECLOCALE' ] = '0'
534569 env ['PYTHONUTF8' ] = '0'
535570
536- expected_preconfig = dict (self .DEFAULT_PRE_CONFIG , ** expected_preconfig )
537- expected_config = self .get_expected_config (expected_preconfig , expected_config , env , add_path )
571+ if api == "isolated" :
572+ default_preconfig = self .ISOLATED_PRE_CONFIG
573+ else :
574+ default_preconfig = self .DEFAULT_PRE_CONFIG
575+ if expected_preconfig is None :
576+ expected_preconfig = {}
577+ expected_preconfig = dict (default_preconfig , ** expected_preconfig )
578+ if expected_config is None :
579+ expected_config = {}
580+ expected_config = self .get_expected_config (expected_preconfig ,
581+ expected_config , env ,
582+ api , add_path )
538583 for key in self .COPY_PRE_CONFIG :
539584 if key not in expected_preconfig :
540585 expected_preconfig [key ] = expected_config [key ]
@@ -677,76 +722,56 @@ def test_init_dev_mode(self):
677722 'dev_mode' : 1 ,
678723 'warnoptions' : ['default' ],
679724 }
680- self .check_config ("init_dev_mode" , config , preconfig )
725+ self .check_config ("init_dev_mode" , config , preconfig , api = "python" )
681726
682727 def test_init_isolated_flag (self ):
683- preconfig = {}
684728 config = {
685729 'isolated' : 1 ,
686730 'use_environment' : 0 ,
687731 'user_site_directory' : 0 ,
688732 }
689- self .check_config ("init_isolated_flag" , config , preconfig )
733+ self .check_config ("init_isolated_flag" , config , api = "python" )
690734
691735 def test_preinit_isolated1 (self ):
692736 # _PyPreConfig.isolated=1, _PyCoreConfig.isolated not set
693- preconfig = {}
694737 config = {
695738 'isolated' : 1 ,
696739 'use_environment' : 0 ,
697740 'user_site_directory' : 0 ,
698741 }
699- self .check_config ("preinit_isolated1" , config , preconfig )
742+ self .check_config ("preinit_isolated1" , config )
700743
701744 def test_preinit_isolated2 (self ):
702745 # _PyPreConfig.isolated=0, _PyCoreConfig.isolated=1
703- preconfig = {}
704746 config = {
705747 'isolated' : 1 ,
706748 'use_environment' : 0 ,
707749 'user_site_directory' : 0 ,
708750 }
709- self .check_config ("preinit_isolated2" , config , preconfig )
751+ self .check_config ("preinit_isolated2" , config )
710752
711753 def test_init_isolated_config (self ):
712- preconfig = {
713- 'configure_locale' : 0 ,
714- }
715- config = {
716- 'isolated' : 1 ,
717- 'use_environment' : 0 ,
718- 'user_site_directory' : 0 ,
719- 'install_signal_handlers' : 0 ,
720- 'pathconfig_warnings' : 0 ,
721- }
722- self .check_config ("init_isolated_config" , config , preconfig )
754+ self .check_config ("init_isolated_config" , api = "isolated" )
723755
724756 def test_init_python_config (self ):
725- preconfig = {}
726- config = {
727- 'configure_c_stdio' : 1 ,
728- 'parse_argv' : 1 ,
729- }
730- self .check_config ("init_python_config" , config , preconfig )
757+ self .check_config ("init_python_config" , api = "python" )
731758
732759 def test_init_dont_configure_locale (self ):
733760 # _PyPreConfig.configure_locale=0
734761 preconfig = {
735762 'configure_locale' : 0 ,
736763 }
737- self .check_config ("init_dont_configure_locale" , {}, preconfig )
764+ self .check_config ("init_dont_configure_locale" , {}, preconfig , api = "python" )
738765
739766 def test_init_read_set (self ):
740- preconfig = {}
741767 core_config = {
742768 'program_name' : './init_read_set' ,
743769 'executable' : 'my_executable' ,
744770 }
745- self .check_config ("init_read_set" , core_config , preconfig ,
771+ self .check_config ("init_read_set" , core_config , api = "python" ,
746772 add_path = "init_read_set_path" )
747773
748774 def test_init_run_main (self ):
749- preconfig = {}
750775 code = ('import _testinternalcapi, json; '
751776 'print(json.dumps(_testinternalcapi.get_configs()))' )
752777 core_config = {
@@ -755,10 +780,9 @@ def test_init_run_main(self):
755780 'run_command' : code + '\n ' ,
756781 'parse_argv' : 1 ,
757782 }
758- self .check_config ("init_run_main" , core_config , preconfig )
783+ self .check_config ("init_run_main" , core_config , api = "python" )
759784
760785 def test_init_main (self ):
761- preconfig = {}
762786 code = ('import _testinternalcapi, json; '
763787 'print(json.dumps(_testinternalcapi.get_configs()))' )
764788 core_config = {
@@ -768,25 +792,26 @@ def test_init_main(self):
768792 'parse_argv' : 1 ,
769793 '_init_main' : 0 ,
770794 }
771- self .check_config ("init_main" , core_config , preconfig ,
795+ self .check_config ("init_main" , core_config , api = "python" ,
772796 stderr = "Run Python code before _Py_InitializeMain" )
773797
774798 def test_init_parse_argv (self ):
775799 core_config = {
800+ 'parse_argv' : 1 ,
776801 'argv' : ['-c' , 'arg1' , '-v' , 'arg3' ],
777802 'program_name' : './argv0' ,
778- 'parse_argv' : 1 ,
779803 'run_command' : 'pass\n ' ,
780804 'use_environment' : 0 ,
781805 }
782- self .check_config ("init_parse_argv" , core_config , {} )
806+ self .check_config ("init_parse_argv" , core_config , api = "python" )
783807
784808 def test_init_dont_parse_argv (self ):
785809 core_config = {
810+ 'parse_argv' : 0 ,
786811 'argv' : ['./argv0' , '-E' , '-c' , 'pass' , 'arg1' , '-v' , 'arg3' ],
787812 'program_name' : './argv0' ,
788813 }
789- self .check_config ("init_dont_parse_argv" , core_config , {} )
814+ self .check_config ("init_dont_parse_argv" , core_config , api = "python" )
790815
791816
792817if __name__ == "__main__" :
0 commit comments