Skip to content

Commit 5edcf26

Browse files
authored
bpo-36763: Rename private Python initialization functions (GH-13511)
* Rename private C functions: * _Py_Initialize_ReconfigureCore => pyinit_core_reconfigure * _Py_InitializeCore_impl => pyinit_core_config * _Py_InitializeCore = > pyinit_core * _Py_InitializeMainInterpreter => pyinit_main * init_python => pyinit_python * Rename _testembed.c commands: add "test_" prefix.
1 parent cfb241b commit 5edcf26

File tree

3 files changed

+117
-122
lines changed

3 files changed

+117
-122
lines changed

Lib/test/test_embed.py

Lines changed: 34 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ def run_embedded_interpreter(self, *args, env=None):
8282
return out, err
8383

8484
def run_repeated_init_and_subinterpreters(self):
85-
out, err = self.run_embedded_interpreter("repeated_init_and_subinterpreters")
85+
out, err = self.run_embedded_interpreter("test_repeated_init_and_subinterpreters")
8686
self.assertEqual(err, "")
8787

8888
# The output from _testembed looks like this:
@@ -172,7 +172,7 @@ def test_subinterps_distinct_state(self):
172172
def test_forced_io_encoding(self):
173173
# Checks forced configuration of embedded interpreter IO streams
174174
env = dict(os.environ, PYTHONIOENCODING="utf-8:surrogateescape")
175-
out, err = self.run_embedded_interpreter("forced_io_encoding", env=env)
175+
out, err = self.run_embedded_interpreter("test_forced_io_encoding", env=env)
176176
if support.verbose > 1:
177177
print()
178178
print(out)
@@ -218,7 +218,7 @@ def test_pre_initialization_api(self):
218218
is initialized (via Py_Initialize()).
219219
"""
220220
env = dict(os.environ, PYTHONPATH=os.pathsep.join(sys.path))
221-
out, err = self.run_embedded_interpreter("pre_initialization_api", env=env)
221+
out, err = self.run_embedded_interpreter("test_pre_initialization_api", env=env)
222222
if MS_WINDOWS:
223223
expected_path = self.test_exe
224224
else:
@@ -234,7 +234,7 @@ def test_pre_initialization_sys_options(self):
234234
"""
235235
env = dict(os.environ, PYTHONPATH=os.pathsep.join(sys.path))
236236
out, err = self.run_embedded_interpreter(
237-
"pre_initialization_sys_options", env=env)
237+
"test_pre_initialization_sys_options", env=env)
238238
expected_output = (
239239
"sys.warnoptions: ['once', 'module', 'default']\n"
240240
"sys._xoptions: {'not_an_option': '1', 'also_not_an_option': '2'}\n"
@@ -249,7 +249,7 @@ def test_bpo20891(self):
249249
calling PyEval_InitThreads() must not crash. PyGILState_Ensure() must
250250
call PyEval_InitThreads() for us in this case.
251251
"""
252-
out, err = self.run_embedded_interpreter("bpo20891")
252+
out, err = self.run_embedded_interpreter("test_bpo20891")
253253
self.assertEqual(out, '')
254254
self.assertEqual(err, '')
255255

@@ -258,20 +258,20 @@ def test_initialize_twice(self):
258258
bpo-33932: Calling Py_Initialize() twice should do nothing (and not
259259
crash!).
260260
"""
261-
out, err = self.run_embedded_interpreter("initialize_twice")
261+
out, err = self.run_embedded_interpreter("test_initialize_twice")
262262
self.assertEqual(out, '')
263263
self.assertEqual(err, '')
264264

265265
def test_initialize_pymain(self):
266266
"""
267267
bpo-34008: Calling Py_Main() after Py_Initialize() must not fail.
268268
"""
269-
out, err = self.run_embedded_interpreter("initialize_pymain")
269+
out, err = self.run_embedded_interpreter("test_initialize_pymain")
270270
self.assertEqual(out.rstrip(), "Py_Main() after Py_Initialize: sys.argv=['-c', 'arg2']")
271271
self.assertEqual(err, '')
272272

273273
def test_run_main(self):
274-
out, err = self.run_embedded_interpreter("run_main")
274+
out, err = self.run_embedded_interpreter("test_run_main")
275275
self.assertEqual(out.rstrip(), "_Py_RunMain(): sys.argv=['-c', 'arg2']")
276276
self.assertEqual(err, '')
277277

@@ -632,13 +632,13 @@ def check_config(self, testname, expected_config=None,
632632
self.check_global_config(config)
633633

634634
def test_init_default_config(self):
635-
self.check_config("init_initialize_config", api=API_COMPAT)
635+
self.check_config("test_init_initialize_config", api=API_COMPAT)
636636

637637
def test_preinit_compat_config(self):
638-
self.check_config("preinit_compat_config", api=API_COMPAT)
638+
self.check_config("test_preinit_compat_config", api=API_COMPAT)
639639

640640
def test_init_compat_config(self):
641-
self.check_config("init_compat_config", api=API_COMPAT)
641+
self.check_config("test_init_compat_config", api=API_COMPAT)
642642

643643
def test_init_global_config(self):
644644
preconfig = {
@@ -660,7 +660,7 @@ def test_init_global_config(self):
660660
'user_site_directory': 0,
661661
'pathconfig_warnings': 0,
662662
}
663-
self.check_config("init_global_config", config, preconfig,
663+
self.check_config("test_init_global_config", config, preconfig,
664664
api=API_COMPAT)
665665

666666
def test_init_from_config(self):
@@ -705,7 +705,7 @@ def test_init_from_config(self):
705705
'check_hash_pycs_mode': 'always',
706706
'pathconfig_warnings': 0,
707707
}
708-
self.check_config("init_from_config", config, preconfig,
708+
self.check_config("test_init_from_config", config, preconfig,
709709
api=API_COMPAT)
710710

711711
def test_init_env(self):
@@ -732,23 +732,23 @@ def test_init_env(self):
732732
'faulthandler': 1,
733733
'warnoptions': ['EnvVar'],
734734
}
735-
self.check_config("init_env", config, preconfig,
735+
self.check_config("test_init_env", config, preconfig,
736736
api=API_COMPAT)
737737

738738
def test_init_env_dev_mode(self):
739739
preconfig = dict(allocator=PYMEM_ALLOCATOR_DEBUG)
740740
config = dict(dev_mode=1,
741741
faulthandler=1,
742742
warnoptions=['default'])
743-
self.check_config("init_env_dev_mode", config, preconfig,
743+
self.check_config("test_init_env_dev_mode", config, preconfig,
744744
api=API_COMPAT)
745745

746746
def test_init_env_dev_mode_alloc(self):
747747
preconfig = dict(allocator=PYMEM_ALLOCATOR_MALLOC)
748748
config = dict(dev_mode=1,
749749
faulthandler=1,
750750
warnoptions=['default'])
751-
self.check_config("init_env_dev_mode_alloc", config, preconfig,
751+
self.check_config("test_init_env_dev_mode_alloc", config, preconfig,
752752
api=API_COMPAT)
753753

754754
def test_init_dev_mode(self):
@@ -760,7 +760,7 @@ def test_init_dev_mode(self):
760760
'dev_mode': 1,
761761
'warnoptions': ['default'],
762762
}
763-
self.check_config("init_dev_mode", config, preconfig,
763+
self.check_config("test_init_dev_mode", config, preconfig,
764764
api=API_PYTHON)
765765

766766
def test_preinit_parse_argv(self):
@@ -777,7 +777,7 @@ def test_preinit_parse_argv(self):
777777
'warnoptions': ['default'],
778778
'xoptions': ['dev'],
779779
}
780-
self.check_config("preinit_parse_argv", config, preconfig,
780+
self.check_config("test_preinit_parse_argv", config, preconfig,
781781
api=API_PYTHON)
782782

783783
def test_preinit_dont_parse_argv(self):
@@ -790,7 +790,7 @@ def test_preinit_dont_parse_argv(self):
790790
"-X", "dev", "-X", "utf8", "script.py"],
791791
'isolated': 0,
792792
}
793-
self.check_config("preinit_dont_parse_argv", config, preconfig,
793+
self.check_config("test_preinit_dont_parse_argv", config, preconfig,
794794
api=API_ISOLATED)
795795

796796
def test_init_isolated_flag(self):
@@ -799,7 +799,7 @@ def test_init_isolated_flag(self):
799799
'use_environment': 0,
800800
'user_site_directory': 0,
801801
}
802-
self.check_config("init_isolated_flag", config, api=API_PYTHON)
802+
self.check_config("test_init_isolated_flag", config, api=API_PYTHON)
803803

804804
def test_preinit_isolated1(self):
805805
# _PyPreConfig.isolated=1, _PyCoreConfig.isolated not set
@@ -808,7 +808,7 @@ def test_preinit_isolated1(self):
808808
'use_environment': 0,
809809
'user_site_directory': 0,
810810
}
811-
self.check_config("preinit_isolated1", config, api=API_COMPAT)
811+
self.check_config("test_preinit_isolated1", config, api=API_COMPAT)
812812

813813
def test_preinit_isolated2(self):
814814
# _PyPreConfig.isolated=0, _PyCoreConfig.isolated=1
@@ -817,32 +817,35 @@ def test_preinit_isolated2(self):
817817
'use_environment': 0,
818818
'user_site_directory': 0,
819819
}
820-
self.check_config("preinit_isolated2", config, api=API_COMPAT)
820+
self.check_config("test_preinit_isolated2", config, api=API_COMPAT)
821821

822822
def test_preinit_isolated_config(self):
823-
self.check_config("preinit_isolated_config", api=API_ISOLATED)
823+
self.check_config("test_preinit_isolated_config", api=API_ISOLATED)
824824

825825
def test_init_isolated_config(self):
826-
self.check_config("init_isolated_config", api=API_ISOLATED)
826+
self.check_config("test_init_isolated_config", api=API_ISOLATED)
827+
828+
def test_preinit_python_config(self):
829+
self.check_config("test_preinit_python_config", api=API_PYTHON)
827830

828831
def test_init_python_config(self):
829-
self.check_config("init_python_config", api=API_PYTHON)
832+
self.check_config("test_init_python_config", api=API_PYTHON)
830833

831834
def test_init_dont_configure_locale(self):
832835
# _PyPreConfig.configure_locale=0
833836
preconfig = {
834837
'configure_locale': 0,
835838
'coerce_c_locale': 0,
836839
}
837-
self.check_config("init_dont_configure_locale", {}, preconfig,
840+
self.check_config("test_init_dont_configure_locale", {}, preconfig,
838841
api=API_PYTHON)
839842

840843
def test_init_read_set(self):
841844
core_config = {
842845
'program_name': './init_read_set',
843846
'executable': 'my_executable',
844847
}
845-
self.check_config("init_read_set", core_config,
848+
self.check_config("test_init_read_set", core_config,
846849
api=API_PYTHON,
847850
add_path="init_read_set_path")
848851

@@ -855,7 +858,7 @@ def test_init_run_main(self):
855858
'run_command': code + '\n',
856859
'parse_argv': 1,
857860
}
858-
self.check_config("init_run_main", core_config, api=API_PYTHON)
861+
self.check_config("test_init_run_main", core_config, api=API_PYTHON)
859862

860863
def test_init_main(self):
861864
code = ('import _testinternalcapi, json; '
@@ -867,7 +870,7 @@ def test_init_main(self):
867870
'parse_argv': 1,
868871
'_init_main': 0,
869872
}
870-
self.check_config("init_main", core_config,
873+
self.check_config("test_init_main", core_config,
871874
api=API_PYTHON,
872875
stderr="Run Python code before _Py_InitializeMain")
873876

@@ -879,7 +882,7 @@ def test_init_parse_argv(self):
879882
'run_command': 'pass\n',
880883
'use_environment': 0,
881884
}
882-
self.check_config("init_parse_argv", core_config, api=API_PYTHON)
885+
self.check_config("test_init_parse_argv", core_config, api=API_PYTHON)
883886

884887
def test_init_dont_parse_argv(self):
885888
pre_config = {
@@ -890,7 +893,7 @@ def test_init_dont_parse_argv(self):
890893
'argv': ['./argv0', '-E', '-c', 'pass', 'arg1', '-v', 'arg3'],
891894
'program_name': './argv0',
892895
}
893-
self.check_config("init_dont_parse_argv", core_config, pre_config,
896+
self.check_config("test_init_dont_parse_argv", core_config, pre_config,
894897
api=API_PYTHON)
895898

896899

Programs/_testembed.c

Lines changed: 33 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1243,39 +1243,39 @@ struct TestCase
12431243
};
12441244

12451245
static struct TestCase TestCases[] = {
1246-
{ "forced_io_encoding", test_forced_io_encoding },
1247-
{ "repeated_init_and_subinterpreters", test_repeated_init_and_subinterpreters },
1248-
{ "pre_initialization_api", test_pre_initialization_api },
1249-
{ "pre_initialization_sys_options", test_pre_initialization_sys_options },
1250-
{ "bpo20891", test_bpo20891 },
1251-
{ "initialize_twice", test_initialize_twice },
1252-
{ "initialize_pymain", test_initialize_pymain },
1253-
{ "init_initialize_config", test_init_initialize_config },
1254-
{ "preinit_compat_config", test_preinit_compat_config },
1255-
{ "init_compat_config", test_init_compat_config },
1256-
{ "init_global_config", test_init_global_config },
1257-
{ "init_from_config", test_init_from_config },
1258-
{ "init_parse_argv", test_init_parse_argv },
1259-
{ "init_dont_parse_argv", test_init_dont_parse_argv },
1260-
{ "init_env", test_init_env },
1261-
{ "init_env_dev_mode", test_init_env_dev_mode },
1262-
{ "init_env_dev_mode_alloc", test_init_env_dev_mode_alloc },
1263-
{ "init_dont_configure_locale", test_init_dont_configure_locale },
1264-
{ "init_dev_mode", test_init_dev_mode },
1265-
{ "init_isolated_flag", test_init_isolated_flag },
1266-
{ "preinit_isolated_config", test_preinit_isolated_config },
1267-
{ "init_isolated_config", test_init_isolated_config },
1268-
{ "preinit_python_config", test_preinit_python_config },
1269-
{ "init_python_config", test_init_python_config },
1270-
{ "preinit_isolated1", test_preinit_isolated1 },
1271-
{ "preinit_isolated2", test_preinit_isolated2 },
1272-
{ "preinit_parse_argv", test_preinit_parse_argv },
1273-
{ "preinit_dont_parse_argv", test_preinit_dont_parse_argv },
1274-
{ "init_read_set", test_init_read_set },
1275-
{ "init_run_main", test_init_run_main },
1276-
{ "init_main", test_init_main },
1277-
{ "run_main", test_run_main },
1278-
{ NULL, NULL }
1246+
{"test_forced_io_encoding", test_forced_io_encoding},
1247+
{"test_repeated_init_and_subinterpreters", test_repeated_init_and_subinterpreters},
1248+
{"test_pre_initialization_api", test_pre_initialization_api},
1249+
{"test_pre_initialization_sys_options", test_pre_initialization_sys_options},
1250+
{"test_bpo20891", test_bpo20891},
1251+
{"test_initialize_twice", test_initialize_twice},
1252+
{"test_initialize_pymain", test_initialize_pymain},
1253+
{"test_init_initialize_config", test_init_initialize_config},
1254+
{"test_preinit_compat_config", test_preinit_compat_config},
1255+
{"test_init_compat_config", test_init_compat_config},
1256+
{"test_init_global_config", test_init_global_config},
1257+
{"test_init_from_config", test_init_from_config},
1258+
{"test_init_parse_argv", test_init_parse_argv},
1259+
{"test_init_dont_parse_argv", test_init_dont_parse_argv},
1260+
{"test_init_env", test_init_env},
1261+
{"test_init_env_dev_mode", test_init_env_dev_mode},
1262+
{"test_init_env_dev_mode_alloc", test_init_env_dev_mode_alloc},
1263+
{"test_init_dont_configure_locale", test_init_dont_configure_locale},
1264+
{"test_init_dev_mode", test_init_dev_mode},
1265+
{"test_init_isolated_flag", test_init_isolated_flag},
1266+
{"test_preinit_isolated_config", test_preinit_isolated_config},
1267+
{"test_init_isolated_config", test_init_isolated_config},
1268+
{"test_preinit_python_config", test_preinit_python_config},
1269+
{"test_init_python_config", test_init_python_config},
1270+
{"test_preinit_isolated1", test_preinit_isolated1},
1271+
{"test_preinit_isolated2", test_preinit_isolated2},
1272+
{"test_preinit_parse_argv", test_preinit_parse_argv},
1273+
{"test_preinit_dont_parse_argv", test_preinit_dont_parse_argv},
1274+
{"test_init_read_set", test_init_read_set},
1275+
{"test_init_run_main", test_init_run_main},
1276+
{"test_init_main", test_init_main},
1277+
{"test_run_main", test_run_main},
1278+
{NULL, NULL}
12791279
};
12801280

12811281
int main(int argc, char *argv[])

0 commit comments

Comments
 (0)