File size: 646 Bytes
6d53c19
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19

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)