Skip to content

Commit

Permalink
reformat all tests in /test dir according to Black.
Browse files Browse the repository at this point in the history
  • Loading branch information
ashleysommer committed Oct 28, 2024
1 parent 8af4cfe commit 88c0175
Show file tree
Hide file tree
Showing 33 changed files with 283 additions and 70 deletions.
7 changes: 4 additions & 3 deletions test/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
from os import path, walk
import rdflib
from rdflib.namespace import Namespace, RDF, RDFS

MF = Namespace('http://www.w3.org/2001/sw/DataAccess/tests/test-manifest#')
SHT = Namespace('http://www.w3.org/ns/shacl-test#')

Expand All @@ -28,6 +29,7 @@ def __init__(self, node, sht_graph, result_node, data_graph, shapes_graph, label
self.label = label
self.status = status


class Manifest(object):
def __init__(self, base, sht_graph, node, includes, entries=None, label=None):
"""
Expand Down Expand Up @@ -133,7 +135,7 @@ def load_manifest(filename, recursion=0):
href = str(i)
if platform.system() == "Windows":
if href.startswith("file:///"):
child_mf = load_manifest(href[8:], recursion=recursion+1)
child_mf = load_manifest(href[8:], recursion=recursion + 1)
else:
raise RuntimeError("Manifest can only include file:/// uris")
else:
Expand Down Expand Up @@ -182,7 +184,6 @@ def flatten_manifests(root_manifest, only_with_entries=False, recursion=0):
else:
m_list.append(root_manifest)
for i in includes:
f = flatten_manifests(i, only_with_entries=only_with_entries,
recursion=recursion+1)
f = flatten_manifests(i, only_with_entries=only_with_entries, recursion=recursion + 1)
m_list.extend(f)
return m_list
18 changes: 10 additions & 8 deletions test/implementation_report.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,7 @@

tests_found_in_manifests = OrderedDict(sorted(tests_found_in_manifests.items()))

tests_base_index = [
(base, i)
for base, tests in tests_found_in_manifests.items()
for i, t in enumerate(tests)
]
tests_base_index = [(base, i) for base, tests in tests_found_in_manifests.items() for i, t in enumerate(tests)]


"""
Expand All @@ -64,6 +60,7 @@

assertions = {}


def make_assertion(base, index):
assertion = list()
assertion_node = rdflib.BNode()
Expand Down Expand Up @@ -95,9 +92,14 @@ def make_assertion(base, index):
print("testing: {}".format(label))
try:
val, _, v_text = pyshacl.validate(
data_file, shacl_graph=shacl_file, inference='rdfs',
check_sht_result=True, sht_validate=sht_validate,
debug=True, meta_shacl=False)
data_file,
shacl_graph=shacl_file,
inference='rdfs',
check_sht_result=True,
sht_validate=sht_validate,
debug=True,
meta_shacl=False,
)
except (NotImplementedError, ReportableRuntimeError) as e:
print(e)
info_text = rdflib.Literal(str(e.args[0]), lang="en")
Expand Down
2 changes: 2 additions & 0 deletions test/issues/issue_102.py
Original file line number Diff line number Diff line change
Expand Up @@ -284,6 +284,7 @@
'''


def test_102():
g_shacl = Graph().parse(data=qb_shacl, format="turtle")
g_data = Graph().parse(data=qb_data, format="turtle")
Expand All @@ -292,5 +293,6 @@ def test_102():
print(a)
assert conforms


if __name__ == "__main__":
test_102()
15 changes: 12 additions & 3 deletions test/issues/test_008.py
Original file line number Diff line number Diff line change
Expand Up @@ -232,11 +232,20 @@
.
'''


def test_008():
res1 = validate(mixed_file_text, data_graph_format='turtle', shacl_graph_format='turtle', inference='both', debug=True)
res1 = validate(
mixed_file_text, data_graph_format='turtle', shacl_graph_format='turtle', inference='both', debug=True
)
conforms, graph, string = res1
assert not conforms
res2 = validate(data_file_text, shacl_graph=shacl_file_text, data_graph_format='turtle', shacl_graph_format='turtle', inference='both', debug=True)
res2 = validate(
data_file_text,
shacl_graph=shacl_file_text,
data_graph_format='turtle',
shacl_graph_format='turtle',
inference='both',
debug=True,
)
conforms, graph, string = res2
assert not conforms

