forked from usnistgov/CASE-Implementation-PROV-O
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_urgent_evidence.py
86 lines (77 loc) · 2.79 KB
/
test_urgent_evidence.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
#!/usr/bin/env python3
# This software was developed at the National Institute of Standards
# and Technology by employees of the Federal Government in the course
# of their official duties. Pursuant to title 17 Section 105 of the
# United States Code this software is not subject to copyright
# protection and is in the public domain. NIST assumes no
# responsibility whatsoever for its use by other parties, and makes
# no guarantees, expressed or implied, about its quality,
# reliability, or any other characteristic.
#
# We would appreciate acknowledgement if the software is used.
import typing
import rdflib
def test_chain_of_communication() -> None:
graph = rdflib.Graph()
graph.parse("urgent_evidence-prov.ttl", format="turtle")
expected: typing.Set[str] = set()
computed: typing.Set[str] = set()
computed_all = set()
computed_linked = set()
query_all = """\
SELECT ?nActivity
WHERE {
?nActivity a prov:Activity .
}
"""
for result in graph.query(query_all):
assert isinstance(result, rdflib.query.ResultRow)
assert isinstance(result[0], rdflib.term.IdentifiedNode)
computed_all.add(result[0].toPython())
query_linked = """\
SELECT ?nActivity
WHERE {
?nActivity prov:wasInformedBy*/prov:used prov:EmptyCollection .
}
"""
for result in graph.query(query_linked):
assert isinstance(result, rdflib.query.ResultRow)
assert isinstance(result[0], rdflib.term.IdentifiedNode)
computed_linked.add(result[0].toPython())
computed = computed_all - computed_linked
assert expected == computed
def test_chain_of_derivation() -> None:
graph = rdflib.Graph()
graph.parse("urgent_evidence-prov.ttl", format="turtle")
expected: typing.Set[str] = set()
computed: typing.Set[str] = set()
computed_all = set()
computed_linked = set()
query_all = """\
SELECT ?nEntity
WHERE {
?nEntity a prov:Entity .
}
"""
for result in graph.query(query_all):
assert isinstance(result, rdflib.query.ResultRow)
assert isinstance(result[0], rdflib.term.IdentifiedNode)
computed_all.add(result[0].toPython())
query_linked = """\
SELECT ?nEntity
WHERE {
?nEntity prov:wasDerivedFrom* prov:EmptyCollection .
}
"""
for result in graph.query(query_linked):
assert isinstance(result, rdflib.query.ResultRow)
assert isinstance(result[0], rdflib.term.IdentifiedNode)
computed_linked.add(result[0].toPython())
computed = computed_all - computed_linked
# TODO Correct website example after documenting discovery method.
computed_known_errors = {"http://example.org/kb/file2-uuid-1"}
assert (
len(computed & computed_known_errors) > 0
), "One known error not found - has it been corrected already?"
computed -= computed_known_errors
assert expected == computed