Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 1 addition & 14 deletions tests/commands/test_bump_command.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
NotAllowed,
NoVersionSpecifiedError,
)
from tests.utils import create_file_and_commit, create_tag, skip_below_py_3_13
from tests.utils import create_file_and_commit, create_tag

if TYPE_CHECKING:
import py
Expand Down Expand Up @@ -1438,19 +1438,6 @@ def test_bump_changelog_contains_increment_only(mocker, tmp_commitizen_project,
assert "2.0.0" not in out


@skip_below_py_3_13
def test_bump_command_shows_description_when_use_help_option(
mocker: MockFixture, capsys, file_regression
):
testargs = ["cz", "bump", "--help"]
mocker.patch.object(sys, "argv", testargs)
with pytest.raises(SystemExit):
cli.main()

out, _ = capsys.readouterr()
file_regression.check(out, extension=".txt")


@pytest.mark.usefixtures("tmp_commitizen_project")
def test_bump_get_next(mocker: MockFixture, capsys):
create_file_and_commit("feat: new file")
Expand Down
14 changes: 0 additions & 14 deletions tests/commands/test_changelog_command.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@
create_tag,
get_current_branch,
merge_branch,
skip_below_py_3_13,
switch_branch,
wait_for_tag,
)
Expand Down Expand Up @@ -1927,16 +1926,3 @@ class FakeTemplate:

assert not target.exists()
assert "Template filename is not set" in str(exc_info.value)


@skip_below_py_3_13
def test_changelog_command_shows_description_when_use_help_option(
mocker: MockFixture, capsys, file_regression
):
testargs = ["cz", "changelog", "--help"]
mocker.patch.object(sys, "argv", testargs)
with pytest.raises(SystemExit):
cli.main()

out, _ = capsys.readouterr()
file_regression.check(out, extension=".txt")
15 changes: 1 addition & 14 deletions tests/commands/test_check_command.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
InvalidCommitMessageError,
NoCommitsFoundError,
)
from tests.utils import create_file_and_commit, skip_below_py_3_13
from tests.utils import create_file_and_commit

if TYPE_CHECKING:
import re
Expand Down Expand Up @@ -427,19 +427,6 @@ def test_check_conventional_commit_succeed_with_git_diff(mocker, capsys):
assert "Commit validation: successful!" in out


@skip_below_py_3_13
def test_check_command_shows_description_when_use_help_option(
mocker: MockFixture, capsys, file_regression
):
testargs = ["cz", "check", "--help"]
mocker.patch.object(sys, "argv", testargs)
with pytest.raises(SystemExit):
cli.main()

out, _ = capsys.readouterr()
file_regression.check(out, extension=".txt")


def test_check_command_with_message_length_limit(config, mocker: MockFixture):
success_mock = mocker.patch("commitizen.out.success")
message = "fix(scope): some commit message"
Expand Down
17 changes: 1 addition & 16 deletions tests/commands/test_commit_command.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
import os
import sys
from unittest.mock import ANY

import pytest
from pytest_mock import MockFixture

from commitizen import cli, cmd, commands
from commitizen import cmd, commands
from commitizen.cz.exceptions import CzException
from commitizen.cz.utils import get_backup_file_path
from commitizen.exceptions import (
Expand All @@ -19,7 +18,6 @@
NotAllowed,
NothingToCommitError,
)
from tests.utils import skip_below_py_3_13


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


@skip_below_py_3_13
def test_commit_command_shows_description_when_use_help_option(
mocker: MockFixture, capsys, file_regression
):
testargs = ["cz", "commit", "--help"]
mocker.patch.object(sys, "argv", testargs)
with pytest.raises(SystemExit):
cli.main()

out, _ = capsys.readouterr()
file_regression.check(out, extension=".txt")


