File size: 1,040 Bytes
0eeab15
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
#!/usr/bin/env python3
import json, sys
from pathlib import Path

def check(path):
    rows=[json.loads(line) for line in Path(path).open(encoding="utf-8") if line.strip()]
    ids=set()
    for n,row in enumerate(rows,1):
        assert row["id"] not in ids, f"duplicate id at line {n}"
        ids.add(row["id"])
        assert set(row["options"]) == {"A","B","C","D"}, f"bad options at line {n}"
        assert len(set(row["options"].values())) == 4, f"duplicate options at line {n}"
        assert row["correct_answer"] in "ABCD", f"bad answer label at line {n}"
        assert row["options"][row["correct_answer"]] == row["correct_answer_value"], f"answer mismatch at line {n}"
        assert set(row["option_explanations"]) == {"A","B","C","D"}, f"missing option explanation at line {n}"
        assert row["question"].strip() and row["solution"].strip(), f"empty question/solution at line {n}"
    print(f"{path}: {len(rows)} records passed structural checks")

if __name__ == "__main__":
    for p in sys.argv[1:]:
        check(p)