Skip to content

Commit 79dfa58

Browse files
committed
test(bump): add test cases for "--allow-no-commit" argument for bump command
1 parent bd1b6b2 commit 79dfa58

File tree

1 file changed

+101
-0
lines changed

1 file changed

+101
-0
lines changed

Diff for: tests/commands/test_bump_command.py

+101
Original file line numberDiff line numberDiff line change
@@ -1449,3 +1449,104 @@ def test_bump_changelog_contains_increment_only(mocker, tmp_commitizen_project,
14491449

14501450
assert "3.0.0" in out
14511451
assert "2.0.0" not in out
1452+
1453+
1454+
def test_bump_allow_no_commit_with_no_commit(mocker, tmp_commitizen_project, capsys):
1455+
with tmp_commitizen_project.as_cwd():
1456+
# Create the first commit and bump to 1.0.0
1457+
create_file_and_commit("feat(user)!: new file")
1458+
testargs = ["cz", "bump", "--yes"]
1459+
mocker.patch.object(sys, "argv", testargs)
1460+
cli.main()
1461+
1462+
# Verify NoCommitsFoundError should be raised
1463+
# when there's no new commit and "--allow-no-commit" is not set
1464+
with pytest.raises(NoCommitsFoundError):
1465+
testargs = ["cz", "bump"]
1466+
mocker.patch.object(sys, "argv", testargs)
1467+
cli.main()
1468+
1469+
# bump to 1.0.1 with new commit when "--allow-no-commit" is set
1470+
testargs = ["cz", "bump", "--allow-no-commit"]
1471+
mocker.patch.object(sys, "argv", testargs)
1472+
cli.main()
1473+
out, _ = capsys.readouterr()
1474+
assert "bump: version 1.0.0 → 1.0.1" in out
1475+
1476+
1477+
def test_bump_allow_no_commit_with_no_eligible_commit(
1478+
mocker, tmp_commitizen_project, capsys
1479+
):
1480+
with tmp_commitizen_project.as_cwd():
1481+
# Create the first commit and bump to 1.0.0
1482+
create_file_and_commit("feat(user)!: new file")
1483+
testargs = ["cz", "bump", "--yes"]
1484+
mocker.patch.object(sys, "argv", testargs)
1485+
cli.main()
1486+
1487+
# Create a commit that is ineligible to bump
1488+
create_file_and_commit("docs(bump): add description for allow no commit")
1489+
1490+
# Verify NoneIncrementExit should be raised
1491+
# when there's no eligible bumping commit and "--allow-no-commit" is not set
1492+
with pytest.raises(NoneIncrementExit):
1493+
testargs = ["cz", "bump", "--yes"]
1494+
mocker.patch.object(sys, "argv", testargs)
1495+
cli.main()
1496+
1497+
# bump to 1.0.1 with ineligible commit when "--allow-no-commit" is set
1498+
testargs = ["cz", "bump", "--allow-no-commit"]
1499+
mocker.patch.object(sys, "argv", testargs)
1500+
cli.main()
1501+
out, _ = capsys.readouterr()
1502+
assert "bump: version 1.0.0 → 1.0.1" in out
1503+
1504+
1505+
def test_bump_allow_no_commit_with_increment(mocker, tmp_commitizen_project, capsys):
1506+
with tmp_commitizen_project.as_cwd():
1507+
# # Create the first commit and bump to 1.0.0
1508+
create_file_and_commit("feat(user)!: new file")
1509+
testargs = ["cz", "bump", "--yes"]
1510+
mocker.patch.object(sys, "argv", testargs)
1511+
cli.main()
1512+
1513+
# Verify NoCommitsFoundError should be raised
1514+
# when there's no new commit and "--allow-no-commit" is not set
1515+
with pytest.raises(NoCommitsFoundError):
1516+
testargs = ["cz", "bump", "--yes"]
1517+
mocker.patch.object(sys, "argv", testargs)
1518+
cli.main()
1519+
1520+
# bump to 1.1.0 with no new commit when "--allow-no-commit" is set
1521+
# and increment is specified
1522+
testargs = ["cz", "bump", "--yes", "--allow-no-commit", "--increment", "MINOR"]
1523+
mocker.patch.object(sys, "argv", testargs)
1524+
cli.main()
1525+
out, _ = capsys.readouterr()
1526+
assert "bump: version 1.0.0 → 1.1.0" in out
1527+
1528+
1529+
def test_bump_allow_no_commit_with_manual_version(
1530+
mocker, tmp_commitizen_project, capsys
1531+
):
1532+
with tmp_commitizen_project.as_cwd():
1533+
# # Create the first commit and bump to 1.0.0
1534+
create_file_and_commit("feat(user)!: new file")
1535+
testargs = ["cz", "bump", "--yes"]
1536+
mocker.patch.object(sys, "argv", testargs)
1537+
cli.main()
1538+
1539+
# Verify NoCommitsFoundError should be raised
1540+
# when there's no new commit and "--allow-no-commit" is not set
1541+
with pytest.raises(NoCommitsFoundError):
1542+
testargs = ["cz", "bump", "--yes"]
1543+
mocker.patch.object(sys, "argv", testargs)
1544+
cli.main()
1545+
1546+
# bump to 1.1.0 with no new commit when "--allow-no-commit" is set
1547+
# and increment is specified
1548+
testargs = ["cz", "bump", "--yes", "--allow-no-commit", "2.0.0"]
1549+
mocker.patch.object(sys, "argv", testargs)
1550+
cli.main()
1551+
out, _ = capsys.readouterr()
1552+
assert "bump: version 1.0.0 → 2.0.0" in out

0 commit comments

Comments
 (0)