Skip to content

Commit 2fff550

Browse files
Merge pull request #22 from casework/update_case_utils_usage
Update case_utils usage
2 parents 7dcb4b8 + 8854bf8 commit 2fff550

23 files changed

+296
-60
lines changed

case_gnu_time/__init__.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ def __init__(self, graph, ns_base, **kwargs):
4949

5050
# Guarantee at least one triple enters the graph.
5151
self._node = rdflib.URIRef(ns_base[prefix_slug + case_utils.local_uuid.local_uuid()])
52-
self.graph.add((self.node, NS_RDF.type, NS_UCO_OBSERVABLE.ObservableObject))
52+
self.graph.add((self.node, NS_RDF.type, NS_UCO_OBSERVABLE.Process))
5353

5454
self._bnode_process = None
5555
self._created_time = None
@@ -141,7 +141,7 @@ def exit_status(self):
141141
@exit_status.setter
142142
def exit_status(self, value):
143143
assert isinstance(value, int)
144-
self.graph.add((self.bnode_process, NS_UCO_OBSERVABLE.exitStatus, rdflib.Literal(value, datatype=NS_XSD.long)))
144+
self.graph.add((self.bnode_process, NS_UCO_OBSERVABLE.exitStatus, rdflib.Literal(value)))
145145
return self._exit_status
146146

147147
@property

setup.cfg

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,15 +17,10 @@ classifiers =
1717

1818
[options]
1919
install_requires =
20-
case_utils
21-
# TODO - This constraint on pyparsing can be removed when rdflib Issue #1190 is resolved.
22-
# https://github.com/RDFLib/rdflib/issues/1190
23-
pyparsing < 3.0.0
20+
case_utils >= 0.3.0
2421
python-dateutil
25-
rdflib
26-
requests
2722
packages = find:
28-
python_requires = >=3.6
23+
python_requires = >=3.7
2924

3025
[options.entry_points]
3126
console_scripts =

tests/Makefile

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,9 @@ all: \
6262
--requirement $(top_srcdir)/dependencies/CASE-Utilities-Python/tests/requirements.txt
6363
source venv/bin/activate \
6464
&& cd $(top_srcdir) \
65-
&& python3 setup.py install
65+
&& pip install \
66+
--editable \
67+
.
6668
source venv/bin/activate \
6769
&& pip install \
6870
-r requirements.txt

tests/as_import/Makefile

Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,10 +40,12 @@ endif
4040
RDF_TOOLKIT_JAR := $(case_srcdir)/lib/rdf-toolkit.jar
4141

4242
all: \
43-
undefined_vocabulary.txt
43+
undefined_vocabulary.txt \
44+
validation.ttl
4445

4546
check: \
46-
undefined_vocabulary.txt
47+
undefined_vocabulary.txt \
48+
validation.ttl
4749
@test ! -s undefined_vocabulary.txt \
4850
|| (echo "ERROR:tests/as_import/Makefile:The output in process.json has undefined CASE or UCO terms. The first few are:" >&2 && head undefined_vocabulary.txt >&2 && exit 1)
4951
source $(tests_srcdir)/venv/bin/activate \
@@ -82,7 +84,6 @@ echo.txt.time.log: \
8284

8385
process.json: \
8486
process.ttl \
85-
$(RDF_TOOLKIT_JAR) \
8687
$(top_srcdir)/dependencies/CASE-Utilities-Python/tests/src/compact.py
8788
java -jar $(RDF_TOOLKIT_JAR) \
8889
--infer-base-iri \
@@ -99,7 +100,9 @@ process.json: \
99100
mv _$@ $@
100101

