Project: pygitweb

47a5dca """Shared fixtures for pgt TUI tests."""
from __future__ import annotations
e37c74c import gc
from collections.abc import Iterator
47a5dca from pathlib import Path
from unittest.mock import MagicMock
import pytest
from pygit2 import Repository, Signature, init_repository
8614508 from pyratatui import Rect
47a5dca
from pygittools.tui.types import PageContext
SIG = Signature("tester", "tester@example.com", 0)
ca718f6 @pytest.fixture(autouse=True)
e37c74c def _drop_unsendable_prompt_state() -> Iterator[None]:
73c9c30 # TextState is unsendable. Drop it on this thread once the test and its
# fixtures have released the page, before another thread's GC can.
yield
gc.collect()
e37c74c
@pytest.fixture(autouse=True)
ca718f6 def _mock_worktree_list(monkeypatch: pytest.MonkeyPatch) -> None:
73c9c30 monkeypatch.setattr(
"pygittools.tui.worktrees_list.list_worktrees",
lambda _repo: ([], None),
)
ca718f6
47a5dca @pytest.fixture
def repo(tmp_path: Path) -> Repository:
73c9c30 repo_path = tmp_path / "repo"
repo_path.mkdir()
return init_repository(str(repo_path), bare=False)
47a5dca
@pytest.fixture
def page_ctx(repo: Repository) -> PageContext:
73c9c30 return PageContext(repo=repo, repo_path=Path(repo.path))
47a5dca
@pytest.fixture
def committed_repo(repo: Repository) -> Repository:
73c9c30 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
47a5dca
8614508 @pytest.fixture
def frame() -> MagicMock:
73c9c30 return MagicMock()
8614508
@pytest.fixture
def area() -> Rect:
73c9c30 return Rect(0, 0, 80, 24)