]>
dreyeck.freedombox.rocks Git - topic-maps.git/blob - scripts/check-semantics.py
2 """Read frozen CXTM baselines as evidence for selected semantic properties.
3 No XML is generated, serialized, canonicalized or compared byte-for-byte here.
8 import xml
.etree
.ElementTree
as ET
9 root
= pathlib
.Path(__file__
).resolve().parent
.parent
10 report
= json
.loads(pathlib
.Path(sys
.argv
[1]).read_text())
11 assert report
['kind'] == 'semantic-observations-not-cxtm'
12 assert report
['failed'] == 0 and report
['passed'] == len(report
['checks'])
13 assert len(set(report
['checks'])) == len(report
['checks'])
14 assert [c
['id'] for c
in report
['cases']] == ['ctm/in/'+n
+'.ctm' for n
in
15 ['simple','subject-identifier','subject-locator','item-identifier','name']]
16 for case
in report
['cases']:
17 assert case
['status'] == 'pass'
18 assert case
['ctmSource'] == (root
/'vendor/cxtm'/case
['id']).read_bytes().decode('utf-8')
19 baseline
= root
/'vendor/cxtm/ctm/baseline'/(pathlib
.Path(case
['id']).name
+'.cxtm')
20 xml
= ET
.parse(baseline
).getroot()
21 assert xml
.tag
== 'topicMap'
22 xml_topics
= xml
.findall('topic')
23 actual
= case
['actualObjects']
24 assert actual
['topicCount'] == len(xml_topics
)
25 assert actual
['nameCount'] == sum(len(t
.findall('name')) for t
in xml_topics
)
26 for topic
, expected
in zip(actual
['topics'], xml_topics
):
27 assert topic
['ordinal'] == int(expected
.attrib
['number']) and topic
['parentIsMap'] is True
28 assert all(child
.tag
in ['itemIdentifiers','subjectIdentifiers','subjectLocators','name'] for child
in expected
)
29 for property_name
in ['itemIdentifiers','subjectIdentifiers','subjectLocators']:
30 values
= [locator
.text
for locator
in expected
.findall(property_name
+'/locator')]
31 # Only a Document-IRI-relative fragment is interpreted here. This
32 # illustrates the selected baselines; it is not a CXTM resolver.
33 values
= [case
['documentIRI']+v
if v
.startswith('#') else v
for v
in values
]
34 assert topic
[property_name
] == values
, (case
['id'], property_name
)
35 assert len(topic
['names']) == len(expected
.findall('name'))
36 for name
, expected_name
in zip(topic
['names'], expected
.findall('name')):
37 assert name
['value'] == expected_name
.find('value').text
38 assert name
['typeTopicOrdinal'] == int(expected_name
.find('type').attrib
['topicref'])
39 assert name
['parentTopicOrdinal'] == topic
['ordinal']
40 print('BASELINE-SEMANTIC-EVIDENCE-PASS: five frozen baselines support the selected properties; no canonicalization claimed')