Skip to content

Commit ce12748

Browse files
committed
test(commands): centralize all --help tests in a file to dedup code
1 parent 2072f8e commit ce12748

22 files changed

+74
-218
lines changed

tests/commands/test_bump_command.py

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
NotAllowed,
2929
NoVersionSpecifiedError,
3030
)
31-
from tests.utils import create_file_and_commit, create_tag, skip_below_py_3_13
31+
from tests.utils import create_file_and_commit, create_tag
3232

3333
if TYPE_CHECKING:
3434
import py
@@ -1438,19 +1438,6 @@ def test_bump_changelog_contains_increment_only(mocker, tmp_commitizen_project,
14381438
assert "2.0.0" not in out
14391439

14401440

1441-
@skip_below_py_3_13
1442-
def test_bump_command_shows_description_when_use_help_option(
1443-
mocker: MockFixture, capsys, file_regression
1444-
):
1445-
testargs = ["cz", "bump", "--help"]
1446-
mocker.patch.object(sys, "argv", testargs)
1447-
with pytest.raises(SystemExit):
1448-
cli.main()
1449-
1450-
out, _ = capsys.readouterr()
1451-
file_regression.check(out, extension=".txt")
1452-
1453-
14541441
@pytest.mark.usefixtures("tmp_commitizen_project")
14551442
def test_bump_get_next(mocker: MockFixture, capsys):
14561443
create_file_and_commit("feat: new file")

tests/commands/test_changelog_command.py

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@
3030
create_tag,
3131
get_current_branch,
3232
merge_branch,
33-
skip_below_py_3_13,
3433
switch_branch,
3534
wait_for_tag,
3635
)
@@ -1927,16 +1926,3 @@ class FakeTemplate:
19271926

19281927
assert not target.exists()
19291928
assert "Template filename is not set" in str(exc_info.value)
1930-
1931-
1932-
@skip_below_py_3_13
1933-
def test_changelog_command_shows_description_when_use_help_option(
1934-
mocker: MockFixture, capsys, file_regression
1935-
):
1936-
testargs = ["cz", "changelog", "--help"]
1937-
mocker.patch.object(sys, "argv", testargs)
1938-
with pytest.raises(SystemExit):
1939-
cli.main()
1940-
1941-
out, _ = capsys.readouterr()
1942-
file_regression.check(out, extension=".txt")

tests/commands/test_check_command.py

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
InvalidCommitMessageError,
1616
NoCommitsFoundError,
1717
)
18-
from tests.utils import create_file_and_commit, skip_below_py_3_13
18+
from tests.utils import create_file_and_commit
1919

2020
if TYPE_CHECKING:
2121
import re
@@ -427,19 +427,6 @@ def test_check_conventional_commit_succeed_with_git_diff(mocker, capsys):
427427
assert "Commit validation: successful!" in out
428428

429429

430-
@skip_below_py_3_13
431-
def test_check_command_shows_description_when_use_help_option(
432-
mocker: MockFixture, capsys, file_regression
433-
):
434-
testargs = ["cz", "check", "--help"]
435-
mocker.patch.object(sys, "argv", testargs)
436-
with pytest.raises(SystemExit):
437-
cli.main()
438-
439-
out, _ = capsys.readouterr()
440-
file_regression.check(out, extension=".txt")
441-
442-
443430
def test_check_command_with_message_length_limit(config, mocker: MockFixture):
444431
success_mock = mocker.patch("commitizen.out.success")
445432
message = "fix(scope): some commit message"

tests/commands/test_commit_command.py

Lines changed: 1 addition & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
11
import os
2-
import sys
32
from unittest.mock import ANY
43

54
import pytest
65
from pytest_mock import MockFixture
76

8-
from commitizen import cli, cmd, commands
7+
from commitizen import cmd, commands
98
from commitizen.cz.exceptions import CzException
109
from commitizen.cz.utils import get_backup_file_path
1110
from commitizen.exceptions import (
@@ -19,7 +18,6 @@
1918
NotAllowed,
2019
NothingToCommitError,
2120
)
22-
from tests.utils import skip_below_py_3_13
2321

2422

