1
- """Unit tests for flake8.options.config.MergedConfigParser ."""
1
+ """Unit tests for flake8.options.config.ConfigParser ."""
2
2
import os
3
3
from unittest import mock
4
4
@@ -32,7 +32,7 @@ def test_parse_cli_config(optmanager, config_finder):
32
32
"--ignore" , parse_from_config = True , comma_separated_list = True
33
33
)
34
34
optmanager .add_option ("--quiet" , parse_from_config = True , action = "count" )
35
- parser = config .MergedConfigParser (optmanager , config_finder )
35
+ parser = config .ConfigParser (optmanager , config_finder )
36
36
37
37
config_file = "tests/fixtures/config_files/cli-specified.ini"
38
38
parsed_config = parser .parse_cli_config (config_file )
@@ -61,41 +61,11 @@ def test_is_configured_by(
61
61
):
62
62
"""Verify the behaviour of the is_configured_by method."""
63
63
parsed_config , _ = config .ConfigFileFinder ._read_config (filename )
64
- parser = config .MergedConfigParser (optmanager , config_finder )
64
+ parser = config .ConfigParser (optmanager , config_finder )
65
65
66
66
assert parser .is_configured_by (parsed_config ) is is_configured_by
67
67
68
68
69
- def test_parse_user_config (optmanager , config_finder ):
70
- """Verify parsing of user config files."""
71
- optmanager .add_option (
72
- "--exclude" ,
73
- parse_from_config = True ,
74
- comma_separated_list = True ,
75
- normalize_paths = True ,
76
- )
77
- optmanager .add_option (
78
- "--ignore" , parse_from_config = True , comma_separated_list = True
79
- )
80
- optmanager .add_option ("--quiet" , parse_from_config = True , action = "count" )
81
- parser = config .MergedConfigParser (optmanager , config_finder )
82
-
83
- config_finder .user_config_file = (
84
- "tests/fixtures/config_files/" "cli-specified.ini"
85
- )
86
- parsed_config = parser .parse_user_config ()
87
-
88
- assert parsed_config == {
89
- "ignore" : ["E123" , "W234" , "E111" ],
90
- "exclude" : [
91
- os .path .abspath ("foo/" ),
92
- os .path .abspath ("bar/" ),
93
- os .path .abspath ("bogus/" ),
94
- ],
95
- "quiet" : 1 ,
96
- }
97
-
98
-
99
69
def test_parse_local_config (optmanager , config_finder ):
100
70
"""Verify parsing of local config files."""
101
71
optmanager .add_option (
@@ -108,7 +78,7 @@ def test_parse_local_config(optmanager, config_finder):
108
78
"--ignore" , parse_from_config = True , comma_separated_list = True
109
79
)
110
80
optmanager .add_option ("--quiet" , parse_from_config = True , action = "count" )
111
- parser = config .MergedConfigParser (optmanager , config_finder )
81
+ parser = config .ConfigParser (optmanager , config_finder )
112
82
113
83
with mock .patch .object (config_finder , "local_config_files" ) as localcfs :
114
84
localcfs .return_value = [
@@ -127,47 +97,14 @@ def test_parse_local_config(optmanager, config_finder):
127
97
}
128
98
129
99
130
- def test_merge_user_and_local_config (optmanager , config_finder ):
131
- """Verify merging of parsed user and local config files."""
132
- optmanager .add_option (
133
- "--exclude" ,
134
- parse_from_config = True ,
135
- comma_separated_list = True ,
136
- normalize_paths = True ,
137
- )
138
- optmanager .add_option (
139
- "--ignore" , parse_from_config = True , comma_separated_list = True
140
- )
141
- optmanager .add_option (
142
- "--select" , parse_from_config = True , comma_separated_list = True
143
- )
144
- parser = config .MergedConfigParser (optmanager , config_finder )
145
-
146
- with mock .patch .object (config_finder , "local_config_files" ) as localcfs :
147
- localcfs .return_value = [
148
- "tests/fixtures/config_files/local-config.ini"
149
- ]
150
- config_finder .user_config_file = (
151
- "tests/fixtures/config_files/" "user-config.ini"
152
- )
153
- parsed_config = parser .merge_user_and_local_config ()
154
-
155
- assert parsed_config == {
156
- "exclude" : [os .path .abspath ("docs/" )],
157
- "ignore" : ["D203" ],
158
- "select" : ["E" , "W" , "F" ],
159
- }
160
-
161
-
162
100
def test_parse_isolates_config (optmanager ):
163
101
"""Verify behaviour of the parse method with isolated=True."""
164
102
config_finder = mock .MagicMock ()
165
103
config_finder .ignore_config_files = True
166
- parser = config .MergedConfigParser (optmanager , config_finder )
104
+ parser = config .ConfigParser (optmanager , config_finder )
167
105
168
106
assert parser .parse () == {}
169
107
assert config_finder .local_configs .called is False
170
- assert config_finder .user_config .called is False
171
108
172
109
173
110
def test_parse_uses_cli_config (optmanager ):
@@ -176,7 +113,7 @@ def test_parse_uses_cli_config(optmanager):
176
113
config_finder = mock .MagicMock ()
177
114
config_finder .config_file = config_file_value
178
115
config_finder .ignore_config_files = False
179
- parser = config .MergedConfigParser (optmanager , config_finder )
116
+ parser = config .ConfigParser (optmanager , config_finder )
180
117
181
118
parser .parse ()
182
119
config_finder .cli_config .assert_called_once_with (config_file_value )
@@ -206,13 +143,11 @@ def test_parsed_configs_are_equivalent(
206
143
optmanager .add_option (
207
144
"--ignore" , parse_from_config = True , comma_separated_list = True
208
145
)
209
- parser = config .MergedConfigParser (optmanager , config_finder )
146
+ parser = config .ConfigParser (optmanager , config_finder )
210
147
211
148
with mock .patch .object (config_finder , "local_config_files" ) as localcfs :
212
149
localcfs .return_value = [config_fixture_path ]
213
- with mock .patch .object (config_finder , "user_config_file" ) as usercf :
214
- usercf .return_value = ""
215
- parsed_config = parser .merge_user_and_local_config ()
150
+ parsed_config = parser .parse ()
216
151
217
152
assert parsed_config ["ignore" ] == ["E123" , "W234" , "E111" ]
218
153
assert parsed_config ["exclude" ] == [
@@ -243,13 +178,11 @@ def test_parsed_hyphenated_and_underscored_names(
243
178
parse_from_config = True ,
244
179
comma_separated_list = True ,
245
180
)
246
- parser = config .MergedConfigParser (optmanager , config_finder )
181
+ parser = config .ConfigParser (optmanager , config_finder )
247
182
248
183
with mock .patch .object (config_finder , "local_config_files" ) as localcfs :
249
184
localcfs .return_value = [config_file ]
250
- with mock .patch .object (config_finder , "user_config_file" ) as usercf :
251
- usercf .return_value = ""
252
- parsed_config = parser .merge_user_and_local_config ()
185
+ parsed_config = parser .parse ()
253
186
254
187
assert parsed_config ["max_line_length" ] == 110
255
188
assert parsed_config ["enable_extensions" ] == ["H101" , "H235" ]
0 commit comments