mirror of
https://github.com/kuhyx/testsAndMisc.git
synced 2026-11-10 23:07:03 +01:00
Some checks are pending
dependency freshness / dependencies on newest stable (push) Waiting to run
md-naming / markdown naming convention (push) Waiting to run
Pre-commit checks / pre-commit (${{ matrix.group }}) (mypy, mypy) (push) Waiting to run
Pre-commit checks / pre-commit (${{ matrix.group }}) (pylint, pylint) (push) Waiting to run
Pre-commit checks / pre-commit (${{ matrix.group }}) (rest, ) (push) Waiting to run
Pre-commit checks / pre-commit (${{ matrix.group }}) (shellcheck, shellcheck) (push) Waiting to run
Python tests / test (push) Waiting to run
repo-contract / repo contract (push) Waiting to run
Shell tests / shell-tests (push) Waiting to run
Shell tests / lib-tests (push) Waiting to run
Shell tests / arch-tests (push) Waiting to run
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01JThjboXTeZ3yJPBzxMx5wS
55 lines
1.9 KiB
Python
55 lines
1.9 KiB
Python
"""Git-backed edge cases: caching, binary files, commits outside HEAD."""
|
|
|
|
from __future__ import annotations
|
|
|
|
from typing import TYPE_CHECKING
|
|
|
|
from python_pkg.token_dashboard import commits, survival
|
|
from python_pkg.token_dashboard.tests.test_efficiency import DAY, MONDAY, _commit, _git
|
|
|
|
if TYPE_CHECKING:
|
|
from pathlib import Path
|
|
|
|
|
|
def _repo(tmp_path: Path) -> Path:
|
|
repo = tmp_path / "r"
|
|
repo.mkdir()
|
|
_git(repo, "init", "-q", when=MONDAY)
|
|
return repo
|
|
|
|
|
|
def test_toplevel_is_resolved_once_per_hint(tmp_path: Path) -> None:
|
|
repo = _repo(tmp_path)
|
|
_commit(repo, "a", "1", MONDAY)
|
|
cache: dict[str, str | None] = {}
|
|
first = commits._toplevel(str(repo), cache)
|
|
assert first == str(repo.resolve())
|
|
cache[str(repo)] = "cached"
|
|
assert commits._toplevel(str(repo), cache) == "cached"
|
|
assert commits._toplevel("", cache) is None
|
|
|
|
|
|
def test_binary_and_empty_files_do_not_count_as_added_lines(tmp_path: Path) -> None:
|
|
repo = _repo(tmp_path)
|
|
old = MONDAY - 40 * DAY
|
|
(repo / "blob.bin").write_bytes(b"\x00\x01\x02")
|
|
(repo / "empty.txt").write_text("", encoding="utf-8")
|
|
(repo / "t.txt").write_text("1\n2\n", encoding="utf-8")
|
|
_git(repo, "add", ".", when=old)
|
|
_git(repo, "commit", "-qm", "mixed", when=old)
|
|
sha = _git(repo, "rev-parse", "HEAD", when=old)
|
|
found = survival.evaluate(str(repo), sha, MONDAY)
|
|
assert (found.verdict, found.added, found.kept) == ("survived", 2, 2)
|
|
|
|
|
|
def test_a_commit_that_is_not_an_ancestor_of_head_is_unknown(tmp_path: Path) -> None:
|
|
repo = _repo(tmp_path)
|
|
old = MONDAY - 40 * DAY
|
|
_commit(repo, "a", "1", old)
|
|
trunk = _git(repo, "branch", "--show-current", when=old)
|
|
_git(repo, "checkout", "-qb", "side", when=old)
|
|
side = _commit(repo, "b", "2", old + 1)
|
|
_git(repo, "checkout", "-q", trunk, when=old)
|
|
found = survival.evaluate(str(repo), side, MONDAY)
|
|
assert (found.verdict, found.sha) == ("unknown", side)
|