-
-
Notifications
You must be signed in to change notification settings - Fork 335
Expand file tree
/
Copy pathtest_cli_config_integration.py
More file actions
90 lines (68 loc) · 2.86 KB
/
test_cli_config_integration.py
File metadata and controls
90 lines (68 loc) · 2.86 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
from __future__ import annotations
from typing import TYPE_CHECKING
import pytest
from commitizen.exceptions import CommitMessageLengthExceededError, DryRunExit
if TYPE_CHECKING:
from pathlib import Path
from tests.utils import UtilFixture
def _write_pyproject_with_message_length_limit(
tmp_path: Path, monkeypatch: pytest.MonkeyPatch, message_length_limit: int
) -> None:
(tmp_path / "pyproject.toml").write_text(
"[tool.commitizen]\n"
'name = "cz_conventional_commits"\n'
f"message_length_limit = {message_length_limit}\n",
encoding="utf-8",
)
monkeypatch.chdir(tmp_path)
def _mock_commit_prompt(mocker, *, subject: str) -> None:
mocker.patch(
"questionary.prompt",
return_value={
"prefix": "feat",
"subject": subject,
"scope": "",
"is_breaking_change": False,
"body": "",
"footer": "",
},
)
@pytest.mark.usefixtures("tmp_commitizen_project")
def test_cli_check_reads_message_length_limit_from_pyproject(
util: UtilFixture, monkeypatch: pytest.MonkeyPatch, tmp_path: Path
):
_write_pyproject_with_message_length_limit(tmp_path, monkeypatch, 10)
long_message_file = tmp_path / "long_message.txt"
long_message_file.write_text("feat: this is definitely too long", encoding="utf-8")
with pytest.raises(CommitMessageLengthExceededError):
util.run_cli("check", "--commit-msg-file", str(long_message_file))
@pytest.mark.usefixtures("tmp_commitizen_project")
def test_cli_commit_reads_message_length_limit_from_pyproject(
util: UtilFixture,
monkeypatch: pytest.MonkeyPatch,
mocker,
tmp_path: Path,
):
_write_pyproject_with_message_length_limit(tmp_path, monkeypatch, 10)
_mock_commit_prompt(mocker, subject="this is definitely too long")
mocker.patch("commitizen.git.is_staging_clean", return_value=False)
with pytest.raises(CommitMessageLengthExceededError):
util.run_cli("commit", "--dry-run")
@pytest.mark.usefixtures("tmp_commitizen_project")
def test_cli_check_cli_overrides_message_length_limit_from_pyproject(
util: UtilFixture, monkeypatch: pytest.MonkeyPatch, tmp_path: Path
):
_write_pyproject_with_message_length_limit(tmp_path, monkeypatch, 10)
util.run_cli("check", "-l", "0", "--message", "feat: this is definitely too long")
@pytest.mark.usefixtures("tmp_commitizen_project")
def test_cli_commit_cli_overrides_message_length_limit_from_pyproject(
util: UtilFixture,
monkeypatch: pytest.MonkeyPatch,
mocker,
tmp_path: Path,
):
_write_pyproject_with_message_length_limit(tmp_path, monkeypatch, 10)
_mock_commit_prompt(mocker, subject="this is definitely too long")
mocker.patch("commitizen.git.is_staging_clean", return_value=False)
with pytest.raises(DryRunExit):
util.run_cli("commit", "--dry-run", "-l", "100")