Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit a4f8c20

Browse filesBrowse files
yusin huangLee-W
yusin huang
authored andcommitted
test(test_cz_search_filter.py): add test cases for search filter configuration
1 parent f77f0bc commit a4f8c20
Copy full SHA for a4f8c20

File tree

1 file changed

+76
-0
lines changed
Filter options

1 file changed

+76
-0
lines changed

‎tests/test_cz_search_filter.py

Copy file name to clipboard
+76Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
import pytest
2+
3+
from commitizen.config import TomlConfig
4+
from commitizen.cz.customize import CustomizeCommitsCz
5+
6+
TOML_WITH_SEARCH_FILTER = r"""
7+
[tool.commitizen]
8+
name = "cz_customize"
9+
10+
[tool.commitizen.customize]
11+
message_template = "{{change_type}}:{% if scope %} ({{scope}}){% endif %}{% if breaking %}!{% endif %} {{message}}"
12+
13+
[[tool.commitizen.customize.questions]]
14+
type = "select"
15+
name = "change_type"
16+
message = "Select the type of change you are committing"
17+
use_search_filter = true
18+
use_jk_keys = false
19+
choices = [
20+
{value = "fix", name = "fix: A bug fix. Correlates with PATCH in SemVer"},
21+
{value = "feat", name = "feat: A new feature. Correlates with MINOR in SemVer"},
22+
{value = "docs", name = "docs: Documentation only changes"},
23+
{value = "style", name = "style: Changes that do not affect the meaning of the code"},
24+
{value = "refactor", name = "refactor: A code change that neither fixes a bug nor adds a feature"},
25+
{value = "perf", name = "perf: A code change that improves performance"},
26+
{value = "test", name = "test: Adding missing or correcting existing tests"},
27+
{value = "build", name = "build: Changes that affect the build system or external dependencies"},
28+
{value = "ci", name = "ci: Changes to CI configuration files and scripts"}
29+
]
30+
31+
[[tool.commitizen.customize.questions]]
32+
type = "input"
33+
name = "scope"
34+
message = "What is the scope of this change? (class or file name): (press [enter] to skip)"
35+
36+
[[tool.commitizen.customize.questions]]
37+
type = "input"
38+
name = "message"
39+
message = "Write a short and imperative summary of the code changes: (lower case and no period)"
40+
"""
41+
42+
43+
@pytest.fixture
44+
def config():
45+
return TomlConfig(data=TOML_WITH_SEARCH_FILTER, path="not_exist.toml")
46+
47+
48+
def test_questions_with_search_filter(config):
49+
"""Test that questions are properly configured with search filter"""
50+
cz = CustomizeCommitsCz(config)
51+
questions = cz.questions()
52+
53+
# Test that the first question (change_type) has search filter enabled
54+
assert questions[0]["type"] == "select"
55+
assert questions[0]["name"] == "change_type"
56+
assert questions[0]["use_search_filter"] is True
57+
assert questions[0]["use_jk_keys"] is False
58+
59+
# Test that the choices are properly configured
60+
choices = questions[0]["choices"]
61+
assert len(choices) == 9 # We have 9 commit types
62+
assert choices[0]["value"] == "fix"
63+
assert choices[1]["value"] == "feat"
64+
65+
66+
def test_message_template(config):
67+
"""Test that the message template is properly configured"""
68+
cz = CustomizeCommitsCz(config)
69+
template = cz.message(
70+
{
71+
"change_type": "feat",
72+
"scope": "search",
73+
"message": "add search filter support",
74+
}
75+
)
76+
assert template == "feat: (search) add search filter support"

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.