"""Tests for the written audit checklist and the monthly season check. Run from the repository root: python3 -m unittest discover tools/tests """ import os import re import sys import unittest sys.dont_write_bytecode = True sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) import estimate_season as E # noqa: E402 ROOT = E.ROOT def read(*parts): with open(os.path.join(ROOT, *parts), encoding="utf-8") as f: return f.read() def section(text, heading): start = text.index(f"## {heading}") nxt = text.find("\n## ", start + 1) return text[start:nxt if nxt != -1 else len(text)] class AuditChecklistTest(unittest.TestCase): def test_the_audit_checklist_has_a_seasons_section_naming_both_steps(self): doc = read("docs", "audit.md") seasons = section(doc, "Seasons") self.assertIn("estimate_season.py check", seasons) self.assertIn("estimate_season.py estimates", seasons) self.assertIn("docs/season-research.md", seasons) self.assertIn("search afresh for a page that states the season", seasons.lower().replace("\n", " ")) self.assertIn("downloads nothing", seasons) self.assertIn("fixed published dataset", seasons) self.assertIn("1. ", seasons) self.assertIn("2. ", seasons) def test_the_commands_it_names_exist(self): import contextlib import io import season_judge for module, subs in ((E, ("check", "estimates")), (season_judge, ("inputs", "packets", "score", "proposals"))): for sub in subs: out = io.StringIO() with contextlib.redirect_stdout(out), self.assertRaises(SystemExit) as stop: module.main([sub, "--help"]) self.assertEqual(stop.exception.code, 0, sub) self.assertIn(f" {sub}", out.getvalue()) def test_every_command_in_the_audit_runs_as_written(self): """Each `python3 tools/