Skip to content

Commit 9311261

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

File tree

1 file changed

+63
-0
lines changed

1 file changed

+63
-0
lines changed

tests/commands/test_init_command.py

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -266,3 +266,66 @@ def test_init_command_shows_description_when_use_help_option(
266266

267267
out, _ = capsys.readouterr()
268268
file_regression.check(out, extension=".txt")
269+
270+
271+
def test_init_configuration_settings(tmpdir, mocker: MockFixture, config):
272+
"""Test that all configuration settings are properly initialized."""
273+
mocker.patch(
274+
"questionary.select",
275+
side_effect=[
276+
FakeQuestion("pyproject.toml"),
277+
FakeQuestion("cz_conventional_commits"),
278+
FakeQuestion("commitizen"),
279+
FakeQuestion("semver"),
280+
],
281+
)
282+
mocker.patch("questionary.confirm", return_value=FakeQuestion(True))
283+
mocker.patch("questionary.text", return_value=FakeQuestion("$version"))
284+
mocker.patch("questionary.checkbox", return_value=FakeQuestion(None))
285+
286+
with tmpdir.as_cwd():
287+
commands.Init(config)()
288+
289+
with open("pyproject.toml", encoding="utf-8") as toml_file:
290+
config_data = toml_file.read()
291+
292+
# Verify all expected settings are present
293+
assert 'name = "cz_conventional_commits"' in config_data
294+
assert 'tag_format = "$version"' in config_data
295+
assert 'version_scheme = "semver"' in config_data
296+
assert 'version = "0.0.1"' in config_data
297+
assert "update_changelog_on_bump = true" in config_data
298+
assert "major_version_zero = true" in config_data
299+
300+
301+
def test_init_configuration_with_version_provider(tmpdir, mocker: MockFixture, config):
302+
"""Test configuration initialization with a different version provider."""
303+
mocker.patch(
304+
"questionary.select",
305+
side_effect=[
306+
FakeQuestion("pyproject.toml"),
307+
FakeQuestion("cz_conventional_commits"),
308+
FakeQuestion("pep621"), # Different version provider
309+
FakeQuestion("semver"),
310+
],
311+
)
312+
mocker.patch("questionary.confirm", return_value=FakeQuestion(True))
313+
mocker.patch("questionary.text", return_value=FakeQuestion("$version"))
314+
mocker.patch("questionary.checkbox", return_value=FakeQuestion(None))
315+
316+
with tmpdir.as_cwd():
317+
commands.Init(config)()
318+
319+
with open("pyproject.toml", encoding="utf-8") as toml_file:
320+
config_data = toml_file.read()
321+
322+
# Verify version provider is set instead of version
323+
assert 'name = "cz_conventional_commits"' in config_data
324+
assert 'tag_format = "$version"' in config_data
325+
assert 'version_scheme = "semver"' in config_data
326+
assert 'version_provider = "pep621"' in config_data
327+
assert "update_changelog_on_bump = true" in config_data
328+
assert "major_version_zero = true" in config_data
329+
assert (
330+
"version = " not in config_data
331+
) # Version should not be set when using version_provider

0 commit comments

Comments
 (0)