]>
dreyeck.freedombox.rocks Git - topic-maps.git/blob - scripts/check-prefixes.py
2 """Check actual model observations, original sources and specific rejection positions."""
6 root
= pathlib
.Path(__file__
).resolve().parent
.parent
7 report
= json
.loads(pathlib
.Path(sys
.argv
[1]).read_text())
8 assert report
['kind'] == 'prefix-and-explicit-datatype-evidence' and report
['failed'] == 0
9 assert report
['passed'] == len(report
['checks']) == len(set(report
['checks']))
10 assert {c
['id'] for c
in report
['cases']} == {
11 'ctm/in/' + n
+ '.ctm' for n
in ['occurrence-explicit-datatype', 'occurrence-datatype-unknown',
12 'prefix-duplicate', 'prefix-duplicate2', 'prefix-multiline']
13 } |
{'ctm/invalid/prefix-collision.ctm', 'ctm/invalid/prefix-undefined2.ctm'}
14 assert len(report
['cases']) == 7
15 prefix
= 'https://ctm-tests.example.invalid/cd165b150176c1d6842b37be9cc9051b40d4996b/'
16 for c
in report
['cases']:
17 ident
= c
['id']; doc
= c
['documentIRI']; name
= pathlib
.Path(ident
).stem
18 source
= (root
/ 'vendor/cxtm' / ident
).read_bytes()
19 assert c
['ctmSource'].encode('utf-8') == source
20 assert doc
== prefix
+ ident
and c
['status'] == 'pass'
21 if '/invalid/' in ident
:
22 collision
= name
== 'prefix-collision'
23 assert c
['conditionClass'] == ('PREFIX-COLLISION' if collision
else 'UNDEFINED-PREFIX')
24 assert c
['code'] == c
['conditionClass'] and c
['positionUnit'] == 'character' and c
['source'] == ident
25 text
= source
.decode('utf-8')
26 position
= text
.index('ex http://www.example.net' if collision
else 'xsd:int')
27 assert c
['position'] == position
and c
['line'] == text
[:position
].count('\n') + 1
28 assert c
['column'] == position
- text
.rfind('\n', 0, position
)
30 m
= c
['actualObjects']; topics
= m
['topics']; occurrence
= name
.startswith('occurrence-')
31 assert m
['nameCount'] == m
['associationCount'] == 0
32 assert m
['topicCount'] == len(topics
) == (2 if occurrence
or name
== 'prefix-duplicate2' else 1)
33 assert m
['occurrenceCount'] == int(occurrence
)
34 for i
, t
in enumerate(topics
, 1):
35 assert t
['ordinal'] == i
and t
['subjectLocators'] == []
37 assert t
['itemIdentifiers'] == [doc
+ ('#topic' if i
== 1 else '#occtype')]
38 assert t
['subjectIdentifiers'] == []
40 assert t
['itemIdentifiers'] == [] and t
['occurrences'] == []
41 assert t
['subjectIdentifiers'] == ['http://psi.example.org/' + ('fake' if i
== 1 else 'fake2')]
43 unknown
= name
== 'occurrence-datatype-unknown'
44 assert topics
[1]['occurrences'] == []
45 assert topics
[0]['occurrences'] == [dict(value
='BOGUS' if unknown
else 'Occurrence',
46 datatype
='http://example.com/bogus' if unknown
else 'http://www.w3.org/2001/XMLSchema#string',
47 parentTopicOrdinal
=1, typeTopicOrdinal
=2, itemIdentifiers
=[])]
48 print('PREFIX-INDEPENDENT-PASS: 7 original sources, 5 model observations, 2 specific rejections with independently checked positions')