14
14
15
15
MAX_HASH_SEED = 4294967295
16
16
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
+
17
54
class SetConfigTests (unittest .TestCase ):
18
55
def setUp (self ):
19
56
self .old_config = _testinternalcapi .get_config ()
@@ -52,42 +89,15 @@ def test_set_invalid(self):
52
89
]
53
90
54
91
# int (unsigned)
55
- options = [
92
+ int_options = [
56
93
'_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' ,
71
94
'bytes_warning' ,
72
- 'inspect' ,
73
- 'interactive' ,
74
95
'optimization_level' ,
75
- 'parser_debug' ,
76
- 'write_bytecode' ,
96
+ 'tracemalloc' ,
77
97
'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' ,
87
98
]
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 :
91
101
value_tests .append ((key , invalid_uint ))
92
102
type_tests .append ((key , "abc" ))
93
103
type_tests .append ((key , 2.0 ))
@@ -148,6 +158,7 @@ def test_set_invalid(self):
148
158
_testinternalcapi .set_config (config )
149
159
150
160
def test_flags (self ):
161
+ bool_options = set (BOOL_OPTIONS )
151
162
for sys_attr , key , value in (
152
163
("debug" , "parser_debug" , 1 ),
153
164
("inspect" , "inspect" , 2 ),
@@ -160,7 +171,10 @@ def test_flags(self):
160
171
):
161
172
with self .subTest (sys = sys_attr , key = key , value = value ):
162
173
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 )
164
178
165
179
self .set_config (write_bytecode = 0 )
166
180
self .assertEqual (sys .flags .dont_write_bytecode , True )
0 commit comments