"""Run the verification checks supplied with the manuscript.""" from pathlib import Path import argparse from datetime import datetime, timezone import json import platform import subprocess import sys import time import numpy as np ROOT = Path(__file__).resolve().parent CHECKS = { 'e7_words': ROOT / 'e7' / 'verify_words.py', 'e7_root_string': ROOT / 'e7' / 'verify_root_string.py', 'e7_jacobian': ROOT / 'e7' / 'verify_positive_jacobian.py', } def main(): parser = argparse.ArgumentParser(description=__doc__) parser.add_argument('checks', nargs='*', metavar='CHECK', help='Available checks: ' + ', '.join(CHECKS) + '. The default is all.') args = parser.parse_args() names = args.checks or list(CHECKS) unknown = [name for name in names if name not in CHECKS] if unknown: parser.error('unknown check: ' + ', '.join(unknown)) output = ROOT / 'results' output.mkdir(exist_ok=True) report = { 'started_utc': datetime.now(timezone.utc).isoformat(), 'python': platform.python_version(), 'numpy': np.__version__, 'checks': [], } for name in names: command = [sys.executable, '-B', str(CHECKS[name])] print('Running ' + name, flush=True) start = time.monotonic() result = subprocess.run(command, cwd=ROOT, text=True, stdout=subprocess.PIPE, stderr=subprocess.STDOUT) log = output / (name + '.log') log.write_text(result.stdout) row = {'name': name, 'exit_code': result.returncode, 'seconds': time.monotonic() - start, 'log': str(log.relative_to(ROOT))} report['checks'].append(row) print(('PASS' if result.returncode == 0 else 'FAIL') + ' ' + name + ' (' + f"{row['seconds']:.2f}" + ' s)', flush=True) if result.returncode: print(result.stdout) break report['status'] = ('PASS' if len(report['checks']) == len(names) and all(r['exit_code'] == 0 for r in report['checks']) else 'FAIL') (output / 'run_report.json').write_text(json.dumps(report, indent=2) + '\n') return 0 if report['status'] == 'PASS' else 1 if __name__ == '__main__': raise SystemExit(main())