示例#1
0
def it_prompts_before_installing(tmp_path: Path,
                                 monkeypatch: MonkeyPatch) -> None:
    make_hooks_dir(tmp_path)

    def fake_input(prompt: str) -> str:
        assert "Are you sure you want to install hooks" in prompt
        return "Y"

    monkeypatch.setattr(builtins, "input", fake_input)
    monkeypatch.setattr(Path, "cwd", lambda: tmp_path)

    console.run(["install"])
示例#2
0
def it_unistalls_hooks(tmp_path: Path) -> None:
    hooks_dir = make_hooks_dir(tmp_path)
    whippet.install_hooks(tmp_path)
    assert_hooks_created(hooks_dir)

    whippet.uninstall_hooks(tmp_path)

    assert_no_hooks(hooks_dir)
示例#3
0
def it_installs_hooks_in_git_dir_in_ancestor_dir(tmp_path: Path) -> None:
    hooks_dir = make_hooks_dir(tmp_path)
    cwd = tmp_path / "foo" / "bar"
    cwd.mkdir(parents=True)

    whippet.install_hooks(cwd)

    assert_hooks_created(hooks_dir)
示例#4
0
def it_uninstalls(tmp_path: Path, monkeypatch: MonkeyPatch) -> None:
    hooks_dir = make_hooks_dir(tmp_path)
    monkeypatch.setattr(Path, "cwd", lambda: tmp_path)
    console.run(["install", "-y"])
    assert_hooks_created(hooks_dir)

    console.run(["uninstall", "-y"])

    assert_no_hooks(hooks_dir)
示例#5
0
def it_installs(tmp_path: Path, monkeypatch: MonkeyPatch) -> None:
    hooks_dir = make_hooks_dir(tmp_path)

    monkeypatch.setattr(builtins, "input", lambda _: "Y")
    monkeypatch.setattr(Path, "cwd", lambda: tmp_path)

    console.run(["install"])

    assert_hooks_created(hooks_dir)
示例#6
0
def it_supports_assume_yes(tmp_path: Path, monkeypatch: MonkeyPatch,
                           yes_arg: str) -> None:
    hooks_dir = make_hooks_dir(tmp_path)

    monkeypatch.setattr(Path, "cwd", lambda: tmp_path)

    console.run(["install", yes_arg])

    assert_hooks_created(hooks_dir)
示例#7
0
def it_aborts_installation_on_negative_prompt(
        tmp_path: Path, monkeypatch: MonkeyPatch) -> None:
    hooks_dir = make_hooks_dir(tmp_path)

    monkeypatch.setattr(builtins, "input", lambda _: "n")
    monkeypatch.setattr(Path, "cwd", lambda: tmp_path)

    console.run(["install"])

    assert_no_hooks(hooks_dir)
示例#8
0
def it_overwrites_own_hooks(tmp_path: Path) -> None:
    hooks_dir = make_hooks_dir(tmp_path)

    existing_hook = "# whippet 1.2.4\nCaptain"
    existing_hook_path = hooks_dir / "pre-commit"
    existing_hook_path.write_text(existing_hook, encoding="utf-8")

    whippet.install_hooks(tmp_path)
    assert existing_hook_path.read_text(encoding="utf-8") != existing_hook

    assert_hooks_created(hooks_dir)
示例#9
0
def it_does_not_remove_custom_hooks(tmp_path: Path,
                                    capsys: CaptureFixture) -> None:
    hooks_dir = make_hooks_dir(tmp_path)

    custom_hook = "Captain"
    custom_hook_path = hooks_dir / "pre-commit"
    custom_hook_path.write_text(custom_hook, encoding="utf-8")
    custom_hook_path.chmod(0o775)

    whippet.install_hooks(tmp_path)
    whippet.uninstall_hooks(tmp_path)

    captured = capsys.readouterr()
    assert "pre-commit hook not created by whippet - skipping" in captured.out
    assert custom_hook_path.read_text(encoding="utf-8") == custom_hook
示例#10
0
def it_does_not_overwrite_existing_hooks(tmp_path: Path,
                                         capsys: CaptureFixture) -> None:
    hooks_dir = make_hooks_dir(tmp_path)

    custom_hook = "Captain"
    custom_hook_path = hooks_dir / "pre-commit"
    custom_hook_path.write_text(custom_hook, encoding="utf-8")
    custom_hook_path.chmod(0o775)

    whippet.install_hooks(tmp_path)
    captured = capsys.readouterr()

    assert "pre-commit hook script already exists - skipping" in captured.out
    assert custom_hook_path.read_text(encoding="utf-8") == custom_hook

    assert_hooks_created(hooks_dir)
示例#11
0
def it_keeps_prompting_until_given_acceptable_answer(
        tmp_path: Path, monkeypatch: MonkeyPatch) -> None:
    hooks_dir = make_hooks_dir(tmp_path)
    attempts = 5

    def fake_input(_: str) -> str:
        nonlocal attempts
        attempts -= 1
        return "x" * attempts

    monkeypatch.setattr(builtins, "input", fake_input)
    monkeypatch.setattr(Path, "cwd", lambda: tmp_path)

    console.run(["install"])

    assert_hooks_created(hooks_dir)