11 changes: 9 additions & 2 deletions test/issues/test_009.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,15 @@
}
"""


def test_009():
res = validate(data_file_text, shacl_graph=shacl_file_text, data_graph_format='json-ld', shacl_graph_format='turtle', inference='both', debug=True)
res = validate(
data_file_text,
shacl_graph=shacl_file_text,
data_graph_format='json-ld',
shacl_graph_format='turtle',
inference='both',
debug=True,
)
conforms, graph, string = res
assert not conforms

14 changes: 11 additions & 3 deletions test/issues/test_012.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,15 +32,23 @@
hei:Ship_to_street "Industrieweg" .
"""


def test_012_text():
res = validate(data_file_text, shacl_graph=shacl_file_text,
data_graph_format='turtle', shacl_graph_format='turtle',
inference='both', debug=True)
res = validate(
data_file_text,
shacl_graph=shacl_file_text,
data_graph_format='turtle',
shacl_graph_format='turtle',
inference='both',
debug=True,
)
conforms, graph, string = res
assert not conforms


def test_012_graph():
from rdflib import Graph

g = Graph()
g.parse(data=data_file_text, format='turtle')
sg = Graph()
Expand Down
24 changes: 18 additions & 6 deletions test/issues/test_014.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,21 +84,33 @@


def test_014_fail():
res = validate(data_file_text, shacl_graph=shacl_file_text, data_graph_format='turtle',
shacl_graph_format='turtle', inference='both', debug=True)
res = validate(
data_file_text,
shacl_graph=shacl_file_text,
data_graph_format='turtle',
shacl_graph_format='turtle',
inference='both',
debug=True,
)
conforms, graph, string = res
assert not conforms


def test_014_pass():
res = validate(data_file_text, shacl_graph=shacl_file_text, data_graph_format='turtle',
shacl_graph_format='turtle', ont_graph=ontology_file_text,
ont_graph_format="turtle", inference='both', debug=True)
res = validate(
data_file_text,
shacl_graph=shacl_file_text,
data_graph_format='turtle',
shacl_graph_format='turtle',
ont_graph=ontology_file_text,
ont_graph_format="turtle",
inference='both',
debug=True,
)
conforms, graph, string = res
assert conforms



if __name__ == "__main__":
test_014_fail()
test_014_pass()
24 changes: 18 additions & 6 deletions test/issues/test_026.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,17 +80,29 @@
}
"""


def test_026_trig():
res = validate(data_file_text_trig, shacl_graph=shacl_file_text,
data_graph_format='trig', shacl_graph_format='turtle',
inference='both', debug=True)
res = validate(
data_file_text_trig,
shacl_graph=shacl_file_text,
data_graph_format='trig',
shacl_graph_format='turtle',
inference='both',
debug=True,
)
conforms, graph, string = res
assert not conforms


def test_026_jsonld():
res = validate(data_file_text_jsonld, shacl_graph=shacl_file_text,
data_graph_format='json-ld', shacl_graph_format='turtle',
inference='both', debug=True)
res = validate(
data_file_text_jsonld,
shacl_graph=shacl_file_text,
data_graph_format='json-ld',
shacl_graph_format='turtle',
inference='both',
debug=True,
)
conforms, graph, string = res
assert not conforms

Expand Down
5 changes: 2 additions & 3 deletions test/issues/test_029/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,10 @@


def test_029():
res = validate(data_graph, shacl_graph=shacl_graph, ont_graph=shacl_graph,
inference='none', debug=True)
res = validate(data_graph, shacl_graph=shacl_graph, ont_graph=shacl_graph, inference='none', debug=True)
conforms, graph, string = res
assert not conforms


if __name__ == "__main__":
test_029()

12 changes: 9 additions & 3 deletions test/issues/test_036.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,16 @@
}
"""


