Skip to content

refactor(Init): remove the variable values_to_add and the _update_config_file function for readability #1537

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: v4-9-0-test
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
test(Init): improve test coverage on config initialization
  • Loading branch information
bearomorphism committed Jun 11, 2025
commit 9311261ffe30b174f9d0d48fbc44741dd459aaea
63 changes: 63 additions & 0 deletions tests/commands/test_init_command.py
Original file line number Diff line number Diff line change
Expand Up @@ -266,3 +266,66 @@ def test_init_command_shows_description_when_use_help_option(

out, _ = capsys.readouterr()
file_regression.check(out, extension=".txt")


def test_init_configuration_settings(tmpdir, mocker: MockFixture, config):
"""Test that all configuration settings are properly initialized."""
mocker.patch(
"questionary.select",
side_effect=[
FakeQuestion("pyproject.toml"),
FakeQuestion("cz_conventional_commits"),
FakeQuestion("commitizen"),
FakeQuestion("semver"),
],
)
mocker.patch("questionary.confirm", return_value=FakeQuestion(True))
mocker.patch("questionary.text", return_value=FakeQuestion("$version"))
mocker.patch("questionary.checkbox", return_value=FakeQuestion(None))

with tmpdir.as_cwd():
commands.Init(config)()

with open("pyproject.toml", encoding="utf-8") as toml_file:
config_data = toml_file.read()

# Verify all expected settings are present
assert 'name = "cz_conventional_commits"' in config_data
assert 'tag_format = "$version"' in config_data
assert 'version_scheme = "semver"' in config_data
assert 'version = "0.0.1"' in config_data
assert "update_changelog_on_bump = true" in config_data
assert "major_version_zero = true" in config_data


def test_init_configuration_with_version_provider(tmpdir, mocker: MockFixture, config):
"""Test configuration initialization with a different version provider."""
mocker.patch(
"questionary.select",
side_effect=[
FakeQuestion("pyproject.toml"),
FakeQuestion("cz_conventional_commits"),
FakeQuestion("pep621"), # Different version provider
FakeQuestion("semver"),
],
)
mocker.patch("questionary.confirm", return_value=FakeQuestion(True))
mocker.patch("questionary.text", return_value=FakeQuestion("$version"))
mocker.patch("questionary.checkbox", return_value=FakeQuestion(None))

with tmpdir.as_cwd():
commands.Init(config)()

with open("pyproject.toml", encoding="utf-8") as toml_file:
config_data = toml_file.read()

# Verify version provider is set instead of version
assert 'name = "cz_conventional_commits"' in config_data
assert 'tag_format = "$version"' in config_data
assert 'version_scheme = "semver"' in config_data
assert 'version_provider = "pep621"' in config_data
assert "update_changelog_on_bump = true" in config_data
assert "major_version_zero = true" in config_data
assert (
"version = " not in config_data
) # Version should not be set when using version_provider