2523
@pytest.fixture
@@ -512,19 +510,6 @@ def test_manual_edit(editor, config, mocker: MockFixture, tmp_path):
512510
assert edited_message == test_message.strip()
513511

514512

515-
@skip_below_py_3_13
516-
def test_commit_command_shows_description_when_use_help_option(
517-
mocker: MockFixture, capsys, file_regression
518-
):
519-
testargs = ["cz", "commit", "--help"]
520-
mocker.patch.object(sys, "argv", testargs)
521-
with pytest.raises(SystemExit):
522-
cli.main()
523-
524-
out, _ = capsys.readouterr()
525-
file_regression.check(out, extension=".txt")
526-
527-
528513
@pytest.mark.usefixtures("staging_is_clean")
529514
@pytest.mark.parametrize(
530515
"out", ["no changes added to commit", "nothing added to commit"]
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
import sys
2+
3+
import pytest
4+
from pytest_mock import MockFixture
5+
6+
from commitizen import cli
7+
from commitizen.commands import Example, Info, ListCz, Schema
8+
9+
10+
@pytest.mark.skipif(
11+
sys.version_info < (3, 13),
12+
reason="The output message of argparse is different between Python 3.13 and lower than Python 3.13",
13+
)
14+
@pytest.mark.parametrize(
15+
"command",
16+
[
17+
"bump",
18+
"changelog",
19+
"check",
20+
"commit",
21+
"example",
22+
"info",
23+
"init",
24+
"ls",
25+
"schema",
26+
"version",
27+
],
28+
)
29+
def test_command_shows_description_when_use_help_option(
30+
mocker: MockFixture,
31+
capsys,
32+
file_regression,
33+
monkeypatch: pytest.MonkeyPatch,
34+
command: str,
35+
):
36+
"""Test that the command shows the description when the help option is used.
37+
38+
Note: If the command description changes, please run `pytest tests/commands/test_common_command.py --regen-all` to regenerate the test files.
39+
"""
40+
# Force consistent terminal output
41+
monkeypatch.setenv("COLUMNS", "80")
42+
monkeypatch.setenv("TERM", "dumb")
43+
monkeypatch.setenv("LC_ALL", "C")
44+
monkeypatch.setenv("LANG", "C")
45+
monkeypatch.setenv("NO_COLOR", "1")
46+
monkeypatch.setenv("PAGER", "cat")
47+
48+
testargs = ["cz", command, "--help"]
49+
mocker.patch.object(sys, "argv", testargs)
50+
with pytest.raises(SystemExit):
51+
cli.main()
52+
53+
out, _ = capsys.readouterr()
54+
file_regression.check(out, extension=".txt")
55+
56+
57+
@pytest.mark.parametrize(
58+
"command",
59+
[
60+
Example,
61+
Info,
62+
ListCz,
63+
Schema,
64+
],
65+
)
66+
def test_simple_command_call_once(config, mocker: MockFixture, command):
67+
write_mock = mocker.patch("commitizen.out.write")
68+
command(config)()
69+
write_mock.assert_called_once()

tests/commands/test_bump_command/test_bump_command_shows_description_when_use_help_option.txt renamed to tests/commands/test_common_command/test_command_shows_description_when_use_help_option_bump_.txt

File renamed without changes.

tests/commands/test_changelog_command/test_changelog_command_shows_description_when_use_help_option.txt renamed to tests/commands/test_common_command/test_command_shows_description_when_use_help_option_changelog_.txt

File renamed without changes.

tests/commands/test_check_command/test_check_command_shows_description_when_use_help_option.txt renamed to tests/commands/test_common_command/test_command_shows_description_when_use_help_option_check_.txt

File renamed without changes.

tests/commands/test_commit_command/test_commit_command_shows_description_when_use_help_option.txt renamed to tests/commands/test_common_command/test_command_shows_description_when_use_help_option_commit_.txt

File renamed without changes.

tests/commands/test_example_command/test_example_command_shows_description_when_use_help_option.txt renamed to tests/commands/test_common_command/test_command_shows_description_when_use_help_option_example_.txt

File renamed without changes.

0 commit comments

Comments
 (0)