Public Access
Post-merge / detect-type (push) Successful in 6s
Post-merge / validate-commit-msg (push) Successful in 7s
Post-merge / configure-repo (push) Successful in 12s
Post-merge / release (push) Failing after 48s
Post-merge / sync-wiki (push) Has been skipped
Post-merge / vikunja (push) Has been skipped
Post-merge / badges (push) Successful in 48s
91 lines
4.2 KiB
Python
91 lines
4.2 KiB
Python
"""Unit tests for devx.tools.check_config."""
|
|
|
|
from pathlib import Path
|
|
|
|
from click.testing import CliRunner
|
|
|
|
from devx.tools.check_config import cli
|
|
|
|
|
|
class TestCheckConfig:
|
|
def test_valid_config(self, tmp_path: Path) -> None:
|
|
"""A valid [tool.devx] section with consistent versions passes."""
|
|
runner = CliRunner()
|
|
with runner.isolated_filesystem(temp_dir=str(tmp_path)) as fs:
|
|
Path(fs, "pyproject.toml").write_text(
|
|
'[project]\nname = "test"\n'
|
|
'[project.optional-dependencies]\nci = ["devx>=0.15.0"]\ndev = ["devx>=0.15.0"]\n'
|
|
'[tool.devx]\ntask_prefix = "TEST"\nvikunja_project_id = 1\nrepo_owner = "owner"\nrepo_name = "test"\n'
|
|
)
|
|
result = runner.invoke(cli)
|
|
assert result.exit_code == 0
|
|
assert "Configuration OK" in result.output
|
|
|
|
def test_missing_tool_devx_section(self, tmp_path: Path) -> None:
|
|
"""Missing [tool.devx] section fails with error."""
|
|
runner = CliRunner()
|
|
with runner.isolated_filesystem(temp_dir=str(tmp_path)) as fs:
|
|
Path(fs, "pyproject.toml").write_text('[project]\nname = "test"\n')
|
|
result = runner.invoke(cli)
|
|
assert result.exit_code == 1
|
|
assert "missing required keys" in result.output
|
|
|
|
def test_partial_tool_devx_section(self, tmp_path: Path) -> None:
|
|
"""Partial [tool.devx] section fails with missing keys."""
|
|
runner = CliRunner()
|
|
with runner.isolated_filesystem(temp_dir=str(tmp_path)) as fs:
|
|
Path(fs, "pyproject.toml").write_text('[project]\nname = "test"\n[tool.devx]\ntask_prefix = "TEST"\n')
|
|
result = runner.invoke(cli)
|
|
assert result.exit_code == 1
|
|
assert "missing required keys" in result.output
|
|
assert "vikunja_project_id" in result.output
|
|
assert "repo_owner" in result.output
|
|
assert "repo_name" in result.output
|
|
|
|
def test_version_mismatch(self, tmp_path: Path) -> None:
|
|
"""Version mismatch across extras fails."""
|
|
runner = CliRunner()
|
|
with runner.isolated_filesystem(temp_dir=str(tmp_path)) as fs:
|
|
Path(fs, "pyproject.toml").write_text(
|
|
'[project]\nname = "test"\n'
|
|
"[project.optional-dependencies]\n"
|
|
'ci = ["devx>=0.15.0"]\n'
|
|
'dev = ["devx>=0.14.2"]\n'
|
|
'[tool.devx]\ntask_prefix = "TEST"\nvikunja_project_id = 1\nrepo_owner = "owner"\nrepo_name = "test"\n'
|
|
)
|
|
result = runner.invoke(cli)
|
|
assert result.exit_code == 1
|
|
assert "version mismatch" in result.output
|
|
|
|
def test_no_pyproject_file(self, tmp_path: Path) -> None:
|
|
"""Missing pyproject.toml fails."""
|
|
runner = CliRunner()
|
|
with runner.isolated_filesystem(temp_dir=str(tmp_path)):
|
|
result = runner.invoke(cli)
|
|
assert result.exit_code == 1
|
|
assert "not found" in result.output
|
|
|
|
def test_no_extras_passes(self, tmp_path: Path) -> None:
|
|
"""No optional-dependencies with devx is fine (no versions to compare)."""
|
|
runner = CliRunner()
|
|
with runner.isolated_filesystem(temp_dir=str(tmp_path)) as fs:
|
|
Path(fs, "pyproject.toml").write_text(
|
|
'[project]\nname = "test"\n'
|
|
'[tool.devx]\ntask_prefix = "TEST"\nvikunja_project_id = 1\nrepo_owner = "owner"\nrepo_name = "test"\n'
|
|
)
|
|
result = runner.invoke(cli)
|
|
assert result.exit_code == 0
|
|
assert "Configuration OK" in result.output
|
|
|
|
def test_single_extra_passes(self, tmp_path: Path) -> None:
|
|
"""Single extra with devx version is fine (no mismatch possible)."""
|
|
runner = CliRunner()
|
|
with runner.isolated_filesystem(temp_dir=str(tmp_path)) as fs:
|
|
Path(fs, "pyproject.toml").write_text(
|
|
'[project]\nname = "test"\n'
|
|
'[project.optional-dependencies]\nci = ["devx>=0.15.0", "pytest"]\n'
|
|
'[tool.devx]\ntask_prefix = "TEST"\nvikunja_project_id = 1\nrepo_owner = "owner"\nrepo_name = "test"\n'
|
|
)
|
|
result = runner.invoke(cli)
|
|
assert result.exit_code == 0
|