Files
ClaudeInit/tests/test_config.py
T
2026-04-13 22:04:05 +02:00

51 lines
1.7 KiB
Python

"""Tests for myclaude.config module."""
import json
from pathlib import Path
from unittest.mock import patch
import pytest
from myclaude.config import load_config, save_config
@pytest.mark.parametrize("repo_url", [
"git@gitea.example.com:user/skills.git",
"git@gitea.internal:org/claude.git",
])
def test_i_can_save_config(tmp_path: Path, repo_url: str) -> None:
config_file = tmp_path / "config.json"
with patch("myclaude.config.CONFIG_DIR", tmp_path), \
patch("myclaude.config.CONFIG_FILE", config_file):
save_config(repo_url)
content = json.loads(config_file.read_text())
assert content["repo_url"] == repo_url
@pytest.mark.parametrize("repo_url", [
"git@gitea.example.com:user/skills.git",
"git@gitea.internal:org/claude.git",
])
def test_i_can_load_config(tmp_path: Path, repo_url: str) -> None:
config_file = tmp_path / "config.json"
config_file.write_text(json.dumps({"repo_url": repo_url}))
with patch("myclaude.config.CONFIG_FILE", config_file):
result = load_config()
assert result["repo_url"] == repo_url
def test_i_can_update_repo_url(tmp_path: Path) -> None:
config_file = tmp_path / "config.json"
config_file.write_text(json.dumps({"repo_url": "git@old.example.com:user/old.git"}))
with patch("myclaude.config.CONFIG_DIR", tmp_path), \
patch("myclaude.config.CONFIG_FILE", config_file):
save_config("git@new.example.com:user/new.git")
content = json.loads(config_file.read_text())
assert content["repo_url"] == "git@new.example.com:user/new.git"
def test_i_cannot_load_config_when_file_missing(tmp_path: Path) -> None:
with patch("myclaude.config.CONFIG_FILE", tmp_path / "config.json"):
with pytest.raises(FileNotFoundError):
load_config()