This repository has been archived on 2026-05-22. You can view files and clone it, but cannot push or open issues or pull requests.
Files
NAIPC-2018/testing.py
2018-03-25 22:52:29 -04:00

26 lines
782 B
Python

import glob, sys, subprocess
_, src, test, t = sys.argv
ig = glob.glob(f'test/{test}/*.in')
og = glob.glob(f'test/{test}/*.ans')
print(test, len(ig), 'tests')
for ifn, ofn in zip(ig, og):
with open(ifn) as fi, open(ofn) as fx:
try:
o = subprocess.check_output(['python', src],
stdin=fi, stderr=subprocess.STDOUT,
timeout=float(t))
except subprocess.CalledProcessError as e:
o = e.output
except subprocess.TimeoutExpired:
o = b'TIMED OUT'
o = o.decode().strip().replace('\r\n', '\n')
x = fx.read().strip().replace('\r\n', '\n')
if o != x:
print(ifn, 'expected:', x, 'got:', o, '=' * 50, sep='\n')