Skip to content

Commit

Permalink
test(test_conf.py): add test case for specify yaml and json files
Browse files Browse the repository at this point in the history
  • Loading branch information
rockleona authored and Lee-W committed Apr 11, 2024
1 parent 85a5ec2 commit 88ab61d
Showing 1 changed file with 41 additions and 3 deletions.
44 changes: 41 additions & 3 deletions tests/test_conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,27 @@
}
}

JSON_STR = r"""
{
"commitizen": {
"name": "cz_jira",
"version": "1.0.0",
"version_files": [
"commitizen/__version__.py",
"pyproject.toml"
]
}
}
"""

YAML_STR = """
commitizen:
name: cz_jira
version: 1.0.0
version_files:
- commitizen/__version__.py
- pyproject.toml
"""

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

def test_load_pyproject_toml_not_in_root_folder(_, tmpdir):
with tmpdir.as_cwd():
_not_root_path = tmpdir.mkdir("not_in_root")
p = tmpdir.join("./not_in_root/pyproject.toml")
p.write(PYPROJECT)
_not_root_path = tmpdir.mkdir("not_in_root").join("pyproject.toml")
_not_root_path.write(PYPROJECT)

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

def test_load_cz_json_not_in_root_folder(_, tmpdir):
with tmpdir.as_cwd():
_not_root_path = tmpdir.mkdir("not_in_root").join(".cz.json")
_not_root_path.write(JSON_STR)

cfg = config.read_cfg(filepath="./not_in_root/.cz.json")
json_cfg_by_class = config.JsonConfig(data=JSON_STR, path=_not_root_path)
assert cfg.settings == json_cfg_by_class.settings

def test_load_cz_yaml_not_in_root_folder(_, tmpdir):
with tmpdir.as_cwd():
_not_root_path = tmpdir.mkdir("not_in_root").join(".cz.yaml")
_not_root_path.write(YAML_STR)

cfg = config.read_cfg(filepath="./not_in_root/.cz.yaml")
yaml_cfg_by_class = config.YAMLConfig(data=JSON_STR, path=_not_root_path)
assert cfg.settings == yaml_cfg_by_class._settings


class TestTomlConfig:
def test_init_empty_config_content(self, tmpdir):
Expand Down

0 comments on commit 88ab61d

Please sign in to comment.