Skip to content

Commit d11ee96

Browse files
committed
test: add test for major_version_zero bug
1 parent 996bff8 commit d11ee96

File tree

2 files changed

+121
-0
lines changed

2 files changed

+121
-0
lines changed

‎tests/commands/test_bump_command.py

+44
Original file line numberDiff line numberDiff line change
@@ -980,3 +980,47 @@ def test_bump_command_prelease_version_type_check_old_tags(
980980
for version_file in [tmp_version_file, tmp_commitizen_cfg_file]:
981981
with open(version_file, "r") as f:
982982
assert "0.2.0" in f.read()
983+
984+
985+
@pytest.mark.usefixtures("tmp_commitizen_project")
986+
@pytest.mark.usefixtures("use_cz_semver")
987+
@pytest.mark.parametrize(
988+
"message, expected_tag",
989+
[
990+
("minor: add users", "0.2.0"),
991+
("patch: bug affecting users", "0.1.1"),
992+
("major: bug affecting users", "1.0.0"),
993+
],
994+
)
995+
def test_bump_with_plugin(mocker: MockFixture, message: str, expected_tag: str):
996+
create_file_and_commit(message)
997+
998+
testargs = ["cz", "--name", "cz_semver", "bump", "--yes"]
999+
mocker.patch.object(sys, "argv", testargs)
1000+
cli.main()
1001+
1002+
tag_exists = git.tag_exist(expected_tag)
1003+
assert tag_exists is True
1004+
1005+
1006+
@pytest.mark.usefixtures("tmp_commitizen_project")
1007+
@pytest.mark.usefixtures("use_cz_semver")
1008+
@pytest.mark.parametrize(
1009+
"message, expected_tag",
1010+
[
1011+
("minor: add users", "0.2.0"),
1012+
("patch: bug affecting users", "0.1.1"),
1013+
("major: bug affecting users", "0.2.0"),
1014+
],
1015+
)
1016+
def test_bump_with_major_version_zero_with_plugin(
1017+
mocker: MockFixture, message: str, expected_tag: str
1018+
):
1019+
create_file_and_commit(message)
1020+
1021+
testargs = ["cz", "--name", "cz_semver", "bump", "--yes", "--major-version-zero"]
1022+
mocker.patch.object(sys, "argv", testargs)
1023+
cli.main()
1024+
1025+
tag_exists = git.tag_exist(expected_tag)
1026+
assert tag_exists is True

‎tests/conftest.py

+77
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88

99
from commitizen import cmd, defaults
1010
from commitizen.config import BaseConfig
11+
from commitizen.cz.base import BaseCommitizen
12+
from commitizen.cz import registry
1113
from tests.utils import create_file_and_commit
1214

1315
SIGNER = "GitHub Action"
@@ -122,3 +124,78 @@ def config():
122124
@pytest.fixture()
123125
def config_path() -> str:
124126
return os.path.join(os.getcwd(), "pyproject.toml")
127+
128+
129+
class SemverCommitizen(BaseCommitizen):
130+
"""A minimal cz rules used to test changelog and bump.
131+
132+
Samples:
133+
```
134+
minor(users): add email to user
135+
major: removed user profile
136+
patch(deps): updated dependency for security
137+
```
138+
"""
139+
140+
bump_pattern = r"^(patch|minor|major)"
141+
bump_map = {
142+
"major": "MAJOR",
143+
"minor": "MINOR",
144+
"patch": "PATCH",
145+
}
146+
# bump_map_major_version_zero = {
147+
# "major": "MINOR",
148+
# "minor": "MINOR",
149+
# "patch": "PATCH",
150+
# }
151+
changelog_pattern = r"^(patch|minor|major)"
152+
commit_parser = r"^(?P<change_type>patch|minor|major)(?:\((?P<scope>[^()\r\n]*)\)|\()?:?\s(?P<message>.+)" # noqa
153+
change_type_map = {
154+
"major": "Breaking Changes",
155+
"minor": "Features",
156+
"patch": "Bugs",
157+
}
158+
159+
def questions(self) -> list:
160+
return [
161+
{
162+
"type": "list",
163+
"name": "prefix",
164+
"message": "Select the type of change you are committing",
165+
"choices": [
166+
{
167+
"value": "patch",
168+
"name": "patch: a bug fix",
169+
"key": "p",
170+
},
171+
{
172+
"value": "minor",
173+
"name": "minor: a new feature, non-breaking",
174+
"key": "m",
175+
},
176+
{
177+
"value": "major",
178+
"name": "major: a breaking change",
179+
"key": "b",
180+
},
181+
],
182+
},
183+
{
184+
"type": "input",
185+
"name": "subject",
186+
"message": (
187+
"Write a short and imperative summary of the code changes: (lower case and no period)\n"
188+
),
189+
},
190+
]
191+
192+
def message(self, answers: dict) -> str:
193+
prefix = answers["prefix"]
194+
subject = answers.get("subject", "default message").trim()
195+
return f"{prefix}: {subject}"
196+
197+
198+
@pytest.fixture()
199+
def use_cz_semver(mocker):
200+
new_cz = {**registry, "cz_semver": SemverCommitizen}
201+
mocker.patch.dict("commitizen.cz.registry", new_cz)

0 commit comments

Comments
 (0)