Skip to content

Commit 05668cd

Browse files
committed
test(test_conf.py): add test case for specify yaml and json files
1 parent f4dc9d9 commit 05668cd

File tree

1 file changed

+41
-3
lines changed

1 file changed

+41
-3
lines changed

tests/test_conf.py

+41-3
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,27 @@
4444
}
4545
}
4646

47+
JSON_STR = r"""
48+
{
49+
"commitizen": {
50+
"name": "cz_jira",
51+
"version": "1.0.0",
52+
"version_files": [
53+
"commitizen/__version__.py",
54+
"pyproject.toml"
55+
]
56+
}
57+
}
58+
"""
59+
60+
YAML_STR = """
61+
commitizen:
62+
name: cz_jira
63+
version: 1.0.0
64+
version_files:
65+
- commitizen/__version__.py
66+
- pyproject.toml
67+
"""
4768

4869
_settings: dict[str, Any] = {
4970
"name": "cz_jira",
@@ -160,13 +181,30 @@ def test_load_empty_pyproject_toml_and_cz_toml_with_config(_, tmpdir):
160181

161182
def test_load_pyproject_toml_not_in_root_folder(_, tmpdir):
162183
with tmpdir.as_cwd():
163-
_not_root_path = tmpdir.mkdir("not_in_root")
164-
p = tmpdir.join("./not_in_root/pyproject.toml")
165-
p.write(PYPROJECT)
184+
_not_root_path = tmpdir.mkdir("not_in_root").join("pyproject.toml")
185+
_not_root_path.write(PYPROJECT)
166186

167187
cfg = config.read_cfg(filepath="./not_in_root/pyproject.toml")
168188
assert cfg.settings == _settings
169189

190+
def test_load_cz_json_not_in_root_folder(_, tmpdir):
191+
with tmpdir.as_cwd():
192+
_not_root_path = tmpdir.mkdir("not_in_root").join(".cz.json")
193+
_not_root_path.write(JSON_STR)
194+
195+
cfg = config.read_cfg(filepath="./not_in_root/.cz.json")
196+
json_cfg_by_class = config.JsonConfig(data=JSON_STR, path=_not_root_path)
197+
assert cfg.settings == json_cfg_by_class.settings
198+
199+
def test_load_cz_yaml_not_in_root_folder(_, tmpdir):
200+
with tmpdir.as_cwd():
201+
_not_root_path = tmpdir.mkdir("not_in_root").join(".cz.yaml")
202+
_not_root_path.write(YAML_STR)
203+
204+
cfg = config.read_cfg(filepath="./not_in_root/.cz.yaml")
205+
yaml_cfg_by_class = config.YAMLConfig(data=JSON_STR, path=_not_root_path)
206+
assert cfg.settings == yaml_cfg_by_class._settings
207+
170208

171209
class TestTomlConfig:
172210
def test_init_empty_config_content(self, tmpdir):

0 commit comments

Comments
 (0)