summaryrefslogtreecommitdiffstats
path: root/Lib/test/test_embed.py
diff options
context:
space:
mode:
authorVictor Stinner <vstinner@redhat.com>2019-05-17 20:44:16 (GMT)
committerGitHub <noreply@github.com>2019-05-17 20:44:16 (GMT)
commitbcfbbd704646622e919c1306a91fba61d603483d (patch)
tree51238f56ba837c49330424bd995b2de71b5a5a48 /Lib/test/test_embed.py
parent98ff4d5fb6a9d01b0176b7786db61346952e5295 (diff)
downloadcpython-bcfbbd704646622e919c1306a91fba61d603483d.zip
cpython-bcfbbd704646622e919c1306a91fba61d603483d.tar.gz
cpython-bcfbbd704646622e919c1306a91fba61d603483d.tar.bz2
bpo-36945: Add _PyPreConfig.configure_locale (GH-13368)
_PyPreConfig_InitIsolatedConfig() sets configure_locale to 0 to prevent Python to modify the LC_CTYPE locale. In that case, coerce_c_locale an coerce_c_locale_warn are set to 0 as well.
Diffstat (limited to 'Lib/test/test_embed.py')
-rw-r--r--Lib/test/test_embed.py34
1 files changed, 30 insertions, 4 deletions
diff --git a/Lib/test/test_embed.py b/Lib/test/test_embed.py
index 50badd8..c389df8 100644
--- a/Lib/test/test_embed.py
+++ b/Lib/test/test_embed.py
@@ -272,10 +272,15 @@ class InitConfigTests(EmbeddingTestsMixin, unittest.TestCase):
maxDiff = 4096
UTF8_MODE_ERRORS = ('surrogatepass' if MS_WINDOWS else 'surrogateescape')
- # Mark config which should be get by get_default_config()
+ # Marker to read the default configuration: get_default_config()
GET_DEFAULT_CONFIG = object()
+
+ # Marker to ignore a configuration parameter
+ IGNORE_CONFIG = object()
+
DEFAULT_PRE_CONFIG = {
'allocator': PYMEM_ALLOCATOR_NOT_SET,
+ 'configure_locale': 1,
'coerce_c_locale': 0,
'coerce_c_locale_warn': 0,
'utf8_mode': 0,
@@ -405,7 +410,7 @@ class InitConfigTests(EmbeddingTestsMixin, unittest.TestCase):
xoptions[opt] = True
return xoptions
- def get_expected_config(self, expected, env, add_path=None):
+ def get_expected_config(self, expected_preconfig, expected, env, add_path=None):
expected = dict(self.DEFAULT_CORE_CONFIG, **expected)
code = textwrap.dedent('''
@@ -471,6 +476,14 @@ class InitConfigTests(EmbeddingTestsMixin, unittest.TestCase):
if add_path is not None:
expected['module_search_paths'].append(add_path)
+
+ if not expected_preconfig['configure_locale']:
+ # there is no easy way to get the locale encoding before
+ # setlocale(LC_CTYPE, "") is called: don't test encodings
+ for key in ('filesystem_encoding', 'filesystem_errors',
+ 'stdio_encoding', 'stdio_errors'):
+ expected[key] = self.IGNORE_CONFIG
+
return expected
def check_pre_config(self, config, expected):
@@ -480,6 +493,10 @@ class InitConfigTests(EmbeddingTestsMixin, unittest.TestCase):
def check_core_config(self, config, expected):
core_config = dict(config['core_config'])
+ for key, value in list(expected.items()):
+ if value is self.IGNORE_CONFIG:
+ del core_config[key]
+ del expected[key]
self.assertEqual(core_config, expected)
def check_global_config(self, config):
@@ -517,7 +534,7 @@ class InitConfigTests(EmbeddingTestsMixin, unittest.TestCase):
env['PYTHONUTF8'] = '0'
expected_preconfig = dict(self.DEFAULT_PRE_CONFIG, **expected_preconfig)
- expected_config = self.get_expected_config(expected_config, env, add_path)
+ expected_config = self.get_expected_config(expected_preconfig, expected_config, env, add_path)
for key in self.COPY_PRE_CONFIG:
if key not in expected_preconfig:
expected_preconfig[key] = expected_config[key]
@@ -692,7 +709,9 @@ class InitConfigTests(EmbeddingTestsMixin, unittest.TestCase):
self.check_config("preinit_isolated2", config, preconfig)
def test_init_isolated_config(self):
- preconfig = {}
+ preconfig = {
+ 'configure_locale': 0,
+ }
config = {
'isolated': 1,
'use_environment': 0,
@@ -710,6 +729,13 @@ class InitConfigTests(EmbeddingTestsMixin, unittest.TestCase):
}
self.check_config("init_python_config", config, preconfig)
+ def test_init_dont_configure_locale(self):
+ # _PyPreConfig.configure_locale=0
+ preconfig = {
+ 'configure_locale': 0,
+ }
+ self.check_config("init_dont_configure_locale", {}, preconfig)
+
def test_init_read_set(self):
preconfig = {}
core_config = {