1414
1515MAX_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+
1754class 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 )
0 commit comments