""" Lightweight test runner. pytest is not installed in this build sandbox and there is no network access to install it (see README) -- this script discovers tests/test_*.py, runs every top-level test_* function, and reports real PASS/FAIL based on actual execution (spec section 6: real execution validation, not static syntax checking). If you have pytest available (e.g. after `pip install -r requirements.txt` somewhere with network access), just run `pytest tests/` instead -- these test files use plain assert and need nothing pytest-specific. """ import importlib.util import sys import traceback from pathlib import Path ROOT = Path(__file__).resolve().parent sys.path.insert(0, str(ROOT)) sys.path.insert(0, str(ROOT / "tests")) def run() -> bool: test_files = sorted((ROOT / "tests").glob("test_*.py")) total = 0 failed = 0 for f in test_files: spec = importlib.util.spec_from_file_location(f.stem, f) module = importlib.util.module_from_spec(spec) try: spec.loader.exec_module(module) except Exception: print(f"IMPORT ERROR {f.name}") traceback.print_exc() failed += 1 total += 1 continue for name in dir(module): if name.startswith("test_"): fn = getattr(module, name) if callable(fn): total += 1 try: fn() print(f"PASS {f.name}::{name}") except Exception: failed += 1 print(f"FAIL {f.name}::{name}") traceback.print_exc() print(f"\n{total - failed}/{total} passed") return failed == 0 if __name__ == "__main__": ok = run() sys.exit(0 if ok else 1)