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