@@ -175,81 +175,93 @@ def test_info(config):
175175 assert isinstance (info , str )
176176
177177
178- def test_override_change_type_choices (config ):
178+ def test_override_takes_precedence_over_extend (config ):
179179 config .settings ["override" ] = {
180- "change_type_choices" : [
181- {
182- "value" : "foo" ,
183- "name" : "foo: non standard change" ,
184- "key" : "o" ,
185- }
186- ]
187- }
188-
189- conventional_commits = ConventionalCommitsCz (config )
190- questions = conventional_commits .questions ()
191- change_type_question = next (q for q in questions if q ["name" ] == "prefix" )
192- choices = change_type_question ["choices" ]
193- assert choices == [
194- {
195- "value" : "foo" ,
196- "name" : "foo: non standard change" ,
197- "key" : "o" ,
180+ "bump_map" : {
181+ "^bar" : "PATCH" ,
198182 }
199- ]
200-
201-
202- def test_extend_bump_map_merges (config , monkeypatch ):
203- monkeypatch .setattr (
204- ConventionalCommitsCz , "bump_map" , dict (ConventionalCommitsCz .bump_map )
205- )
183+ }
206184 config .settings ["extend" ] = {
207185 "bump_map" : {
208186 "^foo" : "MINOR" ,
209187 }
210188 }
211189
212190 conventional_commits = ConventionalCommitsCz (config )
213- assert conventional_commits .bump_map ["^foo" ] == "MINOR"
214- assert r"^feat" in conventional_commits .bump_map
191+ assert conventional_commits .bump_map == {"^bar" : "PATCH" }
215192
216193
217- def test_extend_change_type_choices_appends (config , monkeypatch ):
218- monkeypatch .setattr (
219- ConventionalCommitsCz ,
220- "change_type_choices" ,
221- [* ConventionalCommitsCz .change_type_choices ],
222- )
223- config .settings ["extend" ] = {
194+ @pytest .mark .parametrize ("mode" , ["override" , "extend" ])
195+ def test_apply_supported_settings (mode , config ):
196+ config .settings [mode ] = {
197+ "bump_pattern" : r"^foo:" ,
198+ "bump_map" : {r"^foo" : "MINOR" },
199+ "bump_map_major_version_zero" : {r"^foo" : "PATCH" },
200+ "commit_parser" : r"^(?P<change_type>foo):\s(?P<message>.*)$" ,
201+ "changelog_pattern" : r"^(foo)" ,
202+ "change_type_map" : {"foo" : "Foo" },
224203 "change_type_choices" : [
225204 {
226205 "value" : "foo" ,
227- "name" : "foo: non standard change " ,
206+ "name" : "foo: custom type " ,
228207 "key" : "o" ,
229208 }
230- ]
209+ ],
231210 }
232211
233212 conventional_commits = ConventionalCommitsCz (config )
234- questions = conventional_commits .questions ()
235- change_type_question = next (q for q in questions if q ["name" ] == "prefix" )
236- choice_values = {choice ["value" ] for choice in change_type_question ["choices" ]}
237-
238- assert "fix" in choice_values
239- assert "foo" in choice_values
240213
214+ assert conventional_commits .bump_pattern == r"^foo:"
215+ assert (
216+ conventional_commits .commit_parser
217+ == r"^(?P<change_type>foo):\s(?P<message>.*)$"
218+ )
219+ assert conventional_commits .changelog_pattern == r"^(foo)"
241220
242- def test_override_takes_precedence_over_extend (config ):
243- config .settings ["override" ] = {
244- "bump_map" : {
245- "^bar" : "PATCH" ,
246- }
247- }
221+ if mode == "override" :
222+ assert conventional_commits .bump_map == {r"^foo" : "MINOR" }
223+ assert conventional_commits .bump_map_major_version_zero == {r"^foo" : "PATCH" }
224+ assert conventional_commits .change_type_map == {"foo" : "Foo" }
225+ assert conventional_commits .change_type_choices == [
226+ {
227+ "value" : "foo" ,
228+ "name" : "foo: custom type" ,
229+ "key" : "o" ,
230+ }
231+ ]
232+ else :
233+ assert conventional_commits .bump_map [r"^foo" ] == "MINOR"
234+ assert conventional_commits .bump_map_major_version_zero [r"^foo" ] == "PATCH"
235+ assert conventional_commits .change_type_map ["foo" ] == "Foo"
236+ assert r"^feat" in conventional_commits .bump_map
237+ assert any (
238+ choice ["value" ] == "foo"
239+ for choice in conventional_commits .change_type_choices
240+ )
241+ assert any (
242+ choice ["value" ] == "fix"
243+ for choice in conventional_commits .change_type_choices
244+ )
245+
246+
247+ def test_extend_settings_do_not_leak_to_other_instances (config ):
248248 config .settings ["extend" ] = {
249- "bump_map" : {
250- "^foo" : "MINOR" ,
251- }
249+ "bump_map" : {r"^foo" : "MINOR" },
250+ "change_type_choices" : [
251+ {
252+ "value" : "foo" ,
253+ "name" : "foo: custom type" ,
254+ "key" : "o" ,
255+ }
256+ ],
252257 }
258+ first = ConventionalCommitsCz (config )
253259
254- conventional_commits = ConventionalCommitsCz (config )
255- assert conventional_commits .bump_map == {"^bar" : "PATCH" }
260+ clean_config = config .__class__ ()
261+ clean_config .settings .update ({"name" : "cz_conventional_commits" })
262+ second = ConventionalCommitsCz (clean_config )
263+
264+ assert r"^foo" in first .bump_map
265+ assert any (choice ["value" ] == "foo" for choice in first .change_type_choices )
266+ assert r"^foo" not in second .bump_map
267+ assert all (choice ["value" ] != "foo" for choice in second .change_type_choices )
0 commit comments