Skip to content

Commit b9ed2c9

Browse files
test: Use a single parametrized test
Signed-off-by: Edgar Ramírez Mondragón <edgarrm358@gmail.com>
1 parent 85b1f90 commit b9ed2c9

File tree

4 files changed

+46
-59
lines changed

4 files changed

+46
-59
lines changed

tests/commands/test_bump_command.py

Lines changed: 22 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -1494,18 +1494,28 @@ def test_changelog_config_flag_merge_prerelease_only_prerelease_present(
14941494
file_regression.check(out, extension=".md")
14951495

14961496

1497+
@pytest.mark.parametrize(
1498+
("prerelease", "merge"),
1499+
[
1500+
pytest.param(True, "true", id="with_prerelease_merge"),
1501+
pytest.param(True, "false", id="with_prerelease_no_merge"),
1502+
pytest.param(False, "true", id="without_prerelease"),
1503+
],
1504+
)
14971505
@pytest.mark.usefixtures("tmp_commitizen_project")
14981506
@pytest.mark.freeze_time("2025-01-01")
1499-
def test_changelog_merge_prerelease_preserves_header(
1507+
def test_changelog_merge_preserves_header(
15001508
mocker: MockFixture,
15011509
util: UtilFixture,
15021510
changelog_path: Path,
15031511
config_path: Path,
15041512
file_regression: FileRegressionFixture,
1513+
prerelease: bool,
1514+
merge: str,
15051515
):
15061516
"""Test that merge_prerelease preserves existing changelog header."""
15071517
with config_path.open("a") as f:
1508-
f.write("changelog_merge_prerelease = true\n")
1518+
f.write(f"changelog_merge_prerelease = {merge}\n")
15091519
f.write("update_changelog_on_bump = true\n")
15101520
f.write("annotated_tag = true\n")
15111521

@@ -1516,67 +1526,25 @@ def test_changelog_merge_prerelease_preserves_header(
15161526

15171527
# Create a changelog with a header manually
15181528
changelog_path.write_text(
1519-
"# Changelog\n\nAll notable changes to this project will be documented here.\n\n## 0.1.0 (1970-01-01)\n"
1520-
)
1521-
1522-
util.create_file_and_commit("feat: add new output")
1523-
util.create_file_and_commit("fix: output glitch")
1524-
util.run_cli("bump", "--prerelease", "alpha", "--yes")
1525-
1526-
util.run_cli("bump", "--changelog")
1527-
1528-
with changelog_path.open() as f:
1529-
out = f.read()
1530-
1531-
file_regression.check(out, extension=".md")
1532-
1533-
1534-
@pytest.mark.usefixtures("tmp_commitizen_project")
1535-
@pytest.mark.freeze_time("2025-01-01")
1536-
def test_changelog_merge_prerelease_no_prereleases_to_merge(
1537-
mocker: MockFixture,
1538-
util: UtilFixture,
1539-
changelog_path: Path,
1540-
config_path: Path,
1541-
file_regression: FileRegressionFixture,
1542-
):
1543-
"""Test that merge_prerelease works correctly when there are no prereleases.
1544-
1545-
When changelog_merge_prerelease is enabled but there are no prereleases to merge,
1546-
the normal incremental changelog behavior should apply and the existing changelog
1547-
content should be preserved.
1548-
"""
1549-
with config_path.open("a") as f:
1550-
f.write("changelog_merge_prerelease = true\n")
1551-
f.write("update_changelog_on_bump = true\n")
1552-
f.write("annotated_tag = true\n")
1529+
dedent("""\
1530+
# Changelog
15531531
1554-
# Create initial version with changelog that has a header
1555-
util.create_file_and_commit("feat: initial feature")
1556-
mocker.patch("commitizen.git.GitTag.date", "1970-01-01")
1557-
git.tag("0.1.0")
1532+
All notable changes to this project will be documented here.
15581533
1559-
# Create a changelog with a header manually
1560-
changelog_path.write_text(
1561-
"# Changelog\n\nAll notable changes.\n\n## 0.1.0 (1970-01-01)\n\n### Feat\n\n- initial feature\n"
1534+
## 0.1.0 (1970-01-01)
1535+
""")
15621536
)
15631537

1564-
# Add new commits and do a regular bump (no prerelease)
15651538
util.create_file_and_commit("feat: add new output")
15661539
util.create_file_and_commit("fix: output glitch")
1540+
1541+
if prerelease:
1542+
util.run_cli("bump", "--prerelease", "alpha", "--yes")
1543+
1544+
util.create_file_and_commit("feat: new feature right before the bump")
15671545
util.run_cli("bump", "--changelog")
15681546

15691547
with changelog_path.open() as f:
15701548
out = f.read()
15711549

15721550
file_regression.check(out, extension=".md")
1573-
1574-
1575-
@pytest.mark.usefixtures("tmp_commitizen_project")
1576-
def test_bump_deprecate_files_only(util: UtilFixture):
1577-
util.create_file_and_commit("feat: new file")
1578-
with (
1579-
pytest.warns(DeprecationWarning, match=r".*--files-only.*deprecated"),
1580-
pytest.raises(ExpectedExit),
1581-
):
1582-
util.run_cli("bump", "--yes", "--files-only")

tests/commands/test_bump_command/test_changelog_merge_prerelease_preserves_header.md renamed to tests/commands/test_bump_command/test_changelog_merge_preserves_header_with_prerelease_merge_.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ All notable changes to this project will be documented here.
66

77
### Feat
88

9+
- new feature right before the bump
910
- add new output
1011

1112
### Fix
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# Changelog
2+
3+
All notable changes to this project will be documented here.
4+
5+
## 0.2.0 (2025-01-01)
6+
7+
### Feat
8+
9+
- new feature right before the bump
10+
11+
## 0.2.0a0 (2025-01-01)
12+
13+
### Feat
14+
15+
- add new output
16+
17+
### Fix
18+
19+
- output glitch
20+
21+
## 0.1.0 (1970-01-01)

tests/commands/test_bump_command/test_changelog_merge_prerelease_no_prereleases_to_merge.md renamed to tests/commands/test_bump_command/test_changelog_merge_preserves_header_without_prerelease_.md

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,16 @@
11
# Changelog
22

3-
All notable changes.
3+
All notable changes to this project will be documented here.
44

55
## 0.2.0 (2025-01-01)
66

77
### Feat
88

9+
- new feature right before the bump
910
- add new output
1011

1112
### Fix
1213

1314
- output glitch
1415

1516
## 0.1.0 (1970-01-01)
16-
17-
### Feat
18-
19-
- initial feature

0 commit comments

Comments
 (0)