Skip to content

Commit c5f93cb

Browse files
committed
test(Init): improve test coverage on config initialization
1 parent a52d18f commit c5f93cb

File tree

1 file changed

+62
-1
lines changed

1 file changed

+62
-1
lines changed

tests/commands/test_init_command.py

Lines changed: 62 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -299,7 +299,6 @@ def test_init_command_shows_description_when_use_help_option(
299299
out, _ = capsys.readouterr()
300300
file_regression.check(out, extension=".txt")
301301

302-
303302
def test_init_with_confirmed_tag_format(config, mocker: MockFixture, tmpdir):
304303
mocker.patch(
305304
"commitizen.commands.init.get_tag_names", return_value=["v0.0.2", "v0.0.1"]
@@ -420,3 +419,65 @@ def test_init_with_valid_tag_selection(config, mocker: MockFixture, tmpdir):
420419
content = toml_file.read()
421420
assert 'version = "0.9.0"' in content
422421
assert 'version_scheme = "semver"' in content
422+
423+
def test_init_configuration_settings(tmpdir, mocker: MockFixture, config):
424+
"""Test that all configuration settings are properly initialized."""
425+
mocker.patch(
426+
"questionary.select",
427+
side_effect=[
428+
FakeQuestion("pyproject.toml"),
429+
FakeQuestion("cz_conventional_commits"),
430+
FakeQuestion("commitizen"),
431+
FakeQuestion("semver"),
432+
],
433+
)
434+
mocker.patch("questionary.confirm", return_value=FakeQuestion(True))
435+
mocker.patch("questionary.text", return_value=FakeQuestion("$version"))
436+
mocker.patch("questionary.checkbox", return_value=FakeQuestion(None))
437+
438+
with tmpdir.as_cwd():
439+
commands.Init(config)()
440+
441+
with open("pyproject.toml", encoding="utf-8") as toml_file:
442+
config_data = toml_file.read()
443+
444+
# Verify all expected settings are present
445+
assert 'name = "cz_conventional_commits"' in config_data
446+
assert 'tag_format = "$version"' in config_data
447+
assert 'version_scheme = "semver"' in config_data
448+
assert 'version = "0.0.1"' in config_data
449+
assert "update_changelog_on_bump = true" in config_data
450+
assert "major_version_zero = true" in config_data
451+
452+
453+
def test_init_configuration_with_version_provider(tmpdir, mocker: MockFixture, config):
454+
"""Test configuration initialization with a different version provider."""
455+
mocker.patch(
456+
"questionary.select",
457+
side_effect=[
458+
FakeQuestion("pyproject.toml"),
459+
FakeQuestion("cz_conventional_commits"),
460+
FakeQuestion("pep621"), # Different version provider
461+
FakeQuestion("semver"),
462+
],
463+
)
464+
mocker.patch("questionary.confirm", return_value=FakeQuestion(True))
465+
mocker.patch("questionary.text", return_value=FakeQuestion("$version"))
466+
mocker.patch("questionary.checkbox", return_value=FakeQuestion(None))
467+
468+
with tmpdir.as_cwd():
469+
commands.Init(config)()
470+
471+
with open("pyproject.toml", encoding="utf-8") as toml_file:
472+
config_data = toml_file.read()
473+
474+
# Verify version provider is set instead of version
475+
assert 'name = "cz_conventional_commits"' in config_data
476+
assert 'tag_format = "$version"' in config_data
477+
assert 'version_scheme = "semver"' in config_data
478+
assert 'version_provider = "pep621"' in config_data
479+
assert "update_changelog_on_bump = true" in config_data
480+
assert "major_version_zero = true" in config_data
481+
assert (
482+
"version = " not in config_data
483+
) # Version should not be set when using version_provider

0 commit comments

Comments
 (0)