check.py 945 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. import json
  2. import os
  3. import subprocess
  4. def parse_output(text):
  5. return json.loads(text)
  6. def run_stats():
  7. out = subprocess.run(
  8. ["python3", "/app/stats.py", "/app/orders.csv"],
  9. capture_output=True,
  10. text=True,
  11. )
  12. return parse_output(out.stdout)
  13. def check_parser():
  14. return parse_output('{"alice": 70.0}') == {"alice": 70.0}
  15. def check_data_exists():
  16. return os.path.exists("/app/orders.csv")
  17. def check_output_is_json():
  18. return isinstance(run_stats(), dict)
  19. def check_alice_total():
  20. return run_stats().get("alice") == 70.0
  21. checks = [check_parser, check_data_exists, check_output_is_json, check_alice_total]
  22. passed = 0
  23. for check in checks:
  24. try:
  25. ok = check()
  26. except Exception:
  27. ok = False
  28. print(f"{check.__name__}: {'PASS' if ok else 'FAIL'}")
  29. passed += bool(ok)
  30. with open("/logs/verifier/reward.txt", "w") as f:
  31. f.write(str(passed / len(checks)))