First version. I can init
This commit is contained in:
@@ -0,0 +1,76 @@
|
||||
"""Tests for myclaude.fs_ops module."""
|
||||
|
||||
from pathlib import Path
|
||||
|
||||
import pytest
|
||||
|
||||
from myclaude.fs_ops import (
|
||||
collect_local_skills,
|
||||
copy_claude_md_to_project,
|
||||
copy_skills_to_project,
|
||||
copy_skills_to_repo,
|
||||
)
|
||||
|
||||
|
||||
def test_i_can_copy_all_skills(tmp_project: Path, tmp_repo: Path) -> None:
|
||||
copy_skills_to_project(tmp_repo, tmp_project)
|
||||
assert (tmp_project / ".claude" / "skills" / "skill_a" / "SKILL.md").exists()
|
||||
assert (tmp_project / ".claude" / "skills" / "skill_b" / "SKILL.md").exists()
|
||||
|
||||
|
||||
@pytest.mark.parametrize("requested,expected", [
|
||||
(["skill_a"], ["skill_a"]),
|
||||
(["skill_a", "skill_b"], ["skill_a", "skill_b"]),
|
||||
])
|
||||
def test_i_can_copy_filtered_skills(
|
||||
tmp_project: Path,
|
||||
tmp_repo: Path,
|
||||
requested: list[str],
|
||||
expected: list[str],
|
||||
) -> None:
|
||||
copy_skills_to_project(tmp_repo, tmp_project, skills=requested)
|
||||
installed = collect_local_skills(tmp_project)
|
||||
assert installed == sorted(expected)
|
||||
|
||||
|
||||
def test_i_can_copy_claude_md(tmp_project: Path, tmp_repo: Path) -> None:
|
||||
copy_claude_md_to_project(tmp_repo, tmp_project)
|
||||
assert (tmp_project / "CLAUDE.md").read_text() == "# Claude Template"
|
||||
|
||||
|
||||
def test_i_cannot_init_when_skills_dir_exists(tmp_project: Path, tmp_repo: Path) -> None:
|
||||
(tmp_project / ".claude" / "skills").mkdir(parents=True)
|
||||
with pytest.raises(FileExistsError):
|
||||
copy_skills_to_project(tmp_repo, tmp_project)
|
||||
|
||||
|
||||
def test_i_can_force_overwrite_skills_dir(tmp_project: Path, tmp_repo: Path) -> None:
|
||||
skills_dir = tmp_project / ".claude" / "skills"
|
||||
(skills_dir / "old_skill").mkdir(parents=True)
|
||||
copy_skills_to_project(tmp_repo, tmp_project, force=True)
|
||||
assert not (skills_dir / "old_skill").exists()
|
||||
assert (skills_dir / "skill_a").exists()
|
||||
|
||||
|
||||
@pytest.mark.parametrize("unknown_skill", ["ghost", "unknown", "skill99"])
|
||||
def test_i_cannot_copy_unknown_skill(
|
||||
tmp_project: Path,
|
||||
tmp_repo: Path,
|
||||
unknown_skill: str,
|
||||
) -> None:
|
||||
with pytest.raises(ValueError, match=unknown_skill):
|
||||
copy_skills_to_project(tmp_repo, tmp_project, skills=[unknown_skill])
|
||||
|
||||
|
||||
def test_i_can_collect_local_skills(tmp_project: Path) -> None:
|
||||
for skill in ("skill_a", "skill_b"):
|
||||
(tmp_project / ".claude" / "skills" / skill).mkdir(parents=True)
|
||||
assert collect_local_skills(tmp_project) == ["skill_a", "skill_b"]
|
||||
|
||||
|
||||
def test_i_can_copy_skills_to_repo(tmp_project: Path, tmp_repo: Path) -> None:
|
||||
skill_dir = tmp_project / ".claude" / "skills" / "skill_a"
|
||||
skill_dir.mkdir(parents=True)
|
||||
(skill_dir / "SKILL.md").write_text("# Updated A")
|
||||
copy_skills_to_repo(tmp_project, tmp_repo)
|
||||
assert (tmp_repo / "skills" / "skill_a" / "SKILL.md").read_text() == "# Updated A"
|
||||
Reference in New Issue
Block a user