@pytest.mark.usefixtures("staging_is_clean")
@pytest.mark.parametrize(
"out", ["no changes added to commit", "nothing added to commit"]
Expand Down
69 changes: 69 additions & 0 deletions tests/commands/test_common_command.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
import sys

import pytest
from pytest_mock import MockFixture

from commitizen import cli
from commitizen.commands import Example, Info, ListCz, Schema


@pytest.mark.skipif(
sys.version_info < (3, 13),
reason="The output message of argparse is different between Python 3.13 and lower than Python 3.13",
)
@pytest.mark.parametrize(
"command",
[
"bump",
"changelog",
"check",
"commit",
"example",
"info",
"init",
"ls",
"schema",
"version",
],
)
def test_command_shows_description_when_use_help_option(
mocker: MockFixture,
capsys,
file_regression,
monkeypatch: pytest.MonkeyPatch,
command: str,
):
"""Test that the command shows the description when the help option is used.

Note: If the command description changes, please run `pytest tests/commands/test_common_command.py --regen-all` to regenerate the test files.
"""
# Force consistent terminal output
monkeypatch.setenv("COLUMNS", "80")
monkeypatch.setenv("TERM", "dumb")
monkeypatch.setenv("LC_ALL", "C")
monkeypatch.setenv("LANG", "C")
monkeypatch.setenv("NO_COLOR", "1")
monkeypatch.setenv("PAGER", "cat")
Comment on lines +41 to +46
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copied from AI output. I know COLUMNS is necessary, but not sure for the rest


testargs = ["cz", command, "--help"]
mocker.patch.object(sys, "argv", testargs)
with pytest.raises(SystemExit):
cli.main()

out, _ = capsys.readouterr()
file_regression.check(out, extension=".txt")


@pytest.mark.parametrize(
"command",
[
Example,
Info,
ListCz,
Schema,
],
)
def test_simple_command_call_once(config, mocker: MockFixture, command):
write_mock = mocker.patch("commitizen.out.write")
command(config)()
write_mock.assert_called_once()
26 changes: 0 additions & 26 deletions tests/commands/test_example_command.py

This file was deleted.

26 changes: 0 additions & 26 deletions tests/commands/test_info_command.py

This file was deleted.

17 changes: 1 addition & 16 deletions tests/commands/test_init_command.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,15 @@

import json
import os
import sys
from pathlib import Path
from typing import TYPE_CHECKING, Any

import pytest
import yaml

from commitizen import cli, cmd, commands
from commitizen import cmd, commands
from commitizen.__version__ import __version__
from commitizen.exceptions import InitFailedError, NoAnswersError
from tests.utils import skip_below_py_3_10

if TYPE_CHECKING:
from pytest_mock import MockFixture
Expand Down Expand Up @@ -275,19 +273,6 @@ def test_empty_input_returns_default(self, mocker: MockFixture, config: BaseConf
assert result == "$version" # This is the default format from DEFAULT_SETTINGS


@skip_below_py_3_10
def test_init_command_shows_description_when_use_help_option(
mocker: MockFixture, capsys, file_regression
):
testargs = ["cz", "init", "--help"]
mocker.patch.object(sys, "argv", testargs)
with pytest.raises(SystemExit):
cli.main()

out, _ = capsys.readouterr()
file_regression.check(out, extension=".txt")


def test_init_with_confirmed_tag_format(
config: BaseConfig, mocker: MockFixture, tmpdir
):
Expand Down
26 changes: 0 additions & 26 deletions tests/commands/test_ls_command.py

This file was deleted.

26 changes: 0 additions & 26 deletions tests/commands/test_schema_command.py

This file was deleted.

29 changes: 1 addition & 28 deletions tests/commands/test_version_command.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
import os
import platform
import sys

import pytest
from pytest_mock import MockerFixture

from commitizen import cli, commands
from commitizen import commands
from commitizen.__version__ import __version__
from commitizen.config.base_config import BaseConfig
from tests.utils import skip_below_py_3_10


def test_version_for_showing_project_version_error(config, capsys):
Expand Down Expand Up @@ -105,31 +103,6 @@ def test_version_use_version_provider(
mock.set_version.assert_not_called()


@skip_below_py_3_10
def test_version_command_shows_description_when_use_help_option(
mocker: MockerFixture, capsys, file_regression
):
# Force consistent terminal width for tests to avoid wrapping differences
# between single and multi-worker pytest modes
original_columns = os.environ.get("COLUMNS")
os.environ["COLUMNS"] = "80"

try:
testargs = ["cz", "version", "--help"]
mocker.patch.object(sys, "argv", testargs)
with pytest.raises(SystemExit):
cli.main()

out, _ = capsys.readouterr()
file_regression.check(out, extension=".txt")
finally:
# Restore original COLUMNS
if original_columns is not None:
os.environ["COLUMNS"] = original_columns
else:
os.environ.pop("COLUMNS", None)


@pytest.mark.parametrize(
"version, expected_version",
[
Expand Down
Loading