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
ICPC-2017/icpc_test.py
2018-01-29 16:14:37 -05:00

32 lines
1018 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('utf-8').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')
# run this with arguments:
# <script>.py <testdir> <timelimit>
# <testdir> should be populated with <name>.in <name>.out
# file pairs, as can be downloaded from kattis
# <testdir> should be in the test/ directory, eg test/haiku