101102
process.ttl: \
103+
$(RDF_TOOLKIT_JAR) \
102104
$(tests_srcdir)/.venv.done.log \
105+
$(top_srcdir)/case_gnu_time/__init__.py \
103106
consumer.py \
104107
echo.txt.done.log \
105108
echo.txt.time.log
@@ -141,3 +144,23 @@ undefined_vocabulary.txt: \
141144
> $@_
142145
rm $@__
143146
mv $@_ $@
147+
148+
validation.ttl: \
149+
process.json
150+
rm -f __$@
151+
source $(tests_srcdir)/venv/bin/activate \
152+
&& case_validate \
153+
--format turtle \
154+
--output __$@ \
155+
$< \
156+
; rc=$$? ; test 1 -eq $$rc -o 0 -eq $$rc
157+
test -s __$@
158+
java -jar $(RDF_TOOLKIT_JAR) \
159+
--infer-base-iri \
160+
--inline-blank-nodes \
161+
--source __$@ \
162+
--source-format turtle \
163+
--target _$@ \
164+
--target-format turtle
165+
rm __$@
166+
mv _$@ $@

tests/as_import/process.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,11 @@
77
"xsd": "http://www.w3.org/2001/XMLSchema#"
88
},
99
"@id": "kb:custom-011a93fd-814b-537f-b111-ce4dceb373a6",
10-
"@type": "uco-observable:ObservableObject",
10+
"@type": "uco-observable:Process",
1111
"uco-core:hasFacet": {
1212
"@type": "uco-observable:ProcessFacet",
1313
"uco-observable:exitStatus": {
14-
"@type": "xsd:long",
14+
"@type": "xsd:integer",
1515
"@value": "0"
1616
},
1717
"uco-observable:exitTime": {

tests/as_import/process.ttl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,10 @@
77
@prefix xsd: <http://www.w3.org/2001/XMLSchema#> .
88

99
kb:custom-011a93fd-814b-537f-b111-ce4dceb373a6
10-
a uco-observable:ObservableObject ;
10+
a uco-observable:Process ;
1111
uco-core:hasFacet [
1212
a uco-observable:ProcessFacet ;
13-
uco-observable:exitStatus "0"^^xsd:long ;
13+
uco-observable:exitStatus "0"^^xsd:integer ;
1414
uco-observable:exitTime "2020-10-14T14:07:39.267912-04:00"^^xsd:dateTime ;
1515
uco-observable:observableCreatedTime "2020-10-14T14:07:39.267912-04:00"^^xsd:dateTime ;
1616
] ;

tests/as_import/test_as_import.py

Lines changed: 23 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -14,33 +14,27 @@
1414
import logging
1515
import os
1616

17-
import rdflib
17+
import rdflib.plugins.sparql
18+
19+
import case_utils.ontology
1820

1921
_logger = logging.getLogger(os.path.basename(__file__))
2022

2123
srcdir = os.path.dirname(__file__)
2224

23-
def _parse_graph(filename, format):
25+
def _parse_graph(filename):
2426
graph_filename = os.path.join(srcdir, filename)
2527
graph = rdflib.Graph()
26-
graph.parse(graph_filename, format=format)
28+
graph.parse(graph_filename)
29+
case_utils.ontology.load_subclass_hierarchy(graph)
2730
return graph
2831

29-
def _test_as_import_load(graph_filename, format):
30-
graph = _parse_graph(graph_filename, format)
32+
def _test_as_import_load(graph_filename):
33+
graph = _parse_graph(graph_filename)
3134
assert len(graph) > 0
3235

33-
def _test_as_import_query(graph_filename, format):
34-
#TODO This try block can be removed, and the import put at the script's top, when rdflib Issue #1190 is resolved.
35-
# https://github.com/RDFLib/rdflib/issues/1190
36-
try:
37-
import rdflib.plugins.sparql
38-
except:
39-
import pyparsing
40-
_logger.debug("pyparsing.__version__ = %r." % pyparsing.__version__)
41-
raise
42-
43-
graph = _parse_graph(graph_filename, format)
36+
def _test_as_import_query(graph_filename):
37+
graph = _parse_graph(graph_filename)
4438

4539
nsdict = {k:v for (k,v) in graph.namespace_manager.namespaces()}
4640

@@ -50,13 +44,13 @@ def _test_as_import_query(graph_filename, format):
5044
WHERE
5145
{
5246
?nProcessObject
53-
a uco-observable:ObservableObject ;
47+
a/rdfs:subClassOf* uco-observable:ObservableObject ;
5448
uco-core:hasFacet ?nProcessFacet ;
5549
.
5650
5751
?nProcessFacet
5852
a uco-observable:ProcessFacet ;
59-
uco-observable:exitStatus "0"^^xsd:long ;
53+
uco-observable:exitStatus 0 ;
6054
.
6155
}
6256
""", initNs=nsdict)
@@ -73,13 +67,20 @@ def _test_as_import_query(graph_filename, format):
7367
assert len(iris) == 1
7468

7569
def test_as_import_load_json():
76-
_test_as_import_load("process.json", "json-ld")
70+
_test_as_import_load("process.json")
7771

7872
def test_as_import_load_turtle():
79-
_test_as_import_load("process.ttl", "turtle")
73+
_test_as_import_load("process.ttl")
8074

8175
def test_as_import_query_json():
82-
_test_as_import_query("process.json", "json-ld")
76+
_test_as_import_query("process.json")
8377

8478
def test_as_import_query_turtle():
85-
_test_as_import_query("process.ttl", "turtle")
79+
_test_as_import_query("process.ttl")
80+
81+
def test_as_import_validation():
82+
graph = _parse_graph("validation.ttl")
83+
result = None
84+
for triple in graph.triples((None, rdflib.SH.conforms, None)):
85+
result = triple[2].toPython()
86+
assert result

tests/as_import/validation.ttl

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
@prefix owl: <http://www.w3.org/2002/07/owl#> .
2+
@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
3+
@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .
4+
@prefix sh: <http://www.w3.org/ns/shacl#> .
5+
@prefix xsd: <http://www.w3.org/2001/XMLSchema#> .
6+
7+
[]
8+
a sh:ValidationReport ;
9+
sh:conforms "true"^^xsd:boolean ;
10+
.
11+

tests/from_pip/Makefile

Lines changed: 29 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,12 +40,17 @@ endif
4040
RDF_TOOLKIT_JAR := $(case_srcdir)/lib/rdf-toolkit.jar
4141

4242
all: \
43-
undefined_vocabulary.txt
43+
undefined_vocabulary.txt \
44+
validation.ttl
4445

4546
check: \
46-
undefined_vocabulary.txt
47+
undefined_vocabulary.txt \
48+
validation.ttl
4749
@test ! -s undefined_vocabulary.txt \
4850
|| (echo "ERROR:tests/from_pip/Makefile:The output in process.json has undefined CASE or UCO terms. The first few are:" >&2 && head undefined_vocabulary.txt >&2 && exit 1)
51+
source $(tests_srcdir)/venv/bin/activate \
52+
&& pytest \
53+
--log-level=DEBUG
4954

5055
clean:
5156
@rm -f \
@@ -79,7 +84,6 @@ echo.txt.time.log: \
7984

8085
process.json: \
8186
process.ttl \
82-
$(RDF_TOOLKIT_JAR) \
8387
$(top_srcdir)/dependencies/CASE-Utilities-Python/tests/src/compact.py
8488
java -jar $(RDF_TOOLKIT_JAR) \
8589
--infer-base-iri \
@@ -96,7 +100,9 @@ process.json: \
96100
mv _$@ $@
97101

98102
process.ttl: \
103+
$(RDF_TOOLKIT_JAR) \
99104
$(tests_srcdir)/.venv.done.log \
105+
$(top_srcdir)/case_gnu_time/__init__.py \
100106
echo.txt.done.log \
101107
echo.txt.time.log
102108
rm -f _$@ __$@
@@ -137,3 +143,23 @@ undefined_vocabulary.txt: \
137143
> $@_
138144
rm $@__
139145
mv $@_ $@
146+
147+
validation.ttl: \
148+
process.json
149+
rm -f __$@
150+
source $(tests_srcdir)/venv/bin/activate \
151+
&& case_validate \
152+
--format turtle \
153+
--output __$@ \
154+
$< \
155+
; rc=$$? ; test 1 -eq $$rc -o 0 -eq $$rc
156+
test -s __$@
157+
java -jar $(RDF_TOOLKIT_JAR) \
158+
--infer-base-iri \
159+
--inline-blank-nodes \
160+
--source __$@ \
161+
--source-format turtle \
162+
--target _$@ \
163+
--target-format turtle
164+
rm __$@
165+
mv _$@ $@

tests/from_pip/process.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,11 @@
77
"xsd": "http://www.w3.org/2001/XMLSchema#"
88
},
99
"@id": "kb:process-e7498b28-74d7-5952-a0e3-2f9e924bd662",
10-
"@type": "uco-observable:ObservableObject",
10+
"@type": "uco-observable:Process",
1111
"uco-core:hasFacet": {
1212
"@type": "uco-observable:ProcessFacet",
1313
"uco-observable:exitStatus": {
14-
"@type": "xsd:long",
14+
"@type": "xsd:integer",
1515
"@value": "0"
1616
},
1717
"uco-observable:exitTime": {

tests/from_pip/process.ttl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,10 @@
77
@prefix xsd: <http://www.w3.org/2001/XMLSchema#> .
88

99
kb:process-e7498b28-74d7-5952-a0e3-2f9e924bd662
10-
a uco-observable:ObservableObject ;
10+
a uco-observable:Process ;
1111
uco-core:hasFacet [
1212
a uco-observable:ProcessFacet ;
13-
uco-observable:exitStatus "0"^^xsd:long ;
13+
uco-observable:exitStatus "0"^^xsd:integer ;
1414
uco-observable:exitTime "2020-10-14T14:07:39.267912-04:00"^^xsd:dateTime ;
1515
uco-observable:observableCreatedTime "2020-10-14T14:07:39.267912-04:00"^^xsd:dateTime ;
1616
] ;

tests/from_pip/test_from_pip.py

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
#!/usr/bin/env python3
2+
3+
# This software was developed at the National Institute of Standards
4+
# and Technology by employees of the Federal Government in the course
5+
# of their official duties. Pursuant to title 17 Section 105 of the
6+
# United States Code this software is not subject to copyright
7+
# protection and is in the public domain. NIST assumes no
8+
# responsibility whatsoever for its use by other parties, and makes
9+
# no guarantees, expressed or implied, about its quality,
10+
# reliability, or any other characteristic.
11+
#
12+
# We would appreciate acknowledgement if the software is used.
13+
14+
import os
15+
16+
import rdflib.plugins.sparql
17+
18+
srcdir = os.path.dirname(__file__)
19+
20+
def _parse_graph(filename):
21+
graph_filename = os.path.join(srcdir, filename)
22+
graph = rdflib.Graph()
23+
graph.parse(graph_filename)
24+
return graph
25+
26+
def test_from_pip_validation():
27+
graph = _parse_graph("validation.ttl")
28+
result = None
29+
for triple in graph.triples((None, rdflib.SH.conforms, None)):
30+
result = triple[2].toPython()
31+
assert result

tests/from_pip/validation.ttl

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
@prefix owl: <http://www.w3.org/2002/07/owl#> .
2+
@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
3+
@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .
4+
@prefix sh: <http://www.w3.org/ns/shacl#> .
5+
@prefix xsd: <http://www.w3.org/2001/XMLSchema#> .
6+
7+
[]
8+
a sh:ValidationReport ;
9+
sh:conforms "true"^^xsd:boolean ;
10+
.
11+

0 commit comments

Comments
 (0)