utils/file_length/tests/conftest.py
Krzysztof kuhy Rudnicki 879265b966
Some checks are pending
dependency freshness / dependencies on newest stable (push) Waiting to run
file length / file-length (push) Waiting to run
md-naming / markdown naming convention (push) Waiting to run
palette drift / palette (push) Waiting to run
shared gate tests / gate unit tests (push) Waiting to run
file_length: repo-local .file-length-exempt list, fail-closed, package tested to 100%
A fork of a third-party project can carry data that is code only by
extension (TachiyomiSY's 6000-line exh/eh/tags/*.kt string tables). The
reason belongs in that repo next to the data, so the gate now reads a
.file-length-exempt of '<glob>  # <reason>' lines from its cwd. A glob
without a reason is a suppression and exits 2 instead of passing.

The package had no tests at all; it now has a suite at 100% line+branch,
wired into shared-gates-tests.yml with --cov-fail-under=100.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Yc4TiPjhbQLfH35QBPfrbP
2026-09-12 18:53:19 +02:00

41 lines
1.1 KiB
Python

"""Shared fixtures for the file_length tests."""
from __future__ import annotations
import subprocess
import sys
from pathlib import Path
import pytest
sys.path.insert(0, str(Path(__file__).resolve().parents[2]))
@pytest.fixture(autouse=True)
def _fresh_exempt_cache() -> None:
"""`load` is memoised per root; tests rewrite the file, so drop it."""
from file_length import repo_exempt
repo_exempt.load.cache_clear()
@pytest.fixture
def repo(tmp_path: Path, monkeypatch: pytest.MonkeyPatch) -> Path:
"""A throwaway git repo that is also the cwd, as the gate expects."""
subprocess.run(["git", "init", "-q", str(tmp_path)], check=True)
monkeypatch.chdir(tmp_path)
return tmp_path
def write(root: Path, relative: str, body: str) -> Path:
"""Create `relative` under `root`, parents included, and return it."""
path = root / relative
path.parent.mkdir(parents=True, exist_ok=True)
path.write_text(body, encoding="utf-8")
return path
def lines(count: int) -> str:
"""`count` numbered lines, newline-terminated."""
return "".join(f"line {i}\n" for i in range(count))