]>
dreyeck.freedombox.rocks Git - topic-maps.git/blob - scripts/check-cxtm.py
2dbd7d70b3355ded0b9bf1a29ce9d136eca0e420
2 """Independent raw UTF-8 comparison, XML reference integrity and C14N checks."""
6 import xml
.etree
.ElementTree
as ET
7 root
= pathlib
.Path(__file__
).resolve().parent
.parent
8 report
= json
.loads(pathlib
.Path(sys
.argv
[1]).read_text())
9 assert report
['kind'] == 'cxtm-byte-equality' and report
['failed'] == 0
10 assert report
['passed'] == len(report
['checks']) == len(set(report
['checks']))
11 expected_count
= {'--slice-19b': 171, '--slice-18': 167, '--slice-17b': 110, '--slice-17a': 97, '--slice-16b': 96, '--slice-15': 85, '--slice-14': 64, '--slice-13': 61, '--slice-12a': 58, '--slice-5': 28, '--slice-6': 33, '--slice-7': 39, '--slice-8': 46, '--slice-9': 51, '--slice-10': 55, '--slice-11': 56}.get(sys
.argv
[2] if len(sys
.argv
) > 2 else '', 24)
12 assert len(report
['cases']) == expected_count
13 for case
in report
['cases']:
14 actual
= case
['actualCXTM'].encode('utf-8')
15 expected
= (root
/ 'vendor/cxtm/ctm/baseline' / (pathlib
.Path(case
['id']).name
+ '.cxtm')).read_bytes()
16 assert expected
== case
['expectedCXTM'].encode('utf-8')
17 discrepancy
= expected_count
>= 55 and (case
['id'] == 'ctm/in/occurrence-datetime2.ctm' or expected_count
>= 56 and case
['id'] == 'ctm/in/occurrence-datetime-timezone2.ctm')
19 assert actual
!= expected
and case
['status'] == 'fail'
20 if case
['id'].endswith('timezone2.ctm'):
21 assert b
'<value>2010-12-31T22:00:00Z</value>' in actual
22 assert b
'<value>2011-01-01T00:00:00+02:00</value>' in expected
24 assert b
'<value>1976-09-19T12:02:00</value>' in actual
25 assert b
'<value>1976-09-19T12:01:60</value>' in expected
27 assert actual
== expected
and case
['status'] == 'pass', case
['id']
28 assert case
['byteCount'] == len(actual
)
29 assert case
['baseLocator'].endswith('/' + case
['id'])
30 # CXTM 3.1 adds an LF after the root. XML reparsing drops that Infoset
31 # sibling; this check is separate from the unmodified byte comparison.
32 assert actual
.endswith(b
'</topicMap>\n') and not actual
.startswith(b
'\xef\xbb\xbf')
33 assert ET
.canonicalize(case
['actualCXTM']) + '\n' == case
['actualCXTM'], case
['id']
34 xml
= ET
.fromstring(actual
)
35 topics
= xml
.findall('topic'); associations
= xml
.findall('association')
36 assert [t
.attrib
['number'] for t
in topics
] == list(map(str,range(1,len(topics
)+1)))
38 for i
, a
in enumerate(associations
,1):
39 assert a
.attrib
['number'] == str(i
)
40 for j
, r
in enumerate(a
.findall('role'),1):
41 assert r
.attrib
['number'] == str(j
)
42 role_refs
[f
'association.{i}.role.{j}'] = r
.find('player').attrib
['topicref']
44 assert [o
.attrib
['number'] for o
in t
.findall('occurrence')] == list(map(str, range(1,len(t
.findall('occurrence'))+1)))
45 for n
in t
.findall('name'):
46 assert [v
.attrib
['number'] for v
in n
.findall('variant')] == list(map(str, range(1,len(n
.findall('variant'))+1)))
47 for v
in n
.findall('variant'):
48 assert [c
.tag
for c
in v
] == ['value', 'datatype', 'scope']
49 assert v
.find('scope/scopingTopic') is not None
50 for r
in t
.findall('rolePlayed'):
51 assert role_refs
[r
.attrib
['ref']] == t
.attrib
['number']
52 assert sum(len(t
.findall('rolePlayed')) for t
in topics
) == len(role_refs
)
53 for ref
in xml
.iter():
54 if 'reifier' in ref
.attrib
:
55 assert 1 <= int(ref
.attrib
['reifier']) <= len(topics
)
56 if 'topicref' in ref
.attrib
:
57 assert 1 <= int(ref
.attrib
['topicref']) <= len(topics
)
58 passes
= sum(c
['status'] == 'pass' for c
in report
['cases'])
59 fails
= sum(c
['status'] == 'fail' for c
in report
['cases'])
60 print(f
'CXTM-INDEPENDENT-PASS: {passes} byte-exact unchanged baselines; {fails} explicit normative discrepancy; canonical XML and reference integrity')