| import json | |
| from difflib import unified_diff | |
| def canonical_schedule_json(schedule): | |
| return json.dumps([{"end_step":e, "text":t} for e,t in schedule], ensure_ascii=False, indent=2) | |
| def compare_canonical(expected_json: str, actual_json: str): | |
| # сравнение строк JSON построчно | |
| exp = expected_json.strip().splitlines() | |
| act = actual_json.strip().splitlines() | |
| ok = (exp == act) | |
| diff = "\n".join(unified_diff(exp, act, "expected","actual", lineterm="")) | |
| return ok, diff | |
| def save_case(path, case): | |
| with open(path,"w",encoding="utf-8") as f: | |
| json.dump(case,f,ensure_ascii=False,indent=2) | |