Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 33bfe1d

Browse files
danvergaraLee-W
authored andcommitted
test(test_cs_customize): add support for testing customization for JsonConfig class
120
1 parent 61a06f2 commit 33bfe1d

File tree

1 file changed

+153
-29
lines changed

1 file changed

+153
-29
lines changed

tests/test_cz_customize.py

+153-29
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,10 @@
11
import pytest
22

3-
from commitizen.config import BaseConfig, TomlConfig
3+
from commitizen.config import BaseConfig, JsonConfig, TomlConfig
44
from commitizen.cz.customize import CustomizeCommitsCz
55
from commitizen.exceptions import MissingCzCustomizeConfigError
66

7-
8-
@pytest.fixture(scope="module")
9-
def config():
10-
toml_str = r"""
7+
TOML_STR = r"""
118
[tool.commitizen.customize]
129
message_template = "{{change_type}}:{% if show_message %} {{message}}{% endif %}"
1310
example = "feature: this feature enable customize through config file"
@@ -36,8 +33,154 @@ def config():
3633
type = "confirm"
3734
name = "show_message"
3835
message = "Do you want to add body message in commit?"
36+
"""
37+
38+
JSON_STR = r"""
39+
{
40+
"commitizen": {
41+
"name": "cz_jira",
42+
"version": "1.0.0",
43+
"version_files": [
44+
"commitizen/__version__.py",
45+
"pyproject.toml"
46+
],
47+
"customize": {
48+
"message_template": "{{change_type}}:{% if show_message %} {{message}}{% endif %}",
49+
"example": "feature: this feature enable customize through config file",
50+
"schema": "<type>: <body>",
51+
"schema_pattern": "(feature|bug fix):(\\s.*)",
52+
"bump_pattern": "^(break|new|fix|hotfix)",
53+
"bump_map": {
54+
"break": "MAJOR",
55+
"new": "MINOR",
56+
"fix": "PATCH",
57+
"hotfix": "PATCH"
58+
},
59+
"info": "This is a customized cz.",
60+
"questions": [
61+
{
62+
"type": "list",
63+
"name": "change_type",
64+
"choices": [
65+
{
66+
"value": "feature",
67+
"name": "feature: A new feature."
68+
},
69+
{
70+
"value": "bug fix",
71+
"name": "bug fix: A bug fix."
72+
}
73+
],
74+
"message": "Select the type of change you are committing"
75+
},
76+
{
77+
"type": "input",
78+
"name": "message",
79+
"message": "Body."
80+
},
81+
{
82+
"type": "confirm",
83+
"name": "show_message",
84+
"message": "Do you want to add body message in commit?"
85+
}
86+
]
87+
}
88+
}
89+
}
90+
"""
91+
92+
TOML_STR_INFO_PATH = """
93+
[tool.commitizen.customize]
94+
message_template = "{{change_type}}:{% if show_message %} {{message}}{% endif %}"
95+
example = "feature: this feature enable customize through config file"
96+
schema = "<type>: <body>"
97+
bump_pattern = "^(break|new|fix|hotfix)"
98+
bump_map = {"break" = "MAJOR", "new" = "MINOR", "fix" = "PATCH", "hotfix" = "PATCH"}
99+
info_path = "info.txt"
100+
"""
101+
102+
JSON_STR_INFO_PATH = r"""
103+
{
104+
"commitizen": {
105+
"customize": {
106+
"message_template": "{{change_type}}:{% if show_message %} {{message}}{% endif %}",
107+
"example": "feature: this feature enable customize through config file",
108+
"schema": "<type>: <body>",
109+
"bump_pattern": "^(break|new|fix|hotfix)",
110+
"bump_map": {
111+
"break": "MAJOR",
112+
"new": "MINOR",
113+
"fix": "PATCH",
114+
"hotfix": "PATCH"
115+
},
116+
"info_path": "info.txt"
117+
}
118+
}
119+
}
120+
"""
121+
122+
TOML_STR_WITHOUT_INFO = """
123+
[tool.commitizen.customize]
124+
message_template = "{{change_type}}:{% if show_message %} {{message}}{% endif %}"
125+
example = "feature: this feature enable customize through config file"
126+
schema = "<type>: <body>"
127+
bump_pattern = "^(break|new|fix|hotfix)"
128+
bump_map = {"break" = "MAJOR", "new" = "MINOR", "fix" = "PATCH", "hotfix" = "PATCH"}
129+
"""
130+
131+
JSON_STR_WITHOUT_PATH = r"""
132+
{
133+
"commitizen": {
134+
"customize": {
135+
"message_template": "{{change_type}}:{% if show_message %} {{message}}{% endif %}",
136+
"example": "feature: this feature enable customize through config file",
137+
"schema": "<type>: <body>",
138+
"bump_pattern": "^(break|new|fix|hotfix)",
139+
"bump_map": {
140+
"break": "MAJOR",
141+
"new": "MINOR",
142+
"fix": "PATCH",
143+
"hotfix": "PATCH"
144+
}
145+
}
146+
}
147+
}
148+
"""
149+
150+
151+
@pytest.fixture(
152+
params=[
153+
TomlConfig(data=TOML_STR, path="not_exist.toml"),
154+
JsonConfig(data=JSON_STR, path="not_exist.json"),
155+
]
156+
)
157+
def config(request):
158+
"""Parametrize the config fixture
159+
160+
This fixture allow to test multiple config formats,
161+
without add the builtin parametrize decorator
39162
"""
40-
return TomlConfig(data=toml_str, path="not_exist.toml")
163+
return request.param
164+
165+
166+
@pytest.fixture(
167+
params=[
168+
TomlConfig(data=TOML_STR_INFO_PATH, path="not_exist.toml"),
169+
JsonConfig(data=JSON_STR_INFO_PATH, path="not_exist.json"),
170+
]
171+
)
172+
def config_info(request):
173+
return request.param
174+
175+
176+
@pytest.fixture(
177+
params=[
178+
TomlConfig(data=TOML_STR_WITHOUT_INFO, path="not_exist.toml"),
179+
JsonConfig(data=JSON_STR_WITHOUT_PATH, path="not_exist.json"),
180+
]
181+
)
182+
def config_without_info(request):
183+
return request.param
41184

42185

43186
def test_initialize_cz_customize_failed():
@@ -126,34 +269,15 @@ def test_info(config):
126269
assert "This is a customized cz." in cz.info()
127270

128271

129-
def test_info_with_info_path(tmpdir):
272+
def test_info_with_info_path(tmpdir, config_info):
130273
with tmpdir.as_cwd():
131274
tmpfile = tmpdir.join("info.txt")
132275
tmpfile.write("Test info")
133276

134-
toml_str = """
135-
[tool.commitizen.customize]
136-
message_template = "{{change_type}}:{% if show_message %} {{message}}{% endif %}"
137-
example = "feature: this feature enable customize through config file"
138-
schema = "<type>: <body>"
139-
bump_pattern = "^(break|new|fix|hotfix)"
140-
bump_map = {"break" = "MAJOR", "new" = "MINOR", "fix" = "PATCH", "hotfix" = "PATCH"}
141-
info_path = "info.txt"
142-
"""
143-
config = TomlConfig(data=toml_str, path="not_exist.toml")
144-
cz = CustomizeCommitsCz(config)
277+
cz = CustomizeCommitsCz(config_info)
145278
assert "Test info" in cz.info()
146279

147280

148-
def test_info_without_info():
149-
toml_str = """
150-
[tool.commitizen.customize]
151-
message_template = "{{change_type}}:{% if show_message %} {{message}}{% endif %}"
152-
example = "feature: this feature enable customize through config file"
153-
schema = "<type>: <body>"
154-
bump_pattern = "^(break|new|fix|hotfix)"
155-
bump_map = {"break" = "MAJOR", "new" = "MINOR", "fix" = "PATCH", "hotfix" = "PATCH"}
156-
"""
157-
config = TomlConfig(data=toml_str, path="not_exist.toml")
158-
cz = CustomizeCommitsCz(config)
281+
def test_info_without_info(config_without_info):
282+
cz = CustomizeCommitsCz(config_without_info)
159283
assert cz.info() is None

0 commit comments

Comments
 (0)