]> dreyeck.freedombox.rocks Git - topic-maps.git/blob - scripts/check-report.py
554eb435fa7e14d952b61596a6cc231db316e405
[topic-maps.git] / scripts / check-report.py
1 #!/usr/bin/env python3
2 """Check the Lisp-generated JSON with an independent standard-library decoder."""
3 import json
4 import pathlib
5 import sys
6
7 root = pathlib.Path(__file__).resolve().parent.parent
8 report = json.loads(pathlib.Path(sys.argv[1]).read_text())
9 lock = json.loads((root / 'references/corpus-lock.json').read_text())
10 assert report['repository'] == lock['repository'] and report['commit'] == lock['commit']
11 assert report['qualification'] == lock['draftQualification']
12 assert report['counts'] == lock['ctmCounts']
13 slice7 = len(sys.argv) > 2 and sys.argv[2] == '--slice-7'
14 slice6 = slice7 or len(sys.argv) > 2 and sys.argv[2] == '--slice-6'
15 slice5 = slice6 or len(sys.argv) > 2 and sys.argv[2] == '--slice-5'
16 slice4 = slice5 or len(sys.argv) > 2 and sys.argv[2] == '--slice-4'
17 slice1 = slice4 or (len(sys.argv) > 2 and sys.argv[2] == '--slice-1')
18 assert report['implemented'] == dict(ctmParsing=slice1, tmdmDeserialization=slice1, cxtmCanonicalization=slice4)
19 assert report['countsMatchPin'] is True
20 assert report['correspondence'] == dict(ok=True, missingInputs=[], missingBaselines=[], unmatchedBaselines=[], duplicateIDs=[])
21 cases = report['cases']
22 assert len(cases) == report['counts']['valid'] + report['counts']['invalid']
23 passes = 42 if slice7 else 36 if slice6 else 29 if slice5 else 25 if slice4 else int(slice1)
24 assert report['statuses'] == {'pass': passes, 'fail': 0, 'unsupported': 0, 'not-run': len(cases)-passes}
25 assert [c['id'] for c in cases] == sorted(c['id'] for c in cases)
26 assert len({c['id'] for c in cases}) == len(cases)
27 tested = [c for c in cases if c['status'] == 'pass']
28 if slice4:
29 positives = [c for c in tested if c['category'] == 'valid']
30 assert len(positives) == (39 if slice7 else 33 if slice6 else 28 if slice5 else 24) and all(c['actualOutcome'] == 'cxtm-match' for c in positives)
31 untested = [c for c in cases if c not in tested]
32 assert all(c['status'] == 'not-run' and c['actualOutcome'] is None and c['diagnostics'] == [] for c in untested)
33 if slice1:
34 negative = next(c for c in cases if c['id'] == 'ctm/invalid/prefix-undefined.ctm')
35 assert negative['status'] == 'pass' and negative['actualOutcome'] == 'ctm-rejection'
36 assert len(negative['diagnostics']) == 1 and 'UNDEFINED-PREFIX' in negative['diagnostics'][0]
37 assert all(c['documentIRI'] == 'https://ctm-tests.example.invalid/' + lock['commit'] + '/' + c['id'] for c in cases)
38 assert sum(c['category'] == 'valid' for c in cases) == report['counts']['valid']
39 assert sum(c['category'] == 'invalid' for c in cases) == report['counts']['invalid']
40 assert all(c['expectedOutcome'] == 'ctm-rejection' and c['expectedCXTM'] is None for c in cases if c['category'] == 'invalid')
41 assert all(c['expectedOutcome'] == 'cxtm-equal' and c['expectedCXTM'].endswith('.ctm.cxtm') for c in cases if c['category'] == 'valid')
42 assert all((root/'vendor/cxtm'/c['sourcePathname']).is_file() for c in cases)
43 assert all((root/'vendor/cxtm'/c['expectedCXTM']).is_file() for c in cases if c['expectedCXTM'])
44 assert len(report['auxiliaryResources']) == report['counts']['auxiliary']
45 assert len(report['baselines']) == report['counts']['baselines']
46 assert len(report['infrastructureChecks']) == len(set(report['infrastructureChecks'])) > 0
47 print('REPORT-JSON-PASS: deterministic schema, draft qualification, case contracts and only warranted imported status changes')
48
49 if slice6:
50 for name, reason in [('prefix-collision', 'PREFIX-COLLISION'), ('prefix-undefined2', 'UNDEFINED-PREFIX')]:
51 c = next(c for c in cases if c['id'] == f'ctm/invalid/{name}.ctm')
52 assert c['status'] == 'pass' and c['actualOutcome'] == 'ctm-rejection'
53 assert len(c['diagnostics']) == 1 and reason in c['diagnostics'][0]