def test_036_jsonld():
res = validate(data_file_text_jsonld, shacl_graph=shacl_file_text,
data_graph_format='json-ld', shacl_graph_format='json-ld',
inference='rdfs', debug=True)
res = validate(
data_file_text_jsonld,
shacl_graph=shacl_file_text,
data_graph_format='json-ld',
shacl_graph_format='json-ld',
inference='rdfs',
debug=True,
)
conforms, graph, string = res
assert not conforms

Expand Down
15 changes: 10 additions & 5 deletions test/issues/test_038.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@
from pyshacl import validate

shapes = Graph()
shapes.parse(data="""
shapes.parse(
data="""
@prefix sh: <http://www.w3.org/ns/shacl#> .
@prefix owl: <http://www.w3.org/2002/07/owl#> .
@prefix ex: <http://example.org/ns#> .
Expand All @@ -25,17 +26,21 @@
sh:path ex:name ;
sh:minCount 1 ;
.
""",format="ttl")
""",
format="ttl",
)

data = Graph()
data.parse(data="""
data.parse(
data="""
@prefix ex: <http://example.org/ns#> .
ex:Bob
a ex:Person ;
.
""",format="ttl")

""",
format="ttl",
)


def test_038():
Expand Down
6 changes: 3 additions & 3 deletions test/issues/test_058.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,20 +26,20 @@
"""



def test_058():
dataGraph = rdflib.Graph().parse(data=data, format='ttl')
shaclGraph = rdflib.Graph().parse(data=shaclData, format='ttl')
exc = None
try:
conforms, g, s = validate(dataGraph, shacl_graph=shaclGraph, abort_on_first=False, meta_shacl=False, debug=False, advanced=True)
conforms, g, s = validate(
dataGraph, shacl_graph=shaclGraph, abort_on_first=False, meta_shacl=False, debug=False, advanced=True
)
except Exception as e:
assert isinstance(e, ConstraintLoadError)
exc = e
assert exc is not None
assert "ignoredProperties" in str(exc)



if __name__ == "__main__":
test_058()
17 changes: 14 additions & 3 deletions test/issues/test_062.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,18 +103,29 @@
sh:targetClass exOnt:Animal .
"""


def test_062():
data_fp = BytesIO(data)
shacl_fp = BytesIO(shacl_data)
ont_fp = BytesIO(ont_data)
try:
conforms, g, s = validate(data_fp, shacl_graph=shacl_fp, ont_graph=ont_fp, data_graph_format="json-ld",
shacl_graph_format="turtle", ont_graph_format="turtle", abort_on_first=False,
meta_shacl=False, debug=True, advanced=True)
conforms, g, s = validate(
data_fp,
shacl_graph=shacl_fp,
ont_graph=ont_fp,
data_graph_format="json-ld",
shacl_graph_format="turtle",
ont_graph_format="turtle",
abort_on_first=False,
meta_shacl=False,
debug=True,
advanced=True,
)
except Exception as e:
print(e)
raise
assert conforms


if __name__ == "__main__":
test_062()
12 changes: 9 additions & 3 deletions test/issues/test_079.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
"""
import rdflib
import pyshacl

shapes_data = """\
@prefix ex: <https://example.com#> .
@prefix sh: <http://www.w3.org/ns/shacl#> .
Expand All @@ -28,16 +29,21 @@

def test_079():
shape_g = rdflib.Graph().parse(data=shapes_data, format='turtle')
data_g = rdflib.Graph().parse(data="""
data_g = rdflib.Graph().parse(
data="""
@prefix ex: <https://example.com#> .
ex:aaa a ex:AAA.
ex:aaa a ex:BBB.
ex:aaa a ex:CCC.
""", format='turtle')
""",
format='turtle',
)

conforms, results_graph, results_text = pyshacl.validate(
data_g, shacl_graph=shape_g, debug=True,
data_g,
shacl_graph=shape_g,
debug=True,
)
assert not conforms

Expand Down
Loading

0 comments on commit 88c0175

Please sign in to comment.