Skip to content

Commit 097ef1f

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

22 files changed

+59
-179
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-
fromtests.utilsimportcreate_file_and_commit, create_tag, skip_below_py_3_13
31+
fromtests.utilsimportcreate_file_and_commit, create_tag
3232

3333
ifTYPE_CHECKING:
3434
importpy
@@ -1438,19 +1438,6 @@ def test_bump_changelog_contains_increment_only(mocker, tmp_commitizen_project,
14381438
assert"2.0.0"notinout
14391439

14401440

1441-
@skip_below_py_3_13
1442-
deftest_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-
withpytest.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
deftest_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
assertnottarget.exists()
19291928
assert"Template filename is not set"instr(exc_info.value)
1930-
1931-
1932-
@skip_below_py_3_13
1933-
deftest_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-
withpytest.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-
fromtests.utilsimportcreate_file_and_commit, skip_below_py_3_13
18+
fromtests.utilsimportcreate_file_and_commit
1919

2020
ifTYPE_CHECKING:
2121
importre
@@ -427,19 +427,6 @@ def test_check_conventional_commit_succeed_with_git_diff(mocker, capsys):
427427
assert"Commit validation: successful!"inout
428428

429429

430-
@skip_below_py_3_13
431-
deftest_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-
withpytest.raises(SystemExit):
437-
cli.main()
438-
439-
out, _=capsys.readouterr()
440-
file_regression.check(out, extension=".txt")
441-
442-
443430
deftest_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
importos
2-
importsys
32
fromunittest.mockimportANY
43

54
importpytest
65
frompytest_mockimportMockFixture
76

8-
fromcommitizenimportcli, cmd, commands
7+
fromcommitizenimportcmd, commands
98
fromcommitizen.cz.exceptionsimportCzException
109
fromcommitizen.cz.utilsimportget_backup_file_path
1110
fromcommitizen.exceptionsimport (
@@ -19,7 +18,6 @@
1918
NotAllowed,
2019
NothingToCommitError,
2120
)
22-
fromtests.utilsimportskip_below_py_3_13
2321

2422

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

514512

515-
@skip_below_py_3_13
516-
deftest_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-
withpytest.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: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
importsys
2+
3+
importpytest
4+
frompytest_mockimportMockFixture
5+
6+
fromcommitizenimportcli
7+
8+
# Note: If the command description changes, run `pytest tests/commands/test_common_command.py --regen-all` to regenerate the test files.
9+
10+
11+
@pytest.mark.skipif(
12+
sys.version_info< (3, 13),
13+
reason="The output message of argparse is different between Python 3.13 and lower than Python 3.13",
14+
)
15+
@pytest.mark.parametrize(
16+
"command",
17+
[
18+
"bump",
19+
"changelog",
20+
"check",
21+
"commit",
22+
"example",
23+
"info",
24+
"init",
25+
"ls",
26+
"schema",
27+
"version",
28+
],
29+
)
30+
deftest_command_shows_description_when_use_help_option(
31+
mocker: MockFixture,
32+
capsys,
33+
file_regression,
34+
monkeypatch: pytest.MonkeyPatch,
35+
command: str,
36+
):
37+
monkeypatch.setenv("COLUMNS", "80")
38+
monkeypatch.setenv("TERM", "dumb")
39+
monkeypatch.setenv("LC_ALL", "C")
40+
monkeypatch.setenv("LANG", "C")
41+
monkeypatch.setenv("NO_COLOR", "1")
42+
monkeypatch.setenv("PAGER", "cat")
43+
44+
testargs= ["cz", command, "--help"]
45+
mocker.patch.object(sys, "argv", testargs)
46+
withpytest.raises(SystemExit):
47+
cli.main()
48+
49+
out, _=capsys.readouterr()
50+
file_regression.check(out, extension=".txt")

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)