]>
dreyeck.freedombox.rocks Git - topic-maps.git/blob - scripts/check-integers.py
2 """Independent integer arithmetic, TMDM property and raw baseline evidence checks."""
6 import xml
.etree
.ElementTree
as ET
8 root
= pathlib
.Path(__file__
).resolve().parent
.parent
9 report
= json
.loads(pathlib
.Path(sys
.argv
[1]).read_text())
10 assert report
['kind'] == 'integer-semantic-and-cxtm-evidence' and report
['failed'] == 0
11 assert report
['passed'] == len(report
['checks']) == len(set(report
['checks']))
12 names
= ['occurrence-integer', 'occurrence-integer2', 'occurrence-integer-plus-sign',
13 'occurrence-integer-minus-sign', 'occurrence-integer-leading-zeros', 'occurrence-explicit-datatype2']
14 assert [c
['id'] for c
in report
['cases']] == ['ctm/in/' + n
+ '.ctm' for n
in names
]
15 iri_prefix
= 'https://ctm-tests.example.invalid/cd165b150176c1d6842b37be9cc9051b40d4996b/'
16 datatype
= 'http://www.w3.org/2001/XMLSchema#integer'
17 for c
in report
['cases']:
18 ident
= c
['id']; doc
= c
['documentIRI']; m
= c
['actualObjects']
19 assert c
['ctmSource'].encode('utf-8') == (root
/ 'vendor/cxtm' / ident
).read_bytes()
20 assert doc
== iri_prefix
+ ident
and c
['status'] == 'pass'
21 zeros
= ident
.endswith('occurrence-integer-leading-zeros.ctm')
22 expected
= ['1', '1', '-1', '100', '0', '0', '0'] if zeros
else ['-1'] if ident
.endswith('minus-sign.ctm') else ['42'] if ident
.endswith('datatype2.ctm') else ['1']
23 assert m
['topicCount'] == len(m
['topics']) == (8 if zeros
else 2)
24 assert m
['occurrenceCount'] == len(expected
) and m
['nameCount'] == m
['associationCount'] == 0
25 locals_
= ['topic'] + ([f
'o{i}' for i
in range(1, 8)] if zeros
else ['occtype'])
26 for ordinal
, (topic
, local
) in enumerate(zip(m
['topics'], locals_
), 1):
27 assert topic
['ordinal'] == ordinal
and topic
['itemIdentifiers'] == [doc
+ '#' + local
]
28 assert topic
['subjectIdentifiers'] == topic
['subjectLocators'] == []
30 assert topic
['occurrences'] == []
31 assert m
['topics'][0]['occurrences'] == [dict(value
=v
, datatype
=datatype
, parentTopicOrdinal
=1,
32 typeTopicOrdinal
=i
+ 2, itemIdentifiers
=[]) for i
, v
in enumerate(expected
)]
33 # Python big integers provide an independent algorithm, including 10,000 digits.
34 # Narrow the accepted whitespace here to XML whitespace, not Python's Unicode set.
35 if hasattr(sys
, 'set_int_max_str_digits'):
36 sys
.set_int_max_str_digits(0)
37 assert len(report
['lexicalProbes']) == 143
38 for p
in report
['lexicalProbes']:
39 expected
= str(int(p
['input'].strip(' \t\r\n'), 10))
40 assert p
['datatype'] == datatype
41 assert p
['storedValue'] == (expected
if p
['mode'] == 'implicit' else p
['input'])
42 xml
= ET
.fromstring(p
['actualCXTM'])
43 occurrences
= xml
.findall('topic/occurrence')
44 assert len(occurrences
) == 1 and occurrences
[0].findtext('value') == expected
45 assert occurrences
[0].findtext('datatype') == datatype
46 print('INTEGER-INDEPENDENT-PASS: 6 original sources/model observations; 143 arithmetic-oracle probes, including 10000-digit integers')