"""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_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"))