FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

gh-107954: Add PyConfig_MEMBER_BOOL type to PyConfigSpec by vstinner · Pull Request #116359 · python/cpython · GitHub

/ cpython Public
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension .c  (1) .py  (2) All 2 file types selected
Viewed files
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Unified
Split
Hide whitespace
Diff view
Unified
Split
Hide whitespace
Next Next commit
gh-107954: Add PyConfig_MEMBER_BOOL type to PyConfigSpec
_PyConfig_AsDict() now returns bool objects for options using the new
PyConfig_MEMBER_BOOL type.

Update tests for these changes.
  • Loading branch information
vstinner committed Mar 5, 2024
commit 87faddec75d9cd8454e2a037ad97bed3f5a64952
78 changes: 46 additions & 32 deletions Lib/test/_test_embed_set_config.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,44 @@

MAX_HASH_SEED = 4294967295


BOOL_OPTIONS = [
'isolated',
'use_environment',
'dev_mode',
'install_signal_handlers',
'use_hash_seed',
'faulthandler',
'tracemalloc',
'import_time',
'code_debug_ranges',
'show_ref_count',
'dump_refs',
'malloc_stats',
'parse_argv',
'site_import',
'warn_default_encoding',
'inspect',
'interactive',
'parser_debug',
'write_bytecode',
'quiet',
'user_site_directory',
'configure_c_stdio',
'buffered_stdio',
'use_frozen_modules',
'safe_path',
'pathconfig_warnings',
'module_search_paths_set',
'skip_source_first_line',
'_install_importlib',
'_init_main',
'_is_python_build',
]
if MS_WINDOWS:
BOOL_OPTIONS.append('legacy_windows_stdio')


class SetConfigTests(unittest.TestCase):
def setUp(self):
self.old_config = _testinternalcapi.get_config()
Expand Down Expand Up @@ -52,42 +90,14 @@ def test_set_invalid(self):
]

# int (unsigned)
options = [
int_options = [
'_config_init',
'isolated',
'use_environment',
'dev_mode',
'install_signal_handlers',
'use_hash_seed',
'faulthandler',
'tracemalloc',
'import_time',
'code_debug_ranges',
'show_ref_count',
'dump_refs',
'malloc_stats',
'parse_argv',
'site_import',
'bytes_warning',
'inspect',
'interactive',
'optimization_level',
'parser_debug',
'write_bytecode',
'verbose',
'quiet',
'user_site_directory',
'configure_c_stdio',
'buffered_stdio',
'pathconfig_warnings',
'module_search_paths_set',
'skip_source_first_line',
'_install_importlib',
'_init_main',
]
if MS_WINDOWS:
options.append('legacy_windows_stdio')
for key in options:
int_options.extend(BOOL_OPTIONS)
for key in int_options:
value_tests.append((key, invalid_uint))
type_tests.append((key, "abc"))
type_tests.append((key, 2.0))
Expand Down Expand Up @@ -148,6 +158,7 @@ def test_set_invalid(self):
_testinternalcapi.set_config(config)

def test_flags(self):
bool_options = set(BOOL_OPTIONS)
for sys_attr, key, value in (
("debug", "parser_debug", 1),
("inspect", "inspect", 2),
Expand All @@ -160,7 +171,10 @@ def test_flags(self):
):
with self.subTest(sys=sys_attr, key=key, value=value):
self.set_config(**{key: value, 'parse_argv': 0})
self.assertEqual(getattr(sys.flags, sys_attr), value)
if key in bool_options:
self.assertEqual(getattr(sys.flags, sys_attr), int(bool(value)))
else:
self.assertEqual(getattr(sys.flags, sys_attr), value)

self.set_config(write_bytecode=0)
self.assertEqual(sys.flags.dont_write_bytecode, True)
Expand Down
Loading

Back | FazBrowse Home | New Git URL