Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit cae1410

Browse filesBrowse files
committed
test(bump): improve test coverage
1 parent 5d8abe9 commit cae1410
Copy full SHA for cae1410

File tree

2 files changed

+54
-5
lines changed
Filter options

2 files changed

+54
-5
lines changed

‎commitizen/commands/bump.py

Copy file name to clipboardExpand all lines: commitizen/commands/bump.py
+2-2Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ def __init__(self, config: BaseConfig, arguments: dict):
6565
"template",
6666
"file_name",
6767
]
68-
if arguments[key] is not None
68+
if arguments.get(key) is not None
6969
},
7070
}
7171
self.cz = factory.committer_factory(self.config)
@@ -110,7 +110,7 @@ def is_initial_tag(
110110
if is_yes:
111111
return True
112112

113-
out.info("No tag matching configuration could not be found.")
113+
out.info("No tag matching configuration could be found.")
114114
out.info(
115115
"Possible causes:\n"
116116
"- version in configuration is not the current version\n"

‎tests/commands/test_bump_command.py

Copy file name to clipboardExpand all lines: tests/commands/test_bump_command.py
+52-3Lines changed: 52 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,9 @@
1212
from pytest_mock import MockFixture
1313

1414
import commitizen.commands.bump as bump
15-
from commitizen import cli, cmd, git, hooks
15+
from commitizen import cli, cmd, defaults, git, hooks
1616
from commitizen.changelog_formats import ChangelogFormat
17+
from commitizen.config.base_config import BaseConfig
1718
from commitizen.cz.base import BaseCommitizen
1819
from commitizen.exceptions import (
1920
BumpTagFailedError,
@@ -41,8 +42,8 @@
4142
"fix(user): username exception",
4243
"refactor: remove ini configuration support",
4344
"refactor(config): remove ini configuration support",
44-
"perf: update to use multiproess",
45-
"perf(worker): update to use multiproess",
45+
"perf: update to use multiprocess",
46+
"perf(worker): update to use multiprocess",
4647
),
4748
)
4849
@pytest.mark.usefixtures("tmp_commitizen_project")
@@ -1688,3 +1689,51 @@ def test_bump_warn_but_dont_fail_on_invalid_tags(
16881689

16891690
assert err.count("Invalid version tag: '0.4.3.deadbeaf'") == 1
16901691
assert git.tag_exist("0.4.3")
1692+
1693+
1694+
def test_is_initial_tag(mocker: MockFixture, tmp_commitizen_project):
1695+
"""Test the is_initial_tag method behavior."""
1696+
# Create a commit but no tags
1697+
create_file_and_commit("feat: initial commit")
1698+
1699+
# Initialize Bump with minimal config
1700+
config = BaseConfig()
1701+
config.settings.update(
1702+
{
1703+
"name": defaults.DEFAULT_SETTINGS["name"],
1704+
"encoding": "utf-8",
1705+
"pre_bump_hooks": [],
1706+
"post_bump_hooks": [],
1707+
}
1708+
)
1709+
1710+
# Initialize with required arguments
1711+
arguments = {
1712+
"changelog": False,
1713+
"changelog_to_stdout": False,
1714+
"git_output_to_stderr": False,
1715+
"no_verify": False,
1716+
"check_consistency": False,
1717+
"retry": False,
1718+
"version_scheme": None,
1719+
"file_name": None,
1720+
"template": None,
1721+
"extras": None,
1722+
}
1723+
1724+
bump_cmd = bump.Bump(config, arguments)
1725+
1726+
# Test case 1: No current tag, not yes mode
1727+
mocker.patch("questionary.confirm", return_value=mocker.Mock(ask=lambda: True))
1728+
assert bump_cmd.is_initial_tag(None, is_yes=False) is True
1729+
1730+
# Test case 2: No current tag, yes mode
1731+
assert bump_cmd.is_initial_tag(None, is_yes=True) is True
1732+
1733+
# Test case 3: Has current tag
1734+
mock_tag = mocker.Mock()
1735+
assert bump_cmd.is_initial_tag(mock_tag, is_yes=False) is False
1736+
1737+
# Test case 4: No current tag, user denies
1738+
mocker.patch("questionary.confirm", return_value=mocker.Mock(ask=lambda: False))
1739+
assert bump_cmd.is_initial_tag(None, is_yes=False) is False

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.