mirror of
https://github.com/kuhyx/utils.git
synced 2026-11-21 12:52:28 +01:00
Some checks are pending
file length / file-length (push) Waiting to run
kuhy_credit drift / drift (push) Waiting to run
md-naming / markdown naming convention (push) Waiting to run
palette drift / palette (push) Waiting to run
repo-contract / repo contract (push) Waiting to run
shared gate tests / gate unit tests (push) Waiting to run
A repo under ~/.cache (agent worktrees) had every file exempt, so the local gate passed what CI rejects. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
71 lines
2.2 KiB
Python
71 lines
2.2 KiB
Python
"""The shared exemption predicates in file_length.exemptions."""
|
|
|
|
from __future__ import annotations
|
|
|
|
from pathlib import Path
|
|
|
|
import pytest
|
|
|
|
from file_length.config import (
|
|
DATA_TXT_MAX_MEAN_LINE,
|
|
is_data_text,
|
|
is_generated,
|
|
is_session_artifact,
|
|
is_vendored,
|
|
)
|
|
from file_length.tests.conftest import write
|
|
|
|
|
|
def test_generated_by_extension_pattern(tmp_path: Path) -> None:
|
|
assert is_generated(tmp_path / "model.g.dart")
|
|
assert is_generated(tmp_path / "lib" / "generated" / "x.py")
|
|
|
|
|
|
def test_generated_by_header_marker(tmp_path: Path) -> None:
|
|
marked = write(tmp_path, "a.py", "# line\n# @generated by tool\nx = 1\n")
|
|
plain = write(tmp_path, "b.py", "x = 1\n")
|
|
assert is_generated(marked)
|
|
assert not is_generated(plain)
|
|
|
|
|
|
def test_generated_unreadable_is_false(tmp_path: Path) -> None:
|
|
assert not is_generated(tmp_path / "missing.py")
|
|
|
|
|
|
def test_data_text_only_for_short_line_txt(tmp_path: Path) -> None:
|
|
short = int(DATA_TXT_MAX_MEAN_LINE) - 1
|
|
assert is_data_text(tmp_path / "words.txt", lines=10, size=short * 10)
|
|
assert not is_data_text(tmp_path / "prose.txt", lines=10, size=80 * 10)
|
|
assert not is_data_text(tmp_path / "words.py", lines=10, size=10)
|
|
assert not is_data_text(tmp_path / "empty.txt", lines=0, size=0)
|
|
|
|
|
|
@pytest.mark.parametrize(
|
|
"path",
|
|
[
|
|
"/home/u/repo/node_modules/pkg/index.js",
|
|
"/home/u/repo/.claude/skills/x/SKILL.md",
|
|
"/home/u/mcp-servers/servers/foo/main.py",
|
|
"/home/u/aseprite-mcp/src/x.py",
|
|
],
|
|
)
|
|
def test_vendored_paths(path: str) -> None:
|
|
assert is_vendored(Path(path))
|
|
|
|
|
|
def test_own_code_is_not_vendored() -> None:
|
|
assert not is_vendored(Path("/home/u/src/todo/lib/main.dart"))
|
|
assert not is_vendored(Path("/home/u/mcp-servers/session-autopsy/x.py"))
|
|
|
|
|
|
def test_excluded_dirs_only_count_below_the_root() -> None:
|
|
root = Path("/home/u/.cache/wt")
|
|
assert not is_vendored(root / "src/a.py", root)
|
|
assert is_vendored(root / "build/a.py", root)
|
|
assert is_vendored(Path("/elsewhere/.cache/a.py"), root)
|
|
|
|
|
|
def test_session_artifact() -> None:
|
|
assert is_session_artifact(Path("/home/u/r/docs/superpowers/plans/a.md"))
|
|
assert not is_session_artifact(Path("/home/u/r/docs/README.md"))
|