|
9 | 9 | from unittest.mock import MagicMock, call |
10 | 10 |
|
11 | 11 | import pytest |
| 12 | +from freezegun import freeze_time |
12 | 13 |
|
13 | 14 | import commitizen.commands.bump as bump |
14 | 15 | from commitizen import cli, cmd, defaults, git, hooks |
@@ -1705,3 +1706,66 @@ def test_is_initial_tag(mocker: MockFixture, tmp_commitizen_project): |
1705 | 1706 | # Test case 4: No current tag, user denies |
1706 | 1707 | mocker.patch("questionary.confirm", return_value=mocker.Mock(ask=lambda: False)) |
1707 | 1708 | assert bump_cmd._is_initial_tag(None, is_yes=False) is False |
| 1709 | + |
| 1710 | + |
| 1711 | +@pytest.mark.parametrize("test_input", ["rc", "alpha", "beta"]) |
| 1712 | +@pytest.mark.usefixtures("tmp_commitizen_project") |
| 1713 | +@freeze_time("2025-01-01") |
| 1714 | +def test_changelog_config_flag_merge_prerelease( |
| 1715 | + mocker: MockFixture, changelog_path, config_path, file_regression, test_input |
| 1716 | +): |
| 1717 | + with open(config_path, "a") as f: |
| 1718 | + f.write("changelog_merge_prerelease = true\n") |
| 1719 | + f.write("update_changelog_on_bump = true\n") |
| 1720 | + f.write("annotated_tag = true\n") |
| 1721 | + |
| 1722 | + create_file_and_commit("irrelevant commit") |
| 1723 | + mocker.patch("commitizen.git.GitTag.date", "1970-01-01") |
| 1724 | + git.tag("0.1.0") |
| 1725 | + |
| 1726 | + create_file_and_commit("feat: add new output") |
| 1727 | + create_file_and_commit("fix: output glitch") |
| 1728 | + testargs = ["cz", "bump", "--prerelease", test_input, "--yes"] |
| 1729 | + mocker.patch.object(sys, "argv", testargs) |
| 1730 | + cli.main() |
| 1731 | + |
| 1732 | + testargs = ["cz", "bump", "--changelog"] |
| 1733 | + mocker.patch.object(sys, "argv", testargs) |
| 1734 | + cli.main() |
| 1735 | + |
| 1736 | + with open(changelog_path) as f: |
| 1737 | + out = f.read() |
| 1738 | + |
| 1739 | + file_regression.check(out, extension=".md") |
| 1740 | + |
| 1741 | + |
| 1742 | +@pytest.mark.parametrize("test_input", ["rc", "alpha", "beta"]) |
| 1743 | +@pytest.mark.usefixtures("tmp_commitizen_project") |
| 1744 | +@freeze_time("2025-01-01") |
| 1745 | +def test_changelog_config_flag_merge_prerelease_only_prerelease_present( |
| 1746 | + mocker: MockFixture, changelog_path, config_path, file_regression, test_input |
| 1747 | +): |
| 1748 | + with open(config_path, "a") as f: |
| 1749 | + f.write("changelog_merge_prerelease = true\n") |
| 1750 | + f.write("update_changelog_on_bump = true\n") |
| 1751 | + f.write("annotated_tag = true\n") |
| 1752 | + |
| 1753 | + create_file_and_commit("feat: more relevant commit") |
| 1754 | + testargs = ["cz", "bump", "--prerelease", test_input, "--yes"] |
| 1755 | + mocker.patch.object(sys, "argv", testargs) |
| 1756 | + cli.main() |
| 1757 | + |
| 1758 | + create_file_and_commit("feat: add new output") |
| 1759 | + create_file_and_commit("fix: output glitch") |
| 1760 | + testargs = ["cz", "bump", "--prerelease", test_input, "--yes"] |
| 1761 | + mocker.patch.object(sys, "argv", testargs) |
| 1762 | + cli.main() |
| 1763 | + |
| 1764 | + testargs = ["cz", "bump", "--changelog"] |
| 1765 | + mocker.patch.object(sys, "argv", testargs) |
| 1766 | + cli.main() |
| 1767 | + |
| 1768 | + with open(changelog_path) as f: |
| 1769 | + out = f.read() |
| 1770 | + |
| 1771 | + file_regression.check(out, extension=".md") |
0 commit comments