| 1 | import tempfile |
| 2 | import unittest |
| 3 | from pathlib import Path |
| 4 | |
| 5 | import scripts.track_quality as track_quality |
| 6 | |
| 7 | |
| 8 | class TrackQualityTests(unittest.TestCase): |
| 9 | def test_build_quality_report_summarizes_scores(self) -> None: |
| 10 | tests_root = Path(__file__).resolve().parent |
| 11 | with tempfile.TemporaryDirectory(dir=tests_root) as tmpdir: |
| 12 | analyzed_dir = Path(tmpdir) / "analyzed" |
| 13 | analyzed_dir.mkdir() |
| 14 | (analyzed_dir / "2026-W19-summary.md").write_text( |
| 15 | "---\nweek: 2026-W19\nquality_score: 65\n---\n\nBody\n", |
| 16 | encoding="utf-8", |
| 17 | ) |
| 18 | (analyzed_dir / "2026-W20-summary.md").write_text( |
| 19 | "---\nweek: 2026-W20\nquality_score: 72\n---\n\nBody\n", |
| 20 | encoding="utf-8", |
| 21 | ) |
| 22 | (analyzed_dir / "2026-W21-summary.md").write_text( |
| 23 | "---\nweek: 2026-W21\nquality_score: 81\n---\n\nBody\n", |
| 24 | encoding="utf-8", |
| 25 | ) |
| 26 | |
| 27 | report = track_quality.build_quality_report(analyzed_dir) |
| 28 | |
| 29 | self.assertIn("Summaries analyzed: 3", report) |
| 30 | self.assertIn("Average quality score: 72.7", report) |
| 31 | self.assertIn("Trend: improving", report) |
| 32 | self.assertIn("| 2026-W21 | 81 |", report) |
| 33 | |
| 34 | def test_build_quality_report_handles_missing_entries(self) -> None: |
| 35 | tests_root = Path(__file__).resolve().parent |
| 36 | with tempfile.TemporaryDirectory(dir=tests_root) as tmpdir: |
| 37 | analyzed_dir = Path(tmpdir) / "analyzed" |
| 38 | analyzed_dir.mkdir() |
| 39 | |
| 40 | report = track_quality.build_quality_report(analyzed_dir) |
| 41 | |
| 42 | self.assertIn("No analyzed summaries", report) |
| 43 | self.assertIn("_No data available._", report) |
| 44 | |
| 45 | |
| 46 | if __name__ == "__main__": |
| 47 | unittest.main() |