Skip to content

Commit b41d07d

Browse files
vstinneradorilson
authored andcommitted
pythongh-107954: Add PyConfig_MEMBER_BOOL type to PyConfigSpec (python#116359)
_PyConfig_AsDict() now returns bool objects for options using the new PyConfig_MEMBER_BOOL type. Update tests for these changes.
1 parent 00296a6 commit b41d07d

File tree

4 files changed

+213
-191
lines changed

4 files changed

+213
-191
lines changed

Lib/test/_test_embed_set_config.py

+46-32
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,43 @@
1414

1515
MAX_HASH_SEED = 4294967295
1616

17+
18+
BOOL_OPTIONS = [
19+
'isolated',
20+
'use_environment',
21+
'dev_mode',
22+
'install_signal_handlers',
23+
'use_hash_seed',
24+
'faulthandler',
25+
'import_time',
26+
'code_debug_ranges',
27+
'show_ref_count',
28+
'dump_refs',
29+
'malloc_stats',
30+
'parse_argv',
31+
'site_import',
32+
'warn_default_encoding',
33+
'inspect',
34+
'interactive',
35+
'parser_debug',
36+
'write_bytecode',
37+
'quiet',
38+
'user_site_directory',
39+
'configure_c_stdio',
40+
'buffered_stdio',
41+
'use_frozen_modules',
42+
'safe_path',
43+
'pathconfig_warnings',
44+
'module_search_paths_set',
45+
'skip_source_first_line',
46+
'_install_importlib',
47+
'_init_main',
48+
'_is_python_build',
49+
]
50+
if MS_WINDOWS:
51+
BOOL_OPTIONS.append('legacy_windows_stdio')
52+
53+
1754
class SetConfigTests(unittest.TestCase):
1855
def setUp(self):
1956
self.old_config = _testinternalcapi.get_config()
@@ -52,42 +89,15 @@ def test_set_invalid(self):
5289
]
5390

5491
# int (unsigned)
55-
options = [
92+
int_options = [
5693
'_config_init',
57-
'isolated',
58-
'use_environment',
59-
'dev_mode',
60-
'install_signal_handlers',
61-
'use_hash_seed',
62-
'faulthandler',
63-
'tracemalloc',
64-
'import_time',
65-
'code_debug_ranges',
66-
'show_ref_count',
67-
'dump_refs',
68-
'malloc_stats',
69-
'parse_argv',
70-
'site_import',
7194
'bytes_warning',
72-
'inspect',
73-
'interactive',
7495
'optimization_level',
75-
'parser_debug',
76-
'write_bytecode',
96+
'tracemalloc',
7797
'verbose',
78-
'quiet',
79-
'user_site_directory',
80-
'configure_c_stdio',
81-
'buffered_stdio',
82-
'pathconfig_warnings',
83-
'module_search_paths_set',
84-
'skip_source_first_line',
85-
'_install_importlib',
86-
'_init_main',
8798
]
88-
if MS_WINDOWS:
89-
options.append('legacy_windows_stdio')
90-
for key in options:
99+
int_options.extend(BOOL_OPTIONS)
100+
for key in int_options:
91101
value_tests.append((key, invalid_uint))
92102
type_tests.append((key, "abc"))
93103
type_tests.append((key, 2.0))
@@ -148,6 +158,7 @@ def test_set_invalid(self):
148158
_testinternalcapi.set_config(config)
149159

150160
def test_flags(self):
161+
bool_options = set(BOOL_OPTIONS)
151162
for sys_attr, key, value in (
152163
("debug", "parser_debug", 1),
153164
("inspect", "inspect", 2),
@@ -160,7 +171,10 @@ def test_flags(self):
160171
):
161172
with self.subTest(sys=sys_attr, key=key, value=value):
162173
self.set_config(**{key: value, 'parse_argv': 0})
163-
self.assertEqual(getattr(sys.flags, sys_attr), value)
174+
if key in bool_options:
175+
self.assertEqual(getattr(sys.flags, sys_attr), int(bool(value)))
176+
else:
177+
self.assertEqual(getattr(sys.flags, sys_attr), value)
164178

165179
self.set_config(write_bytecode=0)
166180
self.assertEqual(sys.flags.dont_write_bytecode, True)

Lib/test/test_cmd_line.py

+3-5
Original file line numberDiff line numberDiff line change
@@ -634,15 +634,13 @@ def test_sys_flags_set(self):
634634
PYTHONDONTWRITEBYTECODE=value,
635635
PYTHONVERBOSE=value,
636636
)
637-
dont_write_bytecode = int(bool(value))
637+
expected_bool = int(bool(value))
638638
code = (
639639
"import sys; "
640640
"sys.stderr.write(str(sys.flags)); "
641641
f"""sys.exit(not (
642-
sys.flags.debug == sys.flags.optimize ==
643-
sys.flags.verbose ==
644-
{expected}
645-
and sys.flags.dont_write_bytecode == {dont_write_bytecode}
642+
sys.flags.optimize == sys.flags.verbose == {expected}
643+
and sys.flags.debug == sys.flags.dont_write_bytecode == {expected_bool}
646644
))"""
647645
)
648646
with self.subTest(envar_value=value):

0 commit comments

Comments
 (0)