1414from commitizen .config .yaml_config import YAMLConfig
1515from commitizen .exceptions import ConfigFileIsEmpty , InvalidConfigurationError
1616
17- PYPROJECT = """
17+ TOML_STR = """
1818[tool.commitizen]
1919name = "cz_jira"
2020version = "1.0.0"
3030 "scripts/generate_documentation.sh"
3131]
3232post_bump_hooks = ["scripts/slack_notification.sh"]
33+ """
3334
35+ PYPROJECT = (
36+ TOML_STR
37+ + """
3438[tool.black]
3539line-length = 88
3640target-version = ['py36', 'py37', 'py38']
3741"""
42+ )
43+
3844
3945DICT_CONFIG = {
4046 "commitizen" : {
@@ -198,7 +204,7 @@ def test_load_empty_pyproject_toml_and_cz_toml_with_config(_, tmpdir):
198204 p = tmpdir .join ("pyproject.toml" )
199205 p .write ("" )
200206 p = tmpdir .join (".cz.toml" )
201- p .write (PYPROJECT )
207+ p .write (TOML_STR )
202208
203209 cfg = config .read_cfg ()
204210 assert cfg .settings == _settings
@@ -240,27 +246,25 @@ def test_load_empty_pyproject_toml_from_config_argument(_, tmpdir):
240246
241247class TestWarnMultipleConfigFiles :
242248 @pytest .mark .parametrize (
243- "files,expected_path,should_warn " ,
249+ "files,expected_path" ,
244250 [
245251 # Same directory, different file types
246- ([(".cz.toml" , PYPROJECT ), (".cz.json" , JSON_STR )], ".cz.toml" , True ),
247- ([(".cz.json" , JSON_STR ), (".cz.yaml" , YAML_STR )], ".cz.json" , True ),
248- ([(".cz.toml" , PYPROJECT ), (".cz.yaml" , YAML_STR )], ".cz.toml" , True ),
249- # With pyproject.toml (excluded from warning)
252+ ([(".cz.toml" , TOML_STR ), (".cz.json" , JSON_STR )], ".cz.toml" ),
253+ ([(".cz.json" , JSON_STR ), (".cz.yaml" , YAML_STR )], ".cz.json" ),
254+ ([(".cz.toml" , TOML_STR ), (".cz.yaml" , YAML_STR )], ".cz.toml" ),
255+ # With pyproject.toml
250256 (
251257 [("pyproject.toml" , PYPROJECT ), (".cz.json" , JSON_STR )],
252258 ".cz.json" ,
253- False ,
254259 ),
255260 (
256- [("pyproject.toml" , PYPROJECT ), (".cz.toml" , PYPROJECT )],
261+ [("pyproject.toml" , PYPROJECT ), (".cz.toml" , TOML_STR )],
257262 ".cz.toml" ,
258- False ,
259263 ),
260264 ],
261265 )
262266 def test_warn_multiple_config_files_same_dir (
263- _ , tmpdir , capsys , files , expected_path , should_warn
267+ _ , tmpdir , capsys , files , expected_path
264268 ):
265269 """Test warning when multiple config files exist in same directory."""
266270 with tmpdir .as_cwd ():
@@ -270,27 +274,20 @@ def test_warn_multiple_config_files_same_dir(
270274 cfg = config .read_cfg ()
271275 captured = capsys .readouterr ()
272276
273- if should_warn :
274- assert "Multiple config files detected" in captured .err
275- assert "Using" in captured .err
276- for filename , _ in files :
277- if filename != "pyproject.toml" :
278- assert filename in captured .err
279- else :
280- assert "Multiple config files detected" not in captured .err
277+ assert "Multiple config files detected" in captured .err
278+ for filename , _ in files :
279+ assert filename in captured .err
280+ assert f"Using config file: '{ expected_path } '" in captured .err
281281
282282 assert cfg .path == Path (expected_path )
283- # Verify config loaded correctly (name and version match expected)
284- assert cfg .settings ["name" ] == "cz_jira"
285- assert cfg .settings ["version" ] == "1.0.0"
286283
287284 @pytest .mark .parametrize (
288285 "config_file,content" ,
289286 [
290287 (".cz.json" , JSON_STR ),
291- (".cz.toml" , PYPROJECT ),
288+ (".cz.toml" , TOML_STR ),
292289 (".cz.yaml" , YAML_STR ),
293- ("cz.toml" , PYPROJECT ),
290+ ("cz.toml" , TOML_STR ),
294291 ("cz.json" , JSON_STR ),
295292 ("cz.yaml" , YAML_STR ),
296293 ],
@@ -340,11 +337,11 @@ def test_no_warn_with_explicit_config_path(_, tmpdir, capsys):
340337 [
341338 (file , content , with_git )
342339 for file , content in [
343- (".cz.toml" , PYPROJECT ),
340+ (".cz.toml" , TOML_STR ),
344341 (".cz.json" , JSON_STR ),
345342 (".cz.yaml" , YAML_STR ),
346343 ("pyproject.toml" , PYPROJECT ),
347- ("cz.toml" , PYPROJECT ),
344+ ("cz.toml" , TOML_STR ),
348345 ("cz.json" , JSON_STR ),
349346 ("cz.yaml" , YAML_STR ),
350347 ]
@@ -368,6 +365,18 @@ def test_no_warn_with_single_config_file(
368365 assert "Multiple config files detected" not in captured .err
369366 assert cfg .path == Path (config_file )
370367
368+ def test_no_warn_with_no_commitizen_section_in_pyproject_toml_and_cz_toml (
369+ _ , tmpdir , capsys
370+ ):
371+ with tmpdir .as_cwd ():
372+ tmpdir .join ("pyproject.toml" ).write ("[tool.foo]\n bar = 'baz'" )
373+ tmpdir .join (".cz.toml" ).write (TOML_STR )
374+
375+ cfg = config .read_cfg ()
376+ captured = capsys .readouterr ()
377+ assert "Multiple config files detected" not in captured .err
378+ assert cfg .path == Path (".cz.toml" )
379+
371380
372381@pytest .mark .parametrize (
373382 "config_file, exception_string" ,
0 commit comments