]> dreyeck.freedombox.rocks Git - topic-maps.git/blob - scripts/check-report.py
Implement XTM 2.0 identity and instanceOf reader with offline evidence
[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 slice19c = len(sys.argv) > 2 and sys.argv[2] == '--slice-19c'
14 slice19b = slice19c or len(sys.argv) > 2 and sys.argv[2] == '--slice-19b'
15 slice18 = slice19b or len(sys.argv) > 2 and sys.argv[2] == '--slice-18'
16 slice17b = slice18 or len(sys.argv) > 2 and sys.argv[2] == '--slice-17b'
17 slice17a = slice17b or len(sys.argv) > 2 and sys.argv[2] == '--slice-17a'
18 slice16b = slice17a or len(sys.argv) > 2 and sys.argv[2] == '--slice-16b'
19 slice15 = slice16b or len(sys.argv) > 2 and sys.argv[2] == '--slice-15'
20 slice14 = slice15 or len(sys.argv) > 2 and sys.argv[2] == '--slice-14'
21 slice13 = slice14 or len(sys.argv) > 2 and sys.argv[2] == '--slice-13'
22 slice12a = slice13 or len(sys.argv) > 2 and sys.argv[2] == '--slice-12a'
23 slice11 = slice12a or len(sys.argv) > 2 and sys.argv[2] == '--slice-11'
24 slice10 = slice11 or len(sys.argv) > 2 and sys.argv[2] == '--slice-10'
25 slice9 = slice10 or len(sys.argv) > 2 and sys.argv[2] == '--slice-9'
26 slice8 = slice9 or len(sys.argv) > 2 and sys.argv[2] == '--slice-8'
27 slice7 = slice8 or len(sys.argv) > 2 and sys.argv[2] == '--slice-7'
28 slice6 = slice7 or len(sys.argv) > 2 and sys.argv[2] == '--slice-6'
29 slice5 = slice6 or len(sys.argv) > 2 and sys.argv[2] == '--slice-5'
30 slice4 = slice5 or len(sys.argv) > 2 and sys.argv[2] == '--slice-4'
31 slice1 = slice4 or (len(sys.argv) > 2 and sys.argv[2] == '--slice-1')
32 assert report['implemented'] == dict(ctmParsing=slice1, tmdmDeserialization=slice1, cxtmCanonicalization=slice4)
33 assert report['countsMatchPin'] is True
34 assert report['correspondence'] == dict(ok=True, missingInputs=[], missingBaselines=[], unmatchedBaselines=[], duplicateIDs=[])
35 cases = report['cases']
36 assert len(cases) == report['counts']['valid'] + report['counts']['invalid']
37 passes = 204 if slice19c else 194 if slice19b else 187 if slice18 else 120 if slice17b else 107 if slice17a else 106 if slice16b else 93 if slice15 else 71 if slice14 else 67 if slice13 else 64 if slice12a else 62 if slice10 else 59 if slice9 else 49 if slice8 else 42 if slice7 else 36 if slice6 else 29 if slice5 else 25 if slice4 else int(slice1)
38 assert report['statuses'] == {'pass': passes, 'fail': (4 if slice19c else 2 if slice11 else int(slice10)), 'unsupported': 0, 'not-run': len(cases)-passes-(4 if slice19c else 2 if slice11 else int(slice10))}
39 assert [c['id'] for c in cases] == sorted(c['id'] for c in cases)
40 assert len({c['id'] for c in cases}) == len(cases)
41 tested = [c for c in cases if c['status'] == 'pass']
42 if slice4:
43 positives = [c for c in tested if c['category'] == 'valid']
44 assert len(positives) == (176 if slice19c else 169 if slice19b else 165 if slice18 else 108 if slice17b else 95 if slice17a else 94 if slice16b else 83 if slice15 else 62 if slice14 else 59 if slice13 else 56 if slice12a else 54 if slice10 else 51 if slice9 else 46 if slice8 else 39 if slice7 else 33 if slice6 else 28 if slice5 else 24) and all(c['actualOutcome'] == 'cxtm-match' for c in positives)
45 failed = [c for c in cases if c['status'] == 'fail']
46 if slice10:
47 expected_failed = {'ctm/in/occurrence-datetime2.ctm'}
48 if slice11:
49 expected_failed.add('ctm/in/occurrence-datetime-timezone2.ctm')
50 if slice19c:
51 expected_failed.update({'ctm/in/include-template.ctm', 'ctm/in/include-wildcard2.ctm'})
52 assert {c['id'] for c in failed} == expected_failed
53 assert all(c['actualOutcome'] == 'cxtm-mismatch' and 'normative discrepancy' in c['diagnostics'][0] for c in failed)
54 offset = next(c for c in cases if c['id'] == 'ctm/in/occurrence-datetime-timezone2.ctm')
55 assert offset['status'] == ('fail' if slice11 else 'not-run')
56 else:
57 assert not failed
58 untested = [c for c in cases if c['status'] == 'not-run']
59 assert all(c['status'] == 'not-run' and c['actualOutcome'] is None and c['diagnostics'] == [] for c in untested)
60 if slice1:
61 negative = next(c for c in cases if c['id'] == 'ctm/invalid/prefix-undefined.ctm')
62 assert negative['status'] == 'pass' and negative['actualOutcome'] == 'ctm-rejection'
63 assert len(negative['diagnostics']) == 1 and 'UNDEFINED-PREFIX' in negative['diagnostics'][0]
64 assert all(c['documentIRI'] == 'https://ctm-tests.example.invalid/' + lock['commit'] + '/' + c['id'] for c in cases)
65 assert sum(c['category'] == 'valid' for c in cases) == report['counts']['valid']
66 assert sum(c['category'] == 'invalid' for c in cases) == report['counts']['invalid']
67 assert all(c['expectedOutcome'] == 'ctm-rejection' and c['expectedCXTM'] is None for c in cases if c['category'] == 'invalid')
68 assert all(c['expectedOutcome'] == 'cxtm-equal' and c['expectedCXTM'].endswith('.ctm.cxtm') for c in cases if c['category'] == 'valid')
69 assert all((root/'vendor/cxtm'/c['sourcePathname']).is_file() for c in cases)
70 assert all((root/'vendor/cxtm'/c['expectedCXTM']).is_file() for c in cases if c['expectedCXTM'])
71 assert len(report['auxiliaryResources']) == report['counts']['auxiliary']
72 assert len(report['baselines']) == report['counts']['baselines']
73 assert len(report['infrastructureChecks']) == len(set(report['infrastructureChecks'])) > 0
74 print('REPORT-JSON-PASS: deterministic schema, draft qualification, case contracts and only warranted imported status changes')
75
76 if slice6:
77 for name, reason in [('prefix-collision', 'PREFIX-COLLISION'), ('prefix-undefined2', 'UNDEFINED-PREFIX')]:
78 c = next(c for c in cases if c['id'] == f'ctm/invalid/{name}.ctm')
79 assert c['status'] == 'pass' and c['actualOutcome'] == 'ctm-rejection'
80 assert len(c['diagnostics']) == 1 and reason in c['diagnostics'][0]
81
82 if slice9:
83 for name, reason in [('date-invalid-day', 'INVALID-DATE-DAY'), ('date-invalid-month', 'INVALID-DATE-MONTH'),
84 ('date-invalid-year', 'INVALID-DATE-YEAR'), ('date-invalid-year2', 'INVALID-DATE-YEAR'), ('date-invalid-year3', 'INVALID-DATE-YEAR')]:
85 c = next(c for c in cases if c['id'] == f'ctm/invalid/{name}.ctm')
86 assert c['status'] == 'pass' and c['actualOutcome'] == 'ctm-rejection'
87 assert len(c['diagnostics']) == 1 and reason in c['diagnostics'][0]
88
89 if slice14:
90 c = next(c for c in cases if c['id'] == 'ctm/invalid/variant-no-scope.ctm')
91 assert c['status'] == 'pass' and c['actualOutcome'] == 'ctm-rejection'
92 assert len(c['diagnostics']) == 1 and 'EXPECTED-VARIANT-SCOPE' in c['diagnostics'][0]
93
94 if slice15:
95 c = next(c for c in cases if c['id'] == 'ctm/invalid/embedded-topic-global-scope.ctm')
96 assert c['status'] == 'pass' and c['actualOutcome'] == 'ctm-rejection'
97 assert len(c['diagnostics']) == 1 and 'EMBEDDED-TOPIC-AT-TOP-LEVEL' in c['diagnostics'][0]
98 c = next(c for c in cases if c['id'] == 'ctm/invalid/embedded-topic-template.ctm')
99 assert (c['status'] == 'pass' and c['actualOutcome'] == 'ctm-rejection') if slice18 else (c['status'] == 'not-run' and c['actualOutcome'] is None)