Skip to content

Commit 6ebef0b

Browse files
committed
test(cli): add test cases for uncovered parts
1 parent d6ccf55 commit 6ebef0b

1 file changed

Lines changed: 39 additions & 5 deletions

File tree

tests/test_cli.py

Lines changed: 39 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,46 @@
33
import pytest
44

55
from commitizen import cli
6+
from commitizen.__version__ import __version__
67

78

8-
def test_sysexit_no_argv():
9+
def test_sysexit_no_argv(mocker, capsys):
10+
testargs = ["cz"]
11+
mocker.patch.object(sys, "argv", testargs)
12+
913
with pytest.raises(SystemExit):
1014
cli.main()
15+
out, _ = capsys.readouterr()
16+
assert out.startswith("usage")
17+
18+
19+
def test_cz_with_arg_but_without_command(mocker, capsys):
20+
testargs = ["cz", "--name", "cz_jira"]
21+
mocker.patch.object(sys, "argv", testargs)
22+
23+
with pytest.raises(SystemExit):
24+
cli.main()
25+
_, err = capsys.readouterr()
26+
assert "Command is required" in err
27+
28+
29+
def test_name(mocker, capsys):
30+
testargs = ["cz", "-n", "cz_jira", "example"]
31+
mocker.patch.object(sys, "argv", testargs)
32+
33+
cli.main()
34+
out, _ = capsys.readouterr()
35+
assert out.startswith("JRA")
36+
37+
38+
def test_name_default_value(tmpdir, mocker, capsys):
39+
with tmpdir.as_cwd() as _:
40+
testargs = ["cz", "example"]
41+
mocker.patch.object(sys, "argv", testargs)
42+
43+
cli.main()
44+
out, _ = capsys.readouterr()
45+
assert out.startswith("fix: correct minor typos in code")
1146

1247

1348
def test_ls(mocker, capsys):
@@ -20,11 +55,10 @@ def test_ls(mocker, capsys):
2055
assert isinstance(out, str)
2156

2257

23-
def test_version(mocker):
58+
def test_version(mocker, capsys):
2459
testargs = ["cz", "--version"]
2560
mocker.patch.object(sys, "argv", testargs)
26-
error_mock = mocker.patch("commitizen.out.error")
2761

2862
cli.main()
29-
30-
error_mock.assert_called_once()
63+
out, _ = capsys.readouterr()
64+
assert out.strip() == __version__

0 commit comments

Comments
 (0)