#!/usr/bin/env python3 """Run a build's acceptance checks and print the table the user sees. python3 acceptance_run.py # against the local build python3 acceptance_run.py --url # against the page actually served at the URL python3 acceptance_run.py --selftest Convention (the fixed part of S5-verify): next to the build lives a checks file, `acceptance.js` (run with node) or `acceptance.py` (run with python3). It receives one argument, the path of the HTML to check, and prints one JSON object per line: {"id": "5", "check": "自动加速 1000 次更新后速度", "expected": "7.000", "actual": "7.000", "ok": true} Any other stdout lines are ignored. This script renders the rows as check / expected / actual / match, adds a one-line verdict, and exits 1 on any mismatch, so go-live can refuse to proceed. With --url it first fetches the live HTML (and waits for it to carry the build's rules block, `') with open(os.path.join(d, "acceptance.py"), "w", encoding="utf-8") as f: f.write("import json,sys\nh=open(sys.argv[1],encoding='utf-8').read()\n" "print(json.dumps({'id':'1','check':'rules block present','expected':'yes','actual':'yes' if 'id=\"rules\"' in h else 'no','ok':'id=\"rules\"' in h}))\n" "print(json.dumps({'id':'2','check':'start speed','expected':'6','actual':'6','ok':True}))\n") rows, rc, _ = run_checks(os.path.join(d, "acceptance.py"), sys.executable, os.path.join(d, "index.html")) text, bad = render(rows, "selftest") ok = len(rows) == 2 and bad == 0 and "2/2" in text # a failing row must make the verdict non-zero rows2 = rows + [{"id": "3", "check": "x", "expected": "1", "actual": "2", "ok": False}] _, bad2 = render(rows2, "selftest") ok = ok and bad2 == 1 print("acceptance_run selftest: %s" % ("ok" if ok else "FAIL")) return 0 if ok else 1 if __name__ == "__main__": sys.exit(main())