Skip to content

Commit c952dc9

Browse files
committed
refactor(bump): add test
1 parent 5355301 commit c952dc9

File tree

2 files changed

+55
-3
lines changed

2 files changed

+55
-3
lines changed

commitizen/commands/bump.py

Lines changed: 1 addition & 1 deletion
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)

tests/commands/test_bump_command.py

Lines changed: 54 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,8 @@
4141
"fix(user): username exception",
4242
"refactor: remove ini configuration support",
4343
"refactor(config): remove ini configuration support",
44-
"perf: update to use multiproess",
45-
"perf(worker): update to use multiproess",
44+
"perf: update to use multiprocess",
45+
"perf(worker): update to use multiprocess",
4646
),
4747
)
4848
@pytest.mark.usefixtures("tmp_commitizen_project")
@@ -1688,3 +1688,55 @@ def test_bump_warn_but_dont_fail_on_invalid_tags(
16881688

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

0 commit comments

Comments
 (0)