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
"""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 pygittools.tui.types import PageContext
SIG = Signature("tester", "tester@example.com", 0)
@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(autouse=True)
def _mock_unicurses_io(monkeypatch: pytest.MonkeyPatch) -> None:
"""Avoid requiring a real terminal for status/tab helpers."""
mock = MagicMock()
for name in (
"has_colors",
"start_color",
"use_default_colors",
"init_pair",
):
monkeypatch.setattr(f"pygittools.tui.status_bar.{name}", mock, raising=False)
monkeypatch.setattr(f"pygittools.tui.tabs.{name}", mock, raising=False)
for name in ("move", "clrtoeol", "mvaddstr"):
monkeypatch.setattr(f"pygittools.tui.draw.{name}", mock, raising=False)
monkeypatch.setattr(f"pygittools.tui.status_bar.{name}", mock, raising=False)