52 lines
1.6 KiB
Python
52 lines
1.6 KiB
Python
"""Focused hygiene-helper tests for titan-iac quality modules."""
|
|
|
|
from __future__ import annotations
|
|
|
|
from pathlib import Path
|
|
|
|
from testing.quality_hygiene import count_files_over_line_limit, run_check
|
|
|
|
|
|
def test_count_files_over_line_limit_counts_only_long_matches(tmp_path: Path) -> None:
|
|
"""Only files beyond the configured limit should contribute to the LOC total."""
|
|
|
|
tests_dir = tmp_path / "tests"
|
|
tests_dir.mkdir()
|
|
(tests_dir / "test_short.py").write_text("line\n", encoding="utf-8")
|
|
(tests_dir / "test_long.py").write_text("line\n" * 4, encoding="utf-8")
|
|
(tests_dir / "notes.txt").write_text("line\n" * 8, encoding="utf-8")
|
|
|
|
contract = {
|
|
"hygiene": {
|
|
"max_lines": 3,
|
|
"line_limit_globs": ["tests/*.py"],
|
|
}
|
|
}
|
|
|
|
assert count_files_over_line_limit(contract, tmp_path) == 1
|
|
|
|
|
|
def test_run_check_exempts_conftest_from_naming_rules(tmp_path: Path) -> None:
|
|
"""Shared conftest.py fixtures never violate test naming rules."""
|
|
|
|
tests_dir = tmp_path / "tests"
|
|
tests_dir.mkdir()
|
|
(tests_dir / "conftest.py").write_text("fixtures = True\n", encoding="utf-8")
|
|
(tests_dir / "test_named.py").write_text("checked = True\n", encoding="utf-8")
|
|
|
|
contract = {
|
|
"hygiene": {
|
|
"max_lines": 3,
|
|
"line_limit_globs": [],
|
|
"naming_rules": [
|
|
{
|
|
"glob": "tests/*.py",
|
|
"pattern": "^test_[a-z0-9_]+\\.py$",
|
|
"description": "pytest files use test_*.py names",
|
|
}
|
|
],
|
|
}
|
|
}
|
|
|
|
assert run_check(contract, tmp_path) == []
|