-
Notifications
You must be signed in to change notification settings - Fork 15
/
Copy pathtest_message.py
53 lines (43 loc) · 1.78 KB
/
test_message.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
#!/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 pathlib
import rdflib.plugins.sparql
def test_messages_have_sent_times() -> None:
expected = set()
computed = set()
graph = rdflib.Graph()
srcdir_path = pathlib.Path(__file__).parent
message_json_path = srcdir_path / "message.json"
assert (
message_json_path.exists()
), "message.json not found in same directory as test."
# TODO - Remove 'format' parameter when an rdflib release with this PR is issued:
# https://github.com/RDFLib/rdflib/pull/1403
graph.parse(str(message_json_path), format="json-ld")
nsdict = {k: v for (k, v) in graph.namespace_manager.namespaces()}
query_str = """\
SELECT ?nMessage
WHERE {
?nMessage uco-core:hasFacet ?nMessageFacet .
?nMessageFacet a uco-observable:MessageFacet .
FILTER NOT EXISTS {
?nMessageFacet uco-observable:sentTime ?lSentTime .
}
}
"""
query_object = rdflib.plugins.sparql.prepareQuery(query_str, initNs=nsdict)
for result in graph.query(query_object):
n_message = result[0]
computed.add(n_message.toPython())
assert (
expected == computed
), "Message objects with IRIs in the 'computed' set do not have sent-times. Please ensure this example has sent-times."