Option C Tools
Loading...
Searching...
No Matches
test_lint_health.py
Go to the documentation of this file.
1#!/usr/bin/env python3
2# -*- coding: utf-8 -*-
3# tests/tests_health/test_lint_health.py
4
5"""
6Tests for lint health check.
7
8Purpose
9-------
10Verify that check_lint_health correctly aggregates linter results.
11
12Responsibilities
13----------------
14- Test fully compliant projects.
15- Test partially compliant projects.
16- Test empty projects.
17- Test verbose mode file details.
18
19Diagnostics
20-----------
21Domain: TESTS.HEALTH
22Levels:
23 L2 — test lifecycle
24 L3 — lint aggregation verification
25 L4 — per-check count validation
26
27Contracts
28---------
29- Compliance percentage is calculated correctly.
30- Per-check pass counts match actual results.
31- Verbose mode includes per-file breakdown.
32"""
33
34import pytest
35from pathlib import Path
36
37from oct.health.oct_health import check_lint_health
38from oct.linter.oct_lint import LinterContext
39from tests.tests_health.conftest import make_compliant_file, NON_COMPLIANT_FILE
40
41
42def test_lint_health_all_compliant(temp_project_root: Path, linter_ctx: LinterContext):
43 """Test 100% compliance when all files pass."""
44 (temp_project_root / "good.py").write_text(make_compliant_file("good.py"), encoding="utf-8")
45
46 result = check_lint_health(temp_project_root, linter_ctx)
47
48 assert result["total_files"] == 1
49 assert result["fully_compliant"] == 1
50 assert result["compliance_pct"] == 100.0
51
52
53def test_lint_health_partial_compliance(temp_project_root: Path, linter_ctx: LinterContext):
54 """Test mixed compliance results."""
55 (temp_project_root / "good.py").write_text(make_compliant_file("good.py"), encoding="utf-8")
56 # Pad non-compliant to > 20 lines so it's not trivial
57 padded = NON_COMPLIANT_FILE + "\n".join(["# pad"] * 20)
58 (temp_project_root / "bad.py").write_text(padded, encoding="utf-8")
59
60 result = check_lint_health(temp_project_root, linter_ctx)
61
62 assert result["total_files"] == 2
63 assert result["fully_compliant"] == 1
64 assert result["compliance_pct"] == 50.0
65
66
67def test_lint_health_empty_project(temp_project_root: Path, linter_ctx: LinterContext):
68 """Test health check on project with no Python files."""
69 result = check_lint_health(temp_project_root, linter_ctx)
70
71 assert result["total_files"] == 0
72 assert result["fully_compliant"] == 0
73 assert result["compliance_pct"] == 0.0
74
75
76def test_lint_health_check_categories(temp_project_root: Path, linter_ctx: LinterContext):
77 """Test that all check categories are reported."""
78 (temp_project_root / "good.py").write_text(make_compliant_file("good.py"), encoding="utf-8")
79
80 result = check_lint_health(temp_project_root, linter_ctx)
81
82 expected_checks = ["header", "docstring", "diagnostics_profile", "dbg_usage", "dbg_import", "func_pattern"]
83 for check_name in expected_checks:
84 assert check_name in result["checks"]
85 assert "pass" in result["checks"][check_name]
86 assert "total" in result["checks"][check_name]
87 assert "pct" in result["checks"][check_name]
88
89
90def test_lint_health_verbose_includes_files(temp_project_root: Path, linter_ctx: LinterContext):
91 """Test that verbose mode includes per-file details."""
92 (temp_project_root / "good.py").write_text(make_compliant_file("good.py"), encoding="utf-8")
93
94 result = check_lint_health(temp_project_root, linter_ctx, verbose=True)
95
96 assert "files" in result
97 assert len(result["files"]) == 1
98 assert result["files"][0]["compliant"] is True
99
100
101def test_lint_health_verbose_shows_failures(temp_project_root: Path, linter_ctx: LinterContext):
102 """Test that verbose mode shows failed checks per file."""
103 padded = NON_COMPLIANT_FILE + "\n".join(["# pad"] * 20)
104 (temp_project_root / "bad.py").write_text(padded, encoding="utf-8")
105
106 result = check_lint_health(temp_project_root, linter_ctx, verbose=True)
107
108 assert "files" in result
109 assert len(result["files"]) == 1
110 assert result["files"][0]["compliant"] is False
test_lint_health_verbose_includes_files(Path temp_project_root, LinterContext linter_ctx)
test_lint_health_empty_project(Path temp_project_root, LinterContext linter_ctx)
test_lint_health_partial_compliance(Path temp_project_root, LinterContext linter_ctx)
test_lint_health_all_compliant(Path temp_project_root, LinterContext linter_ctx)
test_lint_health_verbose_shows_failures(Path temp_project_root, LinterContext linter_ctx)
test_lint_health_check_categories(Path temp_project_root, LinterContext linter_ctx)