Skip to content

Commit 8516635

Browse files
test(changelog_merge_prerelease): add tests for changelog_merge_prerelease during bump
1 parent 9c98974 commit 8516635

7 files changed

+149
-0
lines changed

tests/commands/test_bump_command.py

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1737,3 +1737,74 @@ def test_is_initial_tag(mocker: MockFixture, tmp_commitizen_project):
17371737
# Test case 4: No current tag, user denies
17381738
mocker.patch("questionary.confirm", return_value=mocker.Mock(ask=lambda: False))
17391739
assert bump_cmd._is_initial_tag(None, is_yes=False) is False
1740+
1741+
1742+
@pytest.mark.parametrize("test_input", ["rc", "alpha", "beta"])
1743+
@pytest.mark.usefixtures("tmp_commitizen_project")
1744+
def test_changelog_config_flag_merge_prerelease(
1745+
mocker: MockFixture, changelog_path, config_path, file_regression, test_input
1746+
):
1747+
with open(config_path, "a") as f:
1748+
f.write("changelog_merge_prerelease = true\n")
1749+
f.write("update_changelog_on_bump = true\n")
1750+
f.write("annotated_tag = true\n")
1751+
1752+
create_file_and_commit("irrelevant commit")
1753+
mocker.patch("commitizen.git.GitTag.date", "1970-01-01")
1754+
git.tag("0.1.0")
1755+
1756+
create_file_and_commit("feat: add new output")
1757+
create_file_and_commit("fix: output glitch")
1758+
testargs = ["cz", "bump", "--prerelease", test_input, "--yes"]
1759+
mocker.patch.object(sys, "argv", testargs)
1760+
cli.main()
1761+
1762+
testargs = ["cz", "bump", "--changelog"]
1763+
1764+
mocker.patch.object(sys, "argv", testargs)
1765+
cli.main()
1766+
1767+
with open(changelog_path) as f:
1768+
out = f.read()
1769+
out = re.sub(
1770+
r"\([^)]*\)", "", out
1771+
) # remove date from release, since I have no idea how to mock that
1772+
print(out)
1773+
1774+
file_regression.check(out, extension=".md")
1775+
1776+
1777+
@pytest.mark.parametrize("test_input", ["rc", "alpha", "beta"])
1778+
@pytest.mark.usefixtures("tmp_commitizen_project")
1779+
def test_changelog_config_flag_merge_prerelease_more_commits(
1780+
mocker: MockFixture, changelog_path, config_path, file_regression, test_input
1781+
):
1782+
# supposed to verify that logic regarding indexes is generic
1783+
with open(config_path, "a") as f:
1784+
f.write("changelog_merge_prerelease = true\n")
1785+
f.write("update_changelog_on_bump = true\n")
1786+
f.write("annotated_tag = true\n")
1787+
1788+
create_file_and_commit("feat: more relevant commit")
1789+
mocker.patch("commitizen.git.GitTag.date", "1970-01-01")
1790+
git.tag("0.1.0")
1791+
1792+
create_file_and_commit("feat: add new output")
1793+
create_file_and_commit("fix: output glitch")
1794+
testargs = ["cz", "bump", "--prerelease", test_input, "--yes"]
1795+
mocker.patch.object(sys, "argv", testargs)
1796+
cli.main()
1797+
1798+
testargs = ["cz", "bump", "--changelog"]
1799+
1800+
mocker.patch.object(sys, "argv", testargs)
1801+
cli.main()
1802+
1803+
with open(changelog_path) as f:
1804+
out = f.read()
1805+
out = re.sub(
1806+
r"\([^)]*\)", "", out
1807+
) # remove date from release, since I have no idea how to mock that
1808+
print(out)
1809+
1810+
file_regression.check(out, extension=".md")
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
## 0.2.0
2+
3+
### Feat
4+
5+
- add new output
6+
7+
### Fix
8+
9+
- output glitch
10+
11+
## 0.1.0
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
## 0.2.0
2+
3+
### Feat
4+
5+
- add new output
6+
7+
### Fix
8+
9+
- output glitch
10+
11+
## 0.1.0
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
## 0.2.0
2+
3+
### Feat
4+
5+
- add new output
6+
7+
### Fix
8+
9+
- output glitch
10+
11+
## 0.1.0
12+
13+
### Feat
14+
15+
- more relevant commit
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
## 0.2.0
2+
3+
### Feat
4+
5+
- add new output
6+
7+
### Fix
8+
9+
- output glitch
10+
11+
## 0.1.0
12+
13+
### Feat
14+
15+
- more relevant commit
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
## 0.2.0
2+
3+
### Feat
4+
5+
- add new output
6+
7+
### Fix
8+
9+
- output glitch
10+
11+
## 0.1.0
12+
13+
### Feat
14+
15+
- more relevant commit
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
## 0.2.0
2+
3+
### Feat
4+
5+
- add new output
6+
7+
### Fix
8+
9+
- output glitch
10+
11+
## 0.1.0

0 commit comments

Comments
 (0)