Skip to content

Commit 1c59404

Browse files
committed
Test for IRIs that share UUIDs
This is part of implementing CASE-Examples-QC PR 54. No effects were observed on Make-managed files. References: * ajnelson-nist/CASE-Examples-QC#54 Signed-off-by: Alex Nelson <alexander.nelson@nist.gov>
1 parent 11b57db commit 1c59404

File tree

2 files changed

+76
-0
lines changed

2 files changed

+76
-0
lines changed

examples/postvisit.mk

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,9 @@ all_jsonld := $(foreach illustration_dir,$(illustration_dirs),$(illustration_dir
3030
all: \
3131
kb.ttl
3232

33+
.PHONY: \
34+
check-pytest
35+
3336
all-drafting.ttl: \
3437
$(all_drafting_ttl)
3538
source $(top_srcdir)/venv/bin/activate \
@@ -40,7 +43,16 @@ all-drafting.ttl: \
4043
mv _$@ $@
4144

4245
check: \
46+
check-pytest
47+
48+
check-pytest: \
4349
kb.ttl
50+
source $(top_srcdir)/venv/bin/activate \
51+
&& pytest \
52+
--ignore urgent_evidence \
53+
--log-level=DEBUG \
54+
--verbose \
55+
--verbose
4456

4557
clean:
4658
@rm -f \
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
#!/usr/bin/env python3
2+
3+
# Portions of this file contributed by NIST are governed by the
4+
# following statement:
5+
#
6+
# This software was developed at the National Institute of Standards
7+
# and Technology by employees of the Federal Government in the course
8+
# of their official duties. Pursuant to Title 17 Section 105 of the
9+
# United States Code, this software is not subject to copyright
10+
# protection within the United States. NIST assumes no responsibility
11+
# whatsoever for its use by other parties, and makes no guarantees,
12+
# expressed or implied, about its quality, reliability, or any other
13+
# characteristic.
14+
#
15+
# We would appreciate acknowledgement if the software is used.
16+
17+
import logging
18+
from collections import defaultdict
19+
from pathlib import Path
20+
from pprint import pformat
21+
from typing import DefaultDict, Dict, Set
22+
from uuid import UUID
23+
24+
from rdflib import Graph, URIRef
25+
26+
srcdir = Path(__file__).parent
27+
28+
29+
def test_uuid_unique_usage_casework_github_io() -> None:
30+
"""
31+
This test confirms that if two node IRIs end with the same UUID, then the IRI matches.
32+
This test is likely to be copied and adjusted between several example repositories.
33+
"""
34+
uuid_to_urirefs: DefaultDict[UUID, Set[URIRef]] = defaultdict(set)
35+
graph = Graph()
36+
graph.parse(srcdir / "kb.ttl")
37+
38+
def _ingest(n_thing: URIRef) -> None:
39+
thing_iri = str(n_thing)
40+
if len(thing_iri) < 40:
41+
# Not long enough to contain scheme, colon, and UUID.
42+
return
43+
try:
44+
thing_uuid = UUID(thing_iri[-36:])
45+
except ValueError:
46+
return
47+
uuid_to_urirefs[thing_uuid].add(n_thing)
48+
49+
for triple in graph.triples((None, None, None)):
50+
if isinstance(triple[0], URIRef):
51+
_ingest(triple[0])
52+
if isinstance(triple[2], URIRef):
53+
_ingest(triple[2])
54+
55+
computed: Dict[str, Set[str]] = dict()
56+
for _uuid in uuid_to_urirefs:
57+
if len(uuid_to_urirefs[_uuid]) > 1:
58+
computed[str(_uuid)] = {str(x) for x in uuid_to_urirefs[_uuid]}
59+
60+
try:
61+
assert len(computed) == 0
62+
except AssertionError:
63+
logging.debug(pformat(computed))
64+
raise

0 commit comments

Comments
 (0)