@@ -648,6 +648,74 @@ static int test_init_isolated(void)
648648}
649649
650650
651+ /* _PyPreConfig.isolated=1, _PyCoreConfig.isolated=0 */
652+ static int test_preinit_isolated1 (void )
653+ {
654+ _PyInitError err ;
655+
656+ _PyPreConfig preconfig = _PyPreConfig_INIT ;
657+
658+ /* Set coerce_c_locale and utf8_mode to not depend on the locale */
659+ preconfig .coerce_c_locale = 0 ;
660+ preconfig .utf8_mode = 0 ;
661+ preconfig .isolated = 1 ;
662+
663+ err = _Py_PreInitializeFromPreConfig (& preconfig );
664+ if (_Py_INIT_FAILED (err )) {
665+ _Py_ExitInitError (err );
666+ }
667+
668+ _PyCoreConfig config = _PyCoreConfig_INIT ;
669+ config .program_name = L"./_testembed" ;
670+
671+ test_init_env_dev_mode_putenvs ();
672+ err = _Py_InitializeFromConfig (& config );
673+ if (_Py_INIT_FAILED (err )) {
674+ _Py_ExitInitError (err );
675+ }
676+ dump_config ();
677+ Py_Finalize ();
678+ return 0 ;
679+ }
680+
681+
682+ /* _PyPreConfig.isolated=0, _PyCoreConfig.isolated=1 */
683+ static int test_preinit_isolated2 (void )
684+ {
685+ _PyInitError err ;
686+
687+ _PyPreConfig preconfig = _PyPreConfig_INIT ;
688+
689+ /* Set coerce_c_locale and utf8_mode to not depend on the locale */
690+ preconfig .coerce_c_locale = 0 ;
691+ preconfig .utf8_mode = 0 ;
692+ preconfig .isolated = 0 ;
693+
694+ err = _Py_PreInitializeFromPreConfig (& preconfig );
695+ if (_Py_INIT_FAILED (err )) {
696+ _Py_ExitInitError (err );
697+ }
698+
699+ /* Test _PyCoreConfig.isolated=1 */
700+ _PyCoreConfig config = _PyCoreConfig_INIT ;
701+
702+ Py_IsolatedFlag = 0 ;
703+ config .isolated = 1 ;
704+
705+ /* Use path starting with "./" avoids a search along the PATH */
706+ config .program_name = L"./_testembed" ;
707+
708+ test_init_env_dev_mode_putenvs ();
709+ err = _Py_InitializeFromConfig (& config );
710+ if (_Py_INIT_FAILED (err )) {
711+ _Py_ExitInitError (err );
712+ }
713+ dump_config ();
714+ Py_Finalize ();
715+ return 0 ;
716+ }
717+
718+
651719static int test_init_dev_mode (void )
652720{
653721 _PyCoreConfig config = _PyCoreConfig_INIT ;
@@ -699,6 +767,8 @@ static struct TestCase TestCases[] = {
699767 { "init_env_dev_mode_alloc" , test_init_env_dev_mode_alloc },
700768 { "init_dev_mode" , test_init_dev_mode },
701769 { "init_isolated" , test_init_isolated },
770+ { "preinit_isolated1" , test_preinit_isolated1 },
771+ { "preinit_isolated2" , test_preinit_isolated2 },
702772 { NULL , NULL }
703773};
704774
0 commit comments