Skip to content

Commit

Permalink
test: extend tests for 'TestJsonConfig' and 'TestYamlConfig'
Browse files Browse the repository at this point in the history
  • Loading branch information
marcosdotme authored and Lee-W committed May 22, 2024
1 parent 4bf8ca6 commit 912fda8
Showing 1 changed file with 28 additions and 10 deletions.
38 changes: 28 additions & 10 deletions tests/test_conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -255,35 +255,53 @@ def test_init_with_invalid_config_content(
config.TomlConfig(data=existing_content, path=path)


@pytest.mark.parametrize(
"config_file, exception_string",
[
(".cz.json", r"\.cz\.json"),
("cz.json", r"cz\.json"),
],
ids=[".cz.json", "cz.json"],
)
class TestJsonConfig:
def test_init_empty_config_content(self, tmpdir):
path = tmpdir.mkdir("commitizen").join(".cz.json")
def test_init_empty_config_content(self, tmpdir, config_file, exception_string):
path = tmpdir.mkdir("commitizen").join(config_file)
json_config = config.JsonConfig(data="{}", path=path)
json_config.init_empty_config_content()

with open(path, encoding="utf-8") as json_file:
assert json.load(json_file) == {"commitizen": {}}

def test_init_with_invalid_config_content(self, tmpdir):
def test_init_with_invalid_config_content(
self, tmpdir, config_file, exception_string
):
existing_content = "invalid json content"
path = tmpdir.mkdir("commitizen").join(".cz.json")
path = tmpdir.mkdir("commitizen").join(config_file)

with pytest.raises(InvalidConfigurationError, match=r"\.cz\.json"):
with pytest.raises(InvalidConfigurationError, match=exception_string):
config.JsonConfig(data=existing_content, path=path)


@pytest.mark.parametrize(
"config_file, exception_string",
[
(".cz.yaml", r"\.cz\.yaml"),
("cz.yaml", r"cz\.yaml"),
],
ids=[".cz.yaml", "cz.yaml"],
)
class TestYamlConfig:
def test_init_empty_config_content(self, tmpdir):
path = tmpdir.mkdir("commitizen").join(".cz.yaml")
def test_init_empty_config_content(self, tmpdir, config_file, exception_string):
path = tmpdir.mkdir("commitizen").join(config_file)
yaml_config = config.YAMLConfig(data="{}", path=path)
yaml_config.init_empty_config_content()

with open(path) as yaml_file:
assert yaml.safe_load(yaml_file) == {"commitizen": {}}

def test_init_with_invalid_content(self, tmpdir):
def test_init_with_invalid_content(self, tmpdir, config_file, exception_string):
existing_content = "invalid: .cz.yaml: content: maybe?"
path = tmpdir.mkdir("commitizen").join(".cz.yaml")
path = tmpdir.mkdir("commitizen").join(config_file)

with pytest.raises(InvalidConfigurationError, match=r"\.cz\.yaml"):
with pytest.raises(InvalidConfigurationError, match=exception_string):
config.YAMLConfig(data=existing_content, path=path)

0 comments on commit 912fda8

Please sign in to comment.