atlas-iac/testing/tests/test_quality_hygiene_helpers.py
jenkins 64272f52d2 hermes: lift remaining tracked modules to the branch floor
Exercise the mailu sync retry, attribute, and skip branches, the
listener non-object JSON path, and the hygiene conftest skip; drop the
unreachable inverted-range clamp in the semgrep report (the line helper
already floors the end line) and pin that behavior with a test. Exclude
the mailu __main__ guards from measurement.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
2026-08-17 15:10:17 -03:00

53 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_run_check_skips_conftest_files_in_naming_rules(tmp_path: Path) -> None:
"""A conftest.py is pytest plumbing, never a naming-rule violation."""
tests_dir = tmp_path / "tests"
tests_dir.mkdir()
(tests_dir / "conftest.py").write_text("fixtures = True\n", encoding="utf-8")
(tests_dir / "helper.py").write_text("value = 1\n", encoding="utf-8")
contract = {
"hygiene": {
"naming_rules": [
{
"glob": "tests/*.py",
"pattern": "^test_[a-z0-9_]+\\.py$",
"description": "Pytest files use test_*.py names.",
}
]
}
}
issues = run_check(contract, tmp_path)
assert len(issues) == 1
assert "helper.py" in issues[0]
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