#!/usr/bin/env python3 """Exercise every data connector and print what answered. Run this once after deploying — the connectors could not be tested from the machine this was built on, whose network reaches only GitHub and PyPI. python selftest.py Exit code is 0 when the two connectors the dashboard needs to start (protected areas, World Bank indicators) both succeeded, 1 otherwise. The optional sources are reported but never fail the run. """ from __future__ import annotations import sys import sources as src REQUIRED = {"Protected areas", "Human development indicators"} def main() -> int: print(f"{'source':<34} {'state':<12} {'rows':>8} {'s':>5} detail") print("-" * 108) results = src.run_selftest() for s in results: print(f"{s.name:<34} {s.badge:<12} {s.rows:>8,} {s.seconds:>5.1f} {s.detail[:52]}") if s.needs_key and not s.ok: print(f"{'':<34} {'':<12} {'':>8} {'':>5} → needs: {s.needs_key}") print() failed_required = [s for s in results if s.name in REQUIRED and not s.ok] optional_missing = [s for s in results if s.name not in REQUIRED and not s.ok] if optional_missing: print("Optional sources not loaded (the dashboard runs without them):") for s in optional_missing: print(f" · {s.name}: {s.detail}") print() if failed_required: print("BLOCKING — the dashboard cannot start:") for s in failed_required: print(f" · {s.name}: {s.detail}") return 1 print("All required sources loaded.") return 0 if __name__ == "__main__": sys.exit(main())