Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit ba5a71a

Browse files
committed
test(bump): add test cases for "--allow-no-commit" argument for bump command
1 parent 7d63120 commit ba5a71a

File tree

2 files changed

+103
-0
lines changed

2 files changed

+103
-0
lines changed

‎tests/commands/test_bump_command.py‎

Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1543,3 +1543,104 @@ def test_bump_get_next__no_eligible_commits_raises(mocker: MockFixture):
15431543

15441544
with pytest.raises(NoneIncrementExit):
15451545
cli.main()
1546+
1547+
1548+
def test_bump_allow_no_commit_with_no_commit(mocker, tmp_commitizen_project, capsys):
1549+
with tmp_commitizen_project.as_cwd():
1550+
# Create the first commit and bump to 1.0.0
1551+
create_file_and_commit("feat(user)!: new file")
1552+
testargs = ["cz", "bump", "--yes"]
1553+
mocker.patch.object(sys, "argv", testargs)
1554+
cli.main()
1555+
1556+
# Verify NoCommitsFoundError should be raised
1557+
# when there's no new commit and "--allow-no-commit" is not set
1558+
with pytest.raises(NoCommitsFoundError):
1559+
testargs = ["cz", "bump"]
1560+
mocker.patch.object(sys, "argv", testargs)
1561+
cli.main()
1562+
1563+
# bump to 1.0.1 with new commit when "--allow-no-commit" is set
1564+
testargs = ["cz", "bump", "--allow-no-commit"]
1565+
mocker.patch.object(sys, "argv", testargs)
1566+
cli.main()
1567+
out, _ = capsys.readouterr()
1568+
assert "bump: version 1.0.0 → 1.0.1" in out
1569+
1570+
1571+
def test_bump_allow_no_commit_with_no_eligible_commit(
1572+
mocker, tmp_commitizen_project, capsys
1573+
):
1574+
with tmp_commitizen_project.as_cwd():
1575+
# Create the first commit and bump to 1.0.0
1576+
create_file_and_commit("feat(user)!: new file")
1577+
testargs = ["cz", "bump", "--yes"]
1578+
mocker.patch.object(sys, "argv", testargs)
1579+
cli.main()
1580+
1581+
# Create a commit that is ineligible to bump
1582+
create_file_and_commit("docs(bump): add description for allow no commit")
1583+
1584+
# Verify NoneIncrementExit should be raised
1585+
# when there's no eligible bumping commit and "--allow-no-commit" is not set
1586+
with pytest.raises(NoneIncrementExit):
1587+
testargs = ["cz", "bump", "--yes"]
1588+
mocker.patch.object(sys, "argv", testargs)
1589+
cli.main()
1590+
1591+
# bump to 1.0.1 with ineligible commit when "--allow-no-commit" is set
1592+
testargs = ["cz", "bump", "--allow-no-commit"]
1593+
mocker.patch.object(sys, "argv", testargs)
1594+
cli.main()
1595+
out, _ = capsys.readouterr()
1596+
assert "bump: version 1.0.0 → 1.0.1" in out
1597+
1598+
1599+
def test_bump_allow_no_commit_with_increment(mocker, tmp_commitizen_project, capsys):
1600+
with tmp_commitizen_project.as_cwd():
1601+
# # Create the first commit and bump to 1.0.0
1602+
create_file_and_commit("feat(user)!: new file")
1603+
testargs = ["cz", "bump", "--yes"]
1604+
mocker.patch.object(sys, "argv", testargs)
1605+
cli.main()
1606+
1607+
# Verify NoCommitsFoundError should be raised
1608+
# when there's no new commit and "--allow-no-commit" is not set
1609+
with pytest.raises(NoCommitsFoundError):
1610+
testargs = ["cz", "bump", "--yes"]
1611+
mocker.patch.object(sys, "argv", testargs)
1612+
cli.main()
1613+
1614+
# bump to 1.1.0 with no new commit when "--allow-no-commit" is set
1615+
# and increment is specified
1616+
testargs = ["cz", "bump", "--yes", "--allow-no-commit", "--increment", "MINOR"]
1617+
mocker.patch.object(sys, "argv", testargs)
1618+
cli.main()
1619+
out, _ = capsys.readouterr()
1620+
assert "bump: version 1.0.0 → 1.1.0" in out
1621+
1622+
1623+
def test_bump_allow_no_commit_with_manual_version(
1624+
mocker, tmp_commitizen_project, capsys
1625+
):
1626+
with tmp_commitizen_project.as_cwd():
1627+
# # Create the first commit and bump to 1.0.0
1628+
create_file_and_commit("feat(user)!: new file")
1629+
testargs = ["cz", "bump", "--yes"]
1630+
mocker.patch.object(sys, "argv", testargs)
1631+
cli.main()
1632+
1633+
# Verify NoCommitsFoundError should be raised
1634+
# when there's no new commit and "--allow-no-commit" is not set
1635+
with pytest.raises(NoCommitsFoundError):
1636+
testargs = ["cz", "bump", "--yes"]
1637+
mocker.patch.object(sys, "argv", testargs)
1638+
cli.main()
1639+
1640+
# bump to 1.1.0 with no new commit when "--allow-no-commit" is set
1641+
# and increment is specified
1642+
testargs = ["cz", "bump", "--yes", "--allow-no-commit", "2.0.0"]
1643+
mocker.patch.object(sys, "argv", testargs)
1644+
cli.main()
1645+
out, _ = capsys.readouterr()
1646+
assert "bump: version 1.0.0 → 2.0.0" in out

‎tests/commands/test_bump_command/test_bump_command_shows_description_when_use_help_option.txt‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ usage: cz bump [-h] [--dry-run] [--files-only] [--local-version] [--changelog]
1111
[--version-scheme {pep440,semver,semver2}]
1212
[--version-type {pep440,semver,semver2}]
1313
[--build-metadata BUILD_METADATA] [--get-next]
14+
[--allow-no-commit]
1415
[MANUAL_VERSION]
1516

1617
bump semantic version based on the git log
@@ -77,3 +78,4 @@ options:
7778
--build-metadata BUILD_METADATA
7879
Add additional build-metadata to the version-number
7980
--get-next Determine the next version and write to stdout
81+
--allow-no-commit bump version without eligible commits

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /