1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
"""Shared fixtures for pgt TUI tests."""
from __future__ import annotations
from pathlib import Path
from unittest.mock import MagicMock
import pytest
from pygit2 import Repository, Signature, init_repository
from pyratatui import Rect
from pygittools.tui.types import PageContext
SIG = Signature("tester", "tester@example.com", 0)
@pytest.fixture(autouse=True)
def _mock_worktree_list(monkeypatch: pytest.MonkeyPatch) -> None:
monkeypatch.setattr(
"pygittools.tui.worktrees_list.list_worktrees",
lambda _repo: ([], None),
)
@pytest.fixture
def repo(tmp_path: Path) -> Repository:
repo_path = tmp_path / "repo"
repo_path.mkdir()
return init_repository(str(repo_path), bare=False)
@pytest.fixture
def page_ctx(repo: Repository) -> PageContext:
return PageContext(repo=repo, repo_path=Path(repo.path))
@pytest.fixture
def committed_repo(repo: Repository) -> Repository:
workdir = Path(repo.workdir)
(workdir / "tracked.txt").write_text("v1\n", encoding="utf-8")
repo.index.add("tracked.txt")
repo.index.write()
tree = repo.index.write_tree()
repo.create_commit("HEAD", SIG, SIG, "initial", tree, [])
return repo
@pytest.fixture
def frame() -> MagicMock:
return MagicMock()
@pytest.fixture
def area() -> Rect:
return Rect(0, 0, 80, 24)