| data = json.load(sys.stdin) |
| with open(testfile) as testfh: |
| for line in iter(testfh.readline, ""): |
| line = line.rstrip("\r\n") |
| prefix_pos = line.index(prefix) |
| check_expr = line[prefix_pos + len(prefix):] |
| result = eval(check_expr, {"data":data}) |
| exception = traceback.format_exc().splitlines()[-1] |
| if exception is not None: |
| "{file}:{line:d}: check threw exception: {expr}\n" |
| "{file}:{line:d}: exception was: {exception}\n".format( |
| file=testfile, line=lineno, |
| expr=check_expr, exception=exception)) |
| "{file}:{line:d}: check returned False: {expr}\n".format( |
| file=testfile, line=lineno, expr=check_expr)) |
| sys.exit("{} checks failed".format(fails)) |
| sys.stdout.write("{} checks passed\n".format(passes)) |