@@ -255,35 +255,53 @@ def test_init_with_invalid_config_content(
255
255
config .TomlConfig (data = existing_content , path = path )
256
256
257
257
258
+ @pytest .mark .parametrize (
259
+ "config_file, exception_string" ,
260
+ [
261
+ (".cz.json" , r"\.cz\.json" ),
262
+ ("cz.json" , r"cz\.json" ),
263
+ ],
264
+ ids = [".cz.json" , "cz.json" ],
265
+ )
258
266
class TestJsonConfig :
259
- def test_init_empty_config_content (self , tmpdir ):
260
- path = tmpdir .mkdir ("commitizen" ).join (".cz.json" )
267
+ def test_init_empty_config_content (self , tmpdir , config_file , exception_string ):
268
+ path = tmpdir .mkdir ("commitizen" ).join (config_file )
261
269
json_config = config .JsonConfig (data = "{}" , path = path )
262
270
json_config .init_empty_config_content ()
263
271
264
272
with open (path , encoding = "utf-8" ) as json_file :
265
273
assert json .load (json_file ) == {"commitizen" : {}}
266
274
267
- def test_init_with_invalid_config_content (self , tmpdir ):
275
+ def test_init_with_invalid_config_content (
276
+ self , tmpdir , config_file , exception_string
277
+ ):
268
278
existing_content = "invalid json content"
269
- path = tmpdir .mkdir ("commitizen" ).join (".cz.json" )
279
+ path = tmpdir .mkdir ("commitizen" ).join (config_file )
270
280
271
- with pytest .raises (InvalidConfigurationError , match = r"\.cz\.json" ):
281
+ with pytest .raises (InvalidConfigurationError , match = exception_string ):
272
282
config .JsonConfig (data = existing_content , path = path )
273
283
274
284
285
+ @pytest .mark .parametrize (
286
+ "config_file, exception_string" ,
287
+ [
288
+ (".cz.yaml" , r"\.cz\.yaml" ),
289
+ ("cz.yaml" , r"cz\.yaml" ),
290
+ ],
291
+ ids = [".cz.yaml" , "cz.yaml" ],
292
+ )
275
293
class TestYamlConfig :
276
- def test_init_empty_config_content (self , tmpdir ):
277
- path = tmpdir .mkdir ("commitizen" ).join (".cz.yaml" )
294
+ def test_init_empty_config_content (self , tmpdir , config_file , exception_string ):
295
+ path = tmpdir .mkdir ("commitizen" ).join (config_file )
278
296
yaml_config = config .YAMLConfig (data = "{}" , path = path )
279
297
yaml_config .init_empty_config_content ()
280
298
281
299
with open (path ) as yaml_file :
282
300
assert yaml .safe_load (yaml_file ) == {"commitizen" : {}}
283
301
284
- def test_init_with_invalid_content (self , tmpdir ):
302
+ def test_init_with_invalid_content (self , tmpdir , config_file , exception_string ):
285
303
existing_content = "invalid: .cz.yaml: content: maybe?"
286
- path = tmpdir .mkdir ("commitizen" ).join (".cz.yaml" )
304
+ path = tmpdir .mkdir ("commitizen" ).join (config_file )
287
305
288
- with pytest .raises (InvalidConfigurationError , match = r"\.cz\.yaml" ):
306
+ with pytest .raises (InvalidConfigurationError , match = exception_string ):
289
307
config .YAMLConfig (data = existing_content , path = path )
0 commit comments