Skip to content

Commit

Permalink
test(commands): add skip_if_below_py_3_10 as the message of argument …
Browse files Browse the repository at this point in the history
…changes in python 3.10

Optional arguments -> options
  • Loading branch information
Lee-W committed May 22, 2024
1 parent 4636e50 commit 8f4dbe9
Show file tree
Hide file tree
Showing 11 changed files with 34 additions and 2 deletions.
3 changes: 2 additions & 1 deletion tests/commands/test_bump_command.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
NoVersionSpecifiedError,
)
from commitizen.changelog_formats import ChangelogFormat
from tests.utils import create_file_and_commit, create_tag
from tests.utils import create_file_and_commit, create_tag, skip_below_py_3_10


@pytest.mark.parametrize(
Expand Down Expand Up @@ -1451,6 +1451,7 @@ def test_bump_changelog_contains_increment_only(mocker, tmp_commitizen_project,
assert "2.0.0" not in out


@skip_below_py_3_10
def test_bump_command_shows_description_when_use_help_option(
mocker: MockFixture, capsys, file_regression
):
Expand Down
2 changes: 2 additions & 0 deletions tests/commands/test_changelog_command.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
merge_branch,
switch_branch,
wait_for_tag,
skip_below_py_3_10,
)


Expand Down Expand Up @@ -1639,6 +1640,7 @@ def test_export_changelog_template_from_plugin(
assert target.read_text() == tpl


@skip_below_py_3_10
def test_changelog_command_shows_description_when_use_help_option(
mocker: MockFixture, capsys, file_regression
):
Expand Down
3 changes: 2 additions & 1 deletion tests/commands/test_check_command.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
InvalidCommitMessageError,
NoCommitsFoundError,
)
from tests.utils import create_file_and_commit
from tests.utils import create_file_and_commit, skip_below_py_3_10

COMMIT_LOG = [
"refactor: A code change that neither fixes a bug nor adds a feature",
Expand Down Expand Up @@ -416,6 +416,7 @@ def test_check_conventional_commit_succeed_with_git_diff(mocker, capsys):
assert "Commit validation: successful!" in out


@skip_below_py_3_10
def test_check_command_shows_description_when_use_help_option(
mocker: MockFixture, capsys, file_regression
):
Expand Down
3 changes: 3 additions & 0 deletions tests/commands/test_commit_command.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@
NothingToCommitError,
)

from tests.utils import skip_below_py_3_10


@pytest.fixture
def staging_is_clean(mocker: MockFixture, tmp_git_project):
Expand Down Expand Up @@ -409,6 +411,7 @@ def test_commit_command_with_message_length_limit(config, mocker: MockFixture):
commands.Commit(config, {"message_length_limit": message_length - 1})()


@skip_below_py_3_10
def test_commit_command_shows_description_when_use_help_option(
mocker: MockFixture, capsys, file_regression
):
Expand Down
3 changes: 3 additions & 0 deletions tests/commands/test_example_command.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,16 @@

from pytest_mock import MockerFixture

from tests.utils import skip_below_py_3_10


def test_example(config, mocker: MockerFixture):
write_mock = mocker.patch("commitizen.out.write")
commands.Example(config)()
write_mock.assert_called_once()


@skip_below_py_3_10
def test_example_command_shows_description_when_use_help_option(
mocker: MockerFixture, capsys, file_regression
):
Expand Down
2 changes: 2 additions & 0 deletions tests/commands/test_info_command.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from commitizen import cli, commands

from pytest_mock import MockerFixture
from tests.utils import skip_below_py_3_10


def test_info(config, mocker: MockerFixture):
Expand All @@ -11,6 +12,7 @@ def test_info(config, mocker: MockerFixture):
write_mock.assert_called_once()


@skip_below_py_3_10
def test_info_command_shows_description_when_use_help_option(
mocker: MockerFixture, capsys, file_regression
):
Expand Down
3 changes: 3 additions & 0 deletions tests/commands/test_init_command.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
from commitizen.__version__ import __version__
from commitizen.exceptions import InitFailedError, NoAnswersError

from tests.utils import skip_below_py_3_10


class FakeQuestion:
def __init__(self, expected_return):
Expand Down Expand Up @@ -254,6 +256,7 @@ def test_pre_commit_exec_failed(
commands.Init(config)()


@skip_below_py_3_10
def test_init_command_shows_description_when_use_help_option(
mocker: MockFixture, capsys, file_regression
):
Expand Down
3 changes: 3 additions & 0 deletions tests/commands/test_ls_command.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,16 @@

from pytest_mock import MockerFixture

from tests.utils import skip_below_py_3_10


def test_list_cz(config, mocker: MockerFixture):
write_mock = mocker.patch("commitizen.out.write")
commands.ListCz(config)()
write_mock.assert_called_once()


@skip_below_py_3_10
def test_ls_command_shows_description_when_use_help_option(
mocker: MockerFixture, capsys, file_regression
):
Expand Down
3 changes: 3 additions & 0 deletions tests/commands/test_schema_command.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,16 @@

from pytest_mock import MockerFixture

from tests.utils import skip_below_py_3_10


def test_schema(config, mocker: MockerFixture):
write_mock = mocker.patch("commitizen.out.write")
commands.Schema(config)()
write_mock.assert_called_once()


@skip_below_py_3_10
def test_schema_command_shows_description_when_use_help_option(
mocker: MockerFixture, capsys, file_regression
):
Expand Down
2 changes: 2 additions & 0 deletions tests/commands/test_version_command.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
from commitizen import cli, 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(config, capsys):
Expand Down Expand Up @@ -108,6 +109,7 @@ 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
):
Expand Down
9 changes: 9 additions & 0 deletions tests/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,21 @@

import time
import uuid
import sys
from pathlib import Path

import pytest
from deprecated import deprecated

from commitizen import cmd, exceptions, git


skip_below_py_3_10 = pytest.mark.skipif(
sys.version_info < (3, 10),
reason="The output meesage of argparse is different between Python 3.10 and lower than Python 3.10",
)


class FakeCommand:
def __init__(self, out=None, err=None, return_code=0):
self.out = out
Expand Down

0 comments on commit 8f4dbe9

Please sign in to comment.