Skip to content

Commit 2b15a1b

Browse files
committed
test(commands/changelog): add test case for changelog command
1 parent 0b0676d commit 2b15a1b

File tree

1 file changed

+65
-0
lines changed

1 file changed

+65
-0
lines changed
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
import sys
2+
3+
import pytest
4+
5+
from commitizen import cli
6+
from tests.utils import create_file_and_commit
7+
8+
9+
@pytest.mark.usefixtures("tmp_commitizen_project")
10+
def test_changlog_on_empty_project(mocker):
11+
testargs = ["cz", "changelog", "--dry-run"]
12+
mocker.patch.object(sys, "argv", testargs)
13+
14+
with pytest.raises(SystemExit):
15+
cli.main()
16+
17+
18+
@pytest.mark.usefixtures("tmp_commitizen_project")
19+
def test_changlog_from_start(mocker, capsys):
20+
create_file_and_commit("feat: new file")
21+
create_file_and_commit("refactor: not in changelog")
22+
create_file_and_commit("Merge into master")
23+
24+
testargs = ["cz", "changelog", "--dry-run"]
25+
mocker.patch.object(sys, "argv", testargs)
26+
27+
with pytest.raises(SystemExit):
28+
cli.main()
29+
30+
out, _ = capsys.readouterr()
31+
assert out == "# CHANGELOG\n\n## Unreleased\n### feat\n- new file\n\n\n"
32+
33+
34+
@pytest.mark.usefixtures("tmp_commitizen_project")
35+
def test_changlog_from_version_zero_point_two(mocker, capsys):
36+
create_file_and_commit("feat: new file")
37+
create_file_and_commit("refactor: not in changelog")
38+
39+
# create tag
40+
testargs = ["cz", "bump", "--yes"]
41+
mocker.patch.object(sys, "argv", testargs)
42+
cli.main()
43+
capsys.readouterr()
44+
45+
create_file_and_commit("feat: after 0.2.0")
46+
create_file_and_commit("feat: after 0.2")
47+
48+
testargs = ["cz", "changelog", "--start-rev", "0.2.0", "--dry-run"]
49+
mocker.patch.object(sys, "argv", testargs)
50+
with pytest.raises(SystemExit):
51+
cli.main()
52+
53+
out, _ = capsys.readouterr()
54+
assert out == "# CHANGELOG\n\n## Unreleased\n### feat\n- after 0.2\n- after 0.2.0\n\n\n"
55+
56+
57+
@pytest.mark.usefixtures("tmp_commitizen_project")
58+
def test_changlog_with_unsupported_cz(mocker, capsys):
59+
testargs = ["cz", "-n", "cz_jira", "changelog", "--dry-run"]
60+
mocker.patch.object(sys, "argv", testargs)
61+
62+
with pytest.raises(SystemExit):
63+
cli.main()
64+
out, err = capsys.readouterr()
65+
assert "'cz_jira' rule does not support changelog" in err

0 commit comments

Comments
 (0)