CoolFace
Apppublic

Jack1808/Claude_Code

sourceHugging Faceupdated 4mo agoView on Hugging Face
0likes
test_entrypoints.py76 linesDownload Raw Back to cli
1"""Tests for cli/entrypoints.py — fcc-init scaffolding logic."""2 3from pathlib import Path4from unittest.mock import patch5 6 7def _run_init(tmp_home: Path) -> tuple[str, Path]:8    """Run init() with home directory redirected to tmp_home. Returns (printed output, env_file path)."""9    from cli.entrypoints import init10 11    env_file = tmp_home / ".config" / "free-claude-code" / ".env"12    printed: list[str] = []13 14    with (15        patch("pathlib.Path.home", return_value=tmp_home),16        patch(17            "builtins.print",18            side_effect=lambda *a: printed.append(" ".join(str(x) for x in a)),19        ),20    ):21        init()22 23    return "\n".join(printed), env_file24 25 26def test_init_creates_env_file(tmp_path: Path) -> None:27    """init() creates .env from the bundled template when it doesn't exist yet."""28    output, env_file = _run_init(tmp_path)29 30    assert env_file.exists()31    assert env_file.stat().st_size > 032    assert str(env_file) in output33 34 35def test_init_copies_template_content(tmp_path: Path) -> None:36    """init() writes the actual bundled env.example content, not an empty file."""37    import importlib.resources38 39    template = (40        importlib.resources.files("config").joinpath("env.example").read_text("utf-8")41    )42    _, env_file = _run_init(tmp_path)43 44    assert env_file.read_text("utf-8") == template45 46 47def test_init_creates_parent_directories(tmp_path: Path) -> None:48    """init() creates ~/.config/free-claude-code/ even if it doesn't exist."""49    config_dir = tmp_path / ".config" / "free-claude-code"50    assert not config_dir.exists()51 52    _run_init(tmp_path)53 54    assert config_dir.is_dir()55 56 57def test_init_skips_if_env_already_exists(tmp_path: Path) -> None:58    """init() does not overwrite an existing .env and prints a warning."""59    # Create it first60    _run_init(tmp_path)61 62    env_file = tmp_path / ".config" / "free-claude-code" / ".env"63    env_file.write_text("existing content", encoding="utf-8")64 65    output, _ = _run_init(tmp_path)66 67    assert env_file.read_text("utf-8") == "existing content"68    assert "already exists" in output69 70 71def test_init_prints_next_step_hint(tmp_path: Path) -> None:72    """init() tells the user to run free-claude-code after editing .env."""73    output, _ = _run_init(tmp_path)74 75    assert "free-claude-code" in output76