summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorVictor Stinner <vstinner@redhat.com>2019-03-26 23:26:18 (GMT)
committerGitHub <noreply@github.com>2019-03-26 23:26:18 (GMT)
commit6da20a49507c46738632baf3e4bfe3bdd086155b (patch)
tree87f5c0c3842b536d2b3c015f1bf4992b1d279f73
parent6cd658b1a5cb2413230dbc2d9395d20498be8518 (diff)
downloadcpython-6da20a49507c46738632baf3e4bfe3bdd086155b.zip
cpython-6da20a49507c46738632baf3e4bfe3bdd086155b.tar.gz
cpython-6da20a49507c46738632baf3e4bfe3bdd086155b.tar.bz2
bpo-36301: Test Python init with isolated (GH-12569)
Add test_preinit_isolated1() and test_preinit_isolated2() test_embed.
-rw-r--r--Lib/test/test_embed.py20
-rw-r--r--Programs/_testembed.c70
2 files changed, 90 insertions, 0 deletions
diff --git a/Lib/test/test_embed.py b/Lib/test/test_embed.py
index 7efd5be..c44d24e 100644
--- a/Lib/test/test_embed.py
+++ b/Lib/test/test_embed.py
@@ -662,6 +662,26 @@ class InitConfigTests(EmbeddingTestsMixin, unittest.TestCase):
}
self.check_config("init_isolated", config, preconfig)
+ def test_preinit_isolated1(self):
+ # _PyPreConfig.isolated=1, _PyCoreConfig.isolated not set
+ preconfig = {}
+ config = {
+ 'isolated': 1,
+ 'use_environment': 0,
+ 'user_site_directory': 0,
+ }
+ self.check_config("preinit_isolated1", config, preconfig)
+
+ def test_preinit_isolated2(self):
+ # _PyPreConfig.isolated=0, _PyCoreConfig.isolated=1
+ preconfig = {}
+ config = {
+ 'isolated': 1,
+ 'use_environment': 0,
+ 'user_site_directory': 0,
+ }
+ self.check_config("preinit_isolated2", config, preconfig)
+
if __name__ == "__main__":
unittest.main()
diff --git a/Programs/_testembed.c b/Programs/_testembed.c
index 7fb0d69..76de8aa 100644
--- a/Programs/_testembed.c
+++ b/Programs/_testembed.c
@@ -648,6 +648,74 @@ static int test_init_isolated(void)
}
+/* _PyPreConfig.isolated=1, _PyCoreConfig.isolated=0 */
+static int test_preinit_isolated1(void)
+{
+ _PyInitError err;
+
+ _PyPreConfig preconfig = _PyPreConfig_INIT;
+
+ /* Set coerce_c_locale and utf8_mode to not depend on the locale */
+ preconfig.coerce_c_locale = 0;
+ preconfig.utf8_mode = 0;
+ preconfig.isolated = 1;
+
+ err = _Py_PreInitializeFromPreConfig(&preconfig);
+ if (_Py_INIT_FAILED(err)) {
+ _Py_ExitInitError(err);
+ }
+
+ _PyCoreConfig config = _PyCoreConfig_INIT;
+ config.program_name = L"./_testembed";
+
+ test_init_env_dev_mode_putenvs();
+ err = _Py_InitializeFromConfig(&config);
+ if (_Py_INIT_FAILED(err)) {
+ _Py_ExitInitError(err);
+ }
+ dump_config();
+ Py_Finalize();
+ return 0;
+}
+
+
+/* _PyPreConfig.isolated=0, _PyCoreConfig.isolated=1 */
+static int test_preinit_isolated2(void)
+{
+ _PyInitError err;
+
+ _PyPreConfig preconfig = _PyPreConfig_INIT;
+
+ /* Set coerce_c_locale and utf8_mode to not depend on the locale */
+ preconfig.coerce_c_locale = 0;
+ preconfig.utf8_mode = 0;
+ preconfig.isolated = 0;
+
+ err = _Py_PreInitializeFromPreConfig(&preconfig);
+ if (_Py_INIT_FAILED(err)) {
+ _Py_ExitInitError(err);
+ }
+
+ /* Test _PyCoreConfig.isolated=1 */
+ _PyCoreConfig config = _PyCoreConfig_INIT;
+
+ Py_IsolatedFlag = 0;
+ config.isolated = 1;
+
+ /* Use path starting with "./" avoids a search along the PATH */
+ config.program_name = L"./_testembed";
+
+ test_init_env_dev_mode_putenvs();
+ err = _Py_InitializeFromConfig(&config);
+ if (_Py_INIT_FAILED(err)) {
+ _Py_ExitInitError(err);
+ }
+ dump_config();
+ Py_Finalize();
+ return 0;
+}
+
+
static int test_init_dev_mode(void)
{
_PyCoreConfig config = _PyCoreConfig_INIT;
@@ -699,6 +767,8 @@ static struct TestCase TestCases[] = {
{ "init_env_dev_mode_alloc", test_init_env_dev_mode_alloc },
{ "init_dev_mode", test_init_dev_mode },
{ "init_isolated", test_init_isolated },
+ { "preinit_isolated1", test_preinit_isolated1 },
+ { "preinit_isolated2", test_preinit_isolated2 },
{ NULL, NULL }
};