]> dreyeck.freedombox.rocks Git - topic-maps.git/blob - scripts/check-occurrences.py
Implement XTM occurrence core and register eleven originals (Slice 22G)
[topic-maps.git] / scripts / check-occurrences.py
1 #!/usr/bin/env python3
2 """Independent semantic expectations, separate from raw CXTM equality checks."""
3 import json
4 import pathlib
5 import sys
6 report=json.loads(pathlib.Path(sys.argv[1]).read_text())
7 root=pathlib.Path(__file__).resolve().parent.parent
8 assert report['kind']=='occurrence-semantic-and-cxtm-evidence' and report['failed']==0
9 assert report['passed']==len(report['checks'])==len(set(report['checks']))
10 assert len(report['cases'])==4
11 prefix='https://ctm-tests.example.invalid/cd165b150176c1d6842b37be9cc9051b40d4996b/'
12 for case in report['cases']:
13 ident=case['id']; doc=case['documentIRI']; m=case['actualObjects']
14 assert doc==prefix+ident
15 assert case['ctmSource'].encode('utf-8')==(root/'vendor/cxtm'/ident).read_bytes()
16 two=ident.endswith('/occurrence-two.ctm'); uri=ident.endswith('/occurrence-uri-relative.ctm')
17 identifiers=['tmcl-schema','description','see-also'] if two else ['topic','occtype']
18 assert m['topicCount']==len(identifiers) and m['occurrenceCount']==(2 if two else 1)
19 assert m['nameCount']==m['associationCount']==0
20 for index,(t,local) in enumerate(zip(m['topics'],identifiers),1):
21 assert t['ordinal']==index and t['itemIdentifiers']==[doc+'#'+local]
22 assert t['subjectIdentifiers']==t['subjectLocators']==[]
23 if index!=1: assert t['occurrences']==[]
24 values=['A meta-schema for TMCL, describing the allowed structure\n of TMCL schemas.',
25 'http://www.isotopicmaps.org/tmcl/tmcl.html'] if two else [prefix+'ctm/in/file.html' if uri else 'Occurrence']
26 for index,(o,value) in enumerate(zip(m['topics'][0]['occurrences'],values),1):
27 kind='anyURI' if uri or (two and index==2) else 'string'
28 assert o=={'value':value,'datatype':'http://www.w3.org/2001/XMLSchema#'+kind,
29 'parentTopicOrdinal':1,'typeTopicOrdinal':index+1,'itemIdentifiers':[]}
30 assert case['status']=='pass'
31 print('OCCURRENCE-INDEPENDENT-PASS: four original sources, actual parents/types, lexical values, datatype locators, no extra items')