-
Notifications
You must be signed in to change notification settings - Fork 236
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(cli-generate-config): ensure configuration types are always toml …
…parsable (#785)
- Loading branch information
1 parent
253c99e
commit 758e649
Showing
3 changed files
with
42 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,44 +1,61 @@ | ||
from __future__ import annotations | ||
|
||
import json | ||
from typing import TYPE_CHECKING | ||
|
||
import pytest | ||
import tomlkit | ||
|
||
from semantic_release.cli.commands.generate_config import generate_config | ||
from semantic_release.cli.config import RawConfig | ||
|
||
if TYPE_CHECKING: | ||
from typing import Any | ||
|
||
from tests.command_line.conftest import CliRunner | ||
|
||
|
||
@pytest.fixture | ||
def raw_config_dict() -> dict[str, Any]: | ||
return RawConfig().model_dump(mode="json", exclude_none=True) | ||
|
||
|
||
@pytest.mark.parametrize("args", [(), ("--format", "toml"), ("--format", "TOML")]) | ||
def test_generate_config_toml(cli_runner, args): | ||
def test_generate_config_toml( | ||
cli_runner: CliRunner, args: tuple[str], raw_config_dict: dict[str, Any] | ||
): | ||
expected_config_as_str = tomlkit.dumps( | ||
{"semantic_release": raw_config_dict} | ||
).strip() | ||
|
||
result = cli_runner.invoke(generate_config, args) | ||
|
||
assert result.exit_code == 0 | ||
assert ( | ||
result.output.strip() | ||
== tomlkit.dumps( | ||
{"semantic_release": RawConfig().model_dump(exclude_none=True)} | ||
).strip() | ||
) | ||
assert expected_config_as_str == result.output.strip() | ||
|
||
|
||
@pytest.mark.parametrize("args", [("--format", "json"), ("--format", "JSON")]) | ||
def test_generate_config_json(cli_runner, args): | ||
def test_generate_config_json( | ||
cli_runner: CliRunner, args: tuple[str], raw_config_dict: dict[str, Any] | ||
): | ||
expected_config_as_str = json.dumps( | ||
{"semantic_release": raw_config_dict}, indent=4 | ||
).strip() | ||
|
||
result = cli_runner.invoke(generate_config, args) | ||
|
||
assert result.exit_code == 0 | ||
assert ( | ||
result.output.strip() | ||
== json.dumps( | ||
{"semantic_release": RawConfig().model_dump(exclude_none=True)}, indent=4 | ||
).strip() | ||
) | ||
assert expected_config_as_str == result.output.strip() | ||
|
||
|
||
def test_generate_config_pyproject_toml(cli_runner): | ||
def test_generate_config_pyproject_toml( | ||
cli_runner: CliRunner, raw_config_dict: dict[str, Any] | ||
): | ||
expected_config_as_str = tomlkit.dumps( | ||
{"tool": {"semantic_release": raw_config_dict}} | ||
).strip() | ||
|
||
result = cli_runner.invoke(generate_config, ["--format", "toml", "--pyproject"]) | ||
|
||
assert result.exit_code == 0 | ||
assert ( | ||
result.output.strip() | ||
== tomlkit.dumps( | ||
{"tool": {"semantic_release": RawConfig().model_dump(exclude_none=True)}} | ||
).strip() | ||
) | ||
assert expected_config_as_str == result.output.strip() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters