Coverage for target/native-coverage/profiles/11fb979bfcf049d7ab666c331dc8db2a/project/.venv/lib/python3.13/site-packages/pyshacl_turbo/boolean_output.py: 100%

19 statements  

« prev     ^ index     » next       coverage.py v7.17.2, created at 2026-11-30 14:51 +0000

1"""Validate sparse typed SH.value occurrences before constructing report terms.""" 

2 

3from rdflib.namespace import RDF, SH, XSD 

4 

5 

6def boolean_occurrences(records, quads, entries): 

7 def iri(index, value): 

8 return ( 

9 type(index) is int 

10 and 0 <= index < len(records) 

11 and tuple(records[index]) == (0, str(value), None, None) 

12 ) 

13 

14 results = {(s, g) for s, p, o, g in quads if iri(p, RDF.type) and iri(o, SH.ValidationResult)} 

15 result = {} 

16 for entry in entries: 

17 if not isinstance(entry, (list, tuple)) or len(entry) != 2: 

18 raise ValueError("Invalid Boolean report occurrence") 

19 index, code = entry 

20 if type(index) is not int or not 0 <= index < len(quads): 

21 raise ValueError("Invalid Boolean report quad index") 

22 if type(code) is not int or not 1 <= code <= 6 or index in result: 

23 raise ValueError("Invalid or duplicate Boolean report state") 

24 subject, predicate, value, context = quads[index] 

25 if ( 

26 not iri(predicate, SH.value) 

27 or records[value][0] != 2 

28 or records[value][1] not in ("false", "true") 

29 or tuple(records[value][2:]) != (str(XSD.boolean), None) 

30 or (subject, context) not in results 

31 ): 

32 raise ValueError("Boolean occurrence is not a direct ValidationResult value") 

33 result[index] = (code >= 4, (None, False, True)[(code - 1) % 3]) 

34 return result