|
31 | 31 | if TYPE_CHECKING: |
32 | 32 | import py |
33 | 33 | from pytest_mock import MockFixture |
| 34 | + from pytest_regressions.file_regression import FileRegressionFixture |
34 | 35 |
|
35 | 36 | from commitizen.changelog_formats import ChangelogFormat |
36 | 37 | from commitizen.cz.base import BaseCommitizen |
@@ -1494,3 +1495,65 @@ def test_is_initial_tag(mocker: MockFixture, tmp_commitizen_project, util: UtilF |
1494 | 1495 | # Test case 4: No current tag, user denies |
1495 | 1496 | mocker.patch("questionary.confirm", return_value=mocker.Mock(ask=lambda: False)) |
1496 | 1497 | assert bump_cmd._is_initial_tag(None, is_yes=False) is False |
| 1498 | + |
| 1499 | + |
| 1500 | +@pytest.mark.parametrize("test_input", ["rc", "alpha", "beta"]) |
| 1501 | +@pytest.mark.usefixtures("tmp_commitizen_project") |
| 1502 | +@pytest.mark.freeze_time("2025-01-01") |
| 1503 | +def test_changelog_config_flag_merge_prerelease( |
| 1504 | + mocker: MockFixture, |
| 1505 | + util: UtilFixture, |
| 1506 | + changelog_path: str, |
| 1507 | + config_path: str, |
| 1508 | + file_regression: FileRegressionFixture, |
| 1509 | + test_input: str, |
| 1510 | +): |
| 1511 | + with open(config_path, "a") as f: |
| 1512 | + f.write("changelog_merge_prerelease = true\n") |
| 1513 | + f.write("update_changelog_on_bump = true\n") |
| 1514 | + f.write("annotated_tag = true\n") |
| 1515 | + |
| 1516 | + util.create_file_and_commit("irrelevant commit") |
| 1517 | + mocker.patch("commitizen.git.GitTag.date", "1970-01-01") |
| 1518 | + git.tag("0.1.0") |
| 1519 | + |
| 1520 | + util.create_file_and_commit("feat: add new output") |
| 1521 | + util.create_file_and_commit("fix: output glitch") |
| 1522 | + util.run_cli("bump", "--prerelease", test_input, "--yes") |
| 1523 | + |
| 1524 | + util.run_cli("bump", "--changelog") |
| 1525 | + |
| 1526 | + with open(changelog_path) as f: |
| 1527 | + out = f.read() |
| 1528 | + |
| 1529 | + file_regression.check(out, extension=".md") |
| 1530 | + |
| 1531 | + |
| 1532 | +@pytest.mark.parametrize("test_input", ["rc", "alpha", "beta"]) |
| 1533 | +@pytest.mark.usefixtures("tmp_commitizen_project") |
| 1534 | +@pytest.mark.freeze_time("2025-01-01") |
| 1535 | +def test_changelog_config_flag_merge_prerelease_only_prerelease_present( |
| 1536 | + util: UtilFixture, |
| 1537 | + changelog_path: str, |
| 1538 | + config_path: str, |
| 1539 | + file_regression: FileRegressionFixture, |
| 1540 | + test_input: str, |
| 1541 | +): |
| 1542 | + with open(config_path, "a") as f: |
| 1543 | + f.write("changelog_merge_prerelease = true\n") |
| 1544 | + f.write("update_changelog_on_bump = true\n") |
| 1545 | + f.write("annotated_tag = true\n") |
| 1546 | + |
| 1547 | + util.create_file_and_commit("feat: more relevant commit") |
| 1548 | + util.run_cli("bump", "--prerelease", test_input, "--yes") |
| 1549 | + |
| 1550 | + util.create_file_and_commit("feat: add new output") |
| 1551 | + util.create_file_and_commit("fix: output glitch") |
| 1552 | + util.run_cli("bump", "--prerelease", test_input, "--yes") |
| 1553 | + |
| 1554 | + util.run_cli("bump", "--changelog") |
| 1555 | + |
| 1556 | + with open(changelog_path) as f: |
| 1557 | + out = f.read() |
| 1558 | + |
| 1559 | + file_regression.check(out, extension=".md") |
0 commit comments