From 88c0175c19945674f903f9c054ad179de399ecc7 Mon Sep 17 00:00:00 2001 From: Ashley Sommer Date: Mon, 28 Oct 2024 14:53:35 +1000 Subject: [PATCH] reformat all tests in /test dir according to Black. --- test/helpers.py | 7 +- test/implementation_report.py | 18 ++-- test/issues/issue_102.py | 2 + test/issues/test_008.py | 15 ++- test/issues/test_009.py | 11 +- test/issues/test_012.py | 14 ++- test/issues/test_014.py | 24 +++-- test/issues/test_026.py | 24 +++-- test/issues/test_029/__init__.py | 5 +- test/issues/test_036.py | 12 ++- test/issues/test_038.py | 15 ++- test/issues/test_058.py | 6 +- test/issues/test_062.py | 17 ++- test/issues/test_079.py | 12 ++- test/issues/test_087.py | 2 +- test/issues/test_108.py | 1 + test/issues/test_146.py | 1 + test/issues/test_170.py | 5 + test/issues/test_199.py | 13 ++- test/issues/test_213.py | 5 +- test/issues/test_96.py | 1 + test/issues/test_w3_list1.py | 5 +- test/test_advanced.py | 2 + test/test_dash_validate.py | 100 ++++++++++++++++-- test/test_js/conftest.py | 1 + test/test_js/test_js_constraint.py | 3 + test/test_js/test_js_constraint_component.py | 3 + .../test_js_constraint_path_component.py | 3 + test/test_js/test_js_function.py | 3 + test/test_js/test_js_rules.py | 3 + test/test_js/test_js_target.py | 3 + test/test_js/test_js_target_type.py | 3 + test/test_schema_org.py | 14 ++- 33 files changed, 283 insertions(+), 70 deletions(-) diff --git a/test/helpers.py b/test/helpers.py index fa2971c..a0c6466 100644 --- a/test/helpers.py +++ b/test/helpers.py @@ -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#') @@ -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): """ @@ -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: @@ -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 diff --git a/test/implementation_report.py b/test/implementation_report.py index 8284462..4f8a9ec 100644 --- a/test/implementation_report.py +++ b/test/implementation_report.py @@ -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)] """ @@ -64,6 +60,7 @@ assertions = {} + def make_assertion(base, index): assertion = list() assertion_node = rdflib.BNode() @@ -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") diff --git a/test/issues/issue_102.py b/test/issues/issue_102.py index 6e4ce20..9d01547 100644 --- a/test/issues/issue_102.py +++ b/test/issues/issue_102.py @@ -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") @@ -292,5 +293,6 @@ def test_102(): print(a) assert conforms + if __name__ == "__main__": test_102() diff --git a/test/issues/test_008.py b/test/issues/test_008.py index 9865f63..2773cd3 100644 --- a/test/issues/test_008.py +++ b/test/issues/test_008.py @@ -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 - diff --git a/test/issues/test_009.py b/test/issues/test_009.py index c6663bf..6e7de03 100644 --- a/test/issues/test_009.py +++ b/test/issues/test_009.py @@ -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 - diff --git a/test/issues/test_012.py b/test/issues/test_012.py index cbf3dcd..4b596be 100644 --- a/test/issues/test_012.py +++ b/test/issues/test_012.py @@ -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() diff --git a/test/issues/test_014.py b/test/issues/test_014.py index 23bdedd..34fa66f 100644 --- a/test/issues/test_014.py +++ b/test/issues/test_014.py @@ -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() diff --git a/test/issues/test_026.py b/test/issues/test_026.py index 0162677..48499fc 100644 --- a/test/issues/test_026.py +++ b/test/issues/test_026.py @@ -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 diff --git a/test/issues/test_029/__init__.py b/test/issues/test_029/__init__.py index f89ece5..5cfc3c2 100644 --- a/test/issues/test_029/__init__.py +++ b/test/issues/test_029/__init__.py @@ -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() - diff --git a/test/issues/test_036.py b/test/issues/test_036.py index 744a3fd..c23eea3 100644 --- a/test/issues/test_036.py +++ b/test/issues/test_036.py @@ -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 diff --git a/test/issues/test_038.py b/test/issues/test_038.py index e213ddd..c1f717b 100644 --- a/test/issues/test_038.py +++ b/test/issues/test_038.py @@ -9,7 +9,8 @@ from pyshacl import validate shapes = Graph() -shapes.parse(data=""" +shapes.parse( + data=""" @prefix sh: . @prefix owl: . @prefix ex: . @@ -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: . ex:Bob a ex:Person ; . -""",format="ttl") - +""", + format="ttl", +) def test_038(): diff --git a/test/issues/test_058.py b/test/issues/test_058.py index 9359d25..229e748 100644 --- a/test/issues/test_058.py +++ b/test/issues/test_058.py @@ -26,13 +26,14 @@ """ - 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 @@ -40,6 +41,5 @@ def test_058(): assert "ignoredProperties" in str(exc) - if __name__ == "__main__": test_058() diff --git a/test/issues/test_062.py b/test/issues/test_062.py index 8b7883a..ed7e394 100644 --- a/test/issues/test_062.py +++ b/test/issues/test_062.py @@ -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() diff --git a/test/issues/test_079.py b/test/issues/test_079.py index 908e3a3..9367398 100644 --- a/test/issues/test_079.py +++ b/test/issues/test_079.py @@ -5,6 +5,7 @@ """ import rdflib import pyshacl + shapes_data = """\ @prefix ex: . @prefix sh: . @@ -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: . 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 diff --git a/test/issues/test_087.py b/test/issues/test_087.py index 56243db..5bd6e87 100644 --- a/test/issues/test_087.py +++ b/test/issues/test_087.py @@ -52,8 +52,8 @@ :prop :s3 . """ + def test_087(): res1 = validate(mixed_file_text, data_graph_format='turtle', shacl_graph_format='turtle', debug=True) conforms, graph, string = res1 assert conforms - diff --git a/test/issues/test_108.py b/test/issues/test_108.py index 94d1a63..560dfc7 100644 --- a/test/issues/test_108.py +++ b/test/issues/test_108.py @@ -30,6 +30,7 @@ sh:select "SELECT (xsd:string($arg) AS ?result) WHERE { }" . """ + def test_108(): res = validate(shacl_file_text, advanced=True, js=True) conforms, graph, string = res diff --git a/test/issues/test_146.py b/test/issues/test_146.py index d14f630..52dba1d 100644 --- a/test/issues/test_146.py +++ b/test/issues/test_146.py @@ -13,6 +13,7 @@ def test_146() -> None: warnings.simplefilter("always") # Import pyshacl, which should not trigger any warnings import pyshacl + # Verify some things assert len(warning_context) == 0 diff --git a/test/issues/test_170.py b/test/issues/test_170.py index 1d70ad7..563b572 100644 --- a/test/issues/test_170.py +++ b/test/issues/test_170.py @@ -169,6 +169,7 @@ def test_170() -> None: . ''' + def test_170_2() -> None: data_g = rdflib.Graph() data_g.parse(data=data_file, format="turtle") @@ -184,6 +185,7 @@ def test_170_2() -> None: conforms, report, message = validate(data_g, shacl_graph=shapes, ont_graph=ont_2, inference="rdfs", debug=True) assert not conforms + shacl_file_no_sparql_prefixes = '''# baseURI: urn:exShapes @prefix exShapes: . @prefix exOnt: . @@ -214,6 +216,8 @@ def test_170_2() -> None: ] ; . ''' + + def test_170_3() -> None: # The vcard prefix does not exist in the DataFile, only in the Ontology file. # It is defacto behaviour that PySHACL now copies any unknown prefixes from the ontology file into the data file. @@ -230,6 +234,7 @@ def test_170_3() -> None: conforms, report, message = validate(data_g, shacl_graph=shapes, ont_graph=ont_2, inference="rdfs", debug=True) assert not conforms + if __name__ == "__main__": test_170() test_170_2() diff --git a/test/issues/test_199.py b/test/issues/test_199.py index e26df34..fbc56c2 100644 --- a/test/issues/test_199.py +++ b/test/issues/test_199.py @@ -46,20 +46,25 @@ def test_199(): shape_g = rdflib.Graph().parse(data=shapes_data, format='turtle') - data_g = rdflib.Graph().parse(data=""" + data_g = rdflib.Graph().parse( + data=""" @prefix ex: . @prefix sh: . ex:A a ex:TestClass1 . ex:B a ex:TestClass2 . ex:C a ex:TestClass3 . - """, 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 - assert len(list(results_graph[:SH.result])) == 3 + assert len(list(results_graph[: SH.result])) == 3 if __name__ == "__main__": diff --git a/test/issues/test_213.py b/test/issues/test_213.py index 89a2696..eb91e11 100644 --- a/test/issues/test_213.py +++ b/test/issues/test_213.py @@ -51,7 +51,10 @@ def test_213(): shape_g = rdflib.Graph().parse(data=shapes_data, format='turtle') data_g = rdflib.Graph().parse(data=data_g_text, format="turtle") conforms, results_graph, results_text = pyshacl.validate( - data_g, shacl_graph=shape_g, debug=True, meta_shacl=False, + data_g, + shacl_graph=shape_g, + debug=True, + meta_shacl=False, ) assert not conforms assert "QualifiedValueShapeConstraintComponent" in results_text diff --git a/test/issues/test_96.py b/test/issues/test_96.py index 4ed2c20..8d4232a 100644 --- a/test/issues/test_96.py +++ b/test/issues/test_96.py @@ -40,6 +40,7 @@ :prop "fail" . """ + def test_96(): res1 = validate(mixed_file_text, data_graph_format='turtle', shacl_graph_format='turtle', debug=True) conforms, _, _ = res1 diff --git a/test/issues/test_w3_list1.py b/test/issues/test_w3_list1.py index 16c2425..03f62df 100644 --- a/test/issues/test_w3_list1.py +++ b/test/issues/test_w3_list1.py @@ -5,6 +5,7 @@ """ import rdflib import pyshacl + shapes_data = """\ @prefix ex: . @prefix sh: . @@ -58,7 +59,9 @@ def test_w3_list1(): data_g = rdflib.Graph().parse(data=target_data, format='turtle') conforms, results_graph, results_text = pyshacl.validate( - data_g, shacl_graph=shape_g, debug=False, + data_g, + shacl_graph=shape_g, + debug=False, ) print(results_text) assert conforms diff --git a/test/test_advanced.py b/test/test_advanced.py index 56bf6b7..43253c2 100644 --- a/test/test_advanced.py +++ b/test/test_advanced.py @@ -131,6 +131,7 @@ . ''' + def test_advanced(): d = Graph().parse(data=data_graph, format="turtle") s = Graph().parse(data=shacl_file, format="turtle") @@ -138,5 +139,6 @@ def test_advanced(): print(message) assert not conforms + if __name__ == "__main__": exit(test_advanced()) diff --git a/test/test_dash_validate.py b/test/test_dash_validate.py index b61730e..4c45b20 100644 --- a/test/test_dash_validate.py +++ b/test/test_dash_validate.py @@ -40,7 +40,8 @@ def test_dash_validate_all_core(target_file, shacl_file): rdflib.NORMALIZE_LITERALS = False try: val, _, v_text = pyshacl.validate( - target_file, shacl_graph=shacl_file, inference='rdfs', check_dash_result=True, debug=True, meta_shacl=False) + target_file, shacl_graph=shacl_file, inference='rdfs', check_dash_result=True, debug=True, meta_shacl=False + ) except (NotImplementedError, ReportableRuntimeError) as e: print(e) val = False @@ -60,7 +61,14 @@ def test_dash_validate_all_core_sparql_mode(target_file, shacl_file): # shacl_file cannot be None in SPARQL Remote Graph Mode shacl_file = target_file val, _, v_text = pyshacl.validate( - target_file, shacl_graph=shacl_file, inference='none', check_dash_result=True, debug=True, sparql_mode=True, meta_shacl=False) + target_file, + shacl_graph=shacl_file, + inference='none', + check_dash_result=True, + debug=True, + sparql_mode=True, + meta_shacl=False, + ) except (NotImplementedError, ReportableRuntimeError) as e: print(e) val = False @@ -73,6 +81,7 @@ def test_dash_validate_all_core_sparql_mode(target_file, shacl_file): for y in glob.glob(path.join(x[0], '*.test.ttl')): dash_sparql_files.append((y, None)) + @pytest.mark.parametrize('target_file, shacl_file', dash_sparql_files) def test_dash_validate_all_sparql(target_file, shacl_file): # Literals in the data graph should be exactly the same as literals in the shapes graph @@ -81,7 +90,8 @@ def test_dash_validate_all_sparql(target_file, shacl_file): rdflib.NORMALIZE_LITERALS = False try: val, _, v_text = pyshacl.validate( - target_file, shacl_graph=shacl_file, inference='rdfs', check_dash_result=True, debug=True, meta_shacl=False) + target_file, shacl_graph=shacl_file, inference='rdfs', check_dash_result=True, debug=True, meta_shacl=False + ) except (NotImplementedError, ReportableRuntimeError) as e: print(e) val = False @@ -89,6 +99,7 @@ def test_dash_validate_all_sparql(target_file, shacl_file): assert val print(v_text) + @pytest.mark.parametrize('target_file, shacl_file', dash_sparql_files) def test_dash_validate_all_sparql_sparql_mode(target_file, shacl_file): # Literals in the data graph should be exactly the same as literals in the shapes graph @@ -100,7 +111,14 @@ def test_dash_validate_all_sparql_sparql_mode(target_file, shacl_file): # shacl_file cannot be None in SPARQL Remote Graph Mode shacl_file = target_file val, _, v_text = pyshacl.validate( - target_file, shacl_graph=shacl_file, inference='none', check_dash_result=True, debug=True, sparql_mode=True, meta_shacl=False) + target_file, + shacl_graph=shacl_file, + inference='none', + check_dash_result=True, + debug=True, + sparql_mode=True, + meta_shacl=False, + ) except (NotImplementedError, ReportableRuntimeError) as e: print(e) val = False @@ -108,6 +126,7 @@ def test_dash_validate_all_sparql_sparql_mode(target_file, shacl_file): assert val print(v_text) + # Tests for SHACL Advanced Features: https://www.w3.org/TR/shacl-af # Skip these, because sh:target is not part of the SPARQL core spec and support is not implemented @@ -131,13 +150,23 @@ def test_dash_validate_all_sparql_sparql_mode(target_file, shacl_file): for x in walk(path.join(dash_files_dir, 'rules', 'sparql')): for y in glob.glob(path.join(x[0], '*.test.ttl')): dash_sparql_rules_files.append((y, None)) + + @pytest.mark.parametrize('target_file, shacl_file', dash_sparql_rules_files) def test_dash_validate_all_sparql_rules(target_file, shacl_file): try: val, _, v_text = pyshacl.validate( - target_file, shacl_graph=shacl_file, advanced=True, inference='rdfs', check_dash_result=True, debug=True, meta_shacl=False) + target_file, + shacl_graph=shacl_file, + advanced=True, + inference='rdfs', + check_dash_result=True, + debug=True, + meta_shacl=False, + ) except (NotImplementedError, ReportableRuntimeError) as e: import traceback + print(e) traceback.print_tb(e.__traceback__) val = False @@ -150,12 +179,21 @@ def test_dash_validate_all_sparql_rules(target_file, shacl_file): for x in walk(path.join(dash_files_dir, 'rules', 'triple')): for y in glob.glob(path.join(x[0], '*.test.ttl')): dash_triple_rules_files.append((y, None)) + + @pytest.mark.parametrize('target_file, shacl_file', dash_triple_rules_files) def test_dash_validate_all_triple_rules(target_file, shacl_file): test_name = shacl_file or target_file try: val, _, v_text = pyshacl.validate( - target_file, shacl_graph=shacl_file, advanced=True, inference='rdfs', check_dash_result=True, debug=True, meta_shacl=False) + target_file, + shacl_graph=shacl_file, + advanced=True, + inference='rdfs', + check_dash_result=True, + debug=True, + meta_shacl=False, + ) except NotImplementedError as ne: for ani in ALLOWABLE_NOT_IMPLEMENTED: if test_name.endswith(ani): @@ -169,6 +207,7 @@ def test_dash_validate_all_triple_rules(target_file, shacl_file): v_text = "" except ReportableRuntimeError as e: import traceback + print(e) traceback.print_tb(e.__traceback__) val = False @@ -191,12 +230,21 @@ def test_dash_validate_all_triple_rules(target_file, shacl_file): for x in walk(path.join(dash_files_dir, 'target')): for y in glob.glob(path.join(x[0], '*.test.ttl')): dash_target_files.append((y, None)) + + @pytest.mark.parametrize('target_file, shacl_file', dash_target_files) def test_dash_validate_target(target_file, shacl_file): test_name = shacl_file or target_file try: val, _, v_text = pyshacl.validate( - target_file, shacl_graph=shacl_file, advanced=True, inference='rdfs', check_dash_result=True, debug=True, meta_shacl=False) + target_file, + shacl_graph=shacl_file, + advanced=True, + inference='rdfs', + check_dash_result=True, + debug=True, + meta_shacl=False, + ) except NotImplementedError as ne: for ani in ALLOWABLE_NOT_IMPLEMENTED: if test_name.endswith(ani): @@ -210,6 +258,7 @@ def test_dash_validate_target(target_file, shacl_file): v_text = "" except ReportableRuntimeError as e: import traceback + print(e) traceback.print_tb(e.__traceback__) val = False @@ -236,7 +285,15 @@ def test_dash_validate_target_sparql_mode(target_file, shacl_file): # shacl_file cannot be None in SPARQL Remote Graph Mode shacl_file = target_file val, _, v_text = pyshacl.validate( - target_file, shacl_graph=shacl_file, advanced=True, inference='none', check_dash_result=True, debug=True, sparql_mode=True, meta_shacl=False) + target_file, + shacl_graph=shacl_file, + advanced=True, + inference='none', + check_dash_result=True, + debug=True, + sparql_mode=True, + meta_shacl=False, + ) except NotImplementedError as ne: for ani in ALLOWABLE_NOT_IMPLEMENTED: if test_name.endswith(ani): @@ -250,6 +307,7 @@ def test_dash_validate_target_sparql_mode(target_file, shacl_file): v_text = "" except ReportableRuntimeError as e: import traceback + print(e) traceback.print_tb(e.__traceback__) val = False @@ -267,16 +325,26 @@ def test_dash_validate_target_sparql_mode(target_file, shacl_file): print(v_text) + # Get all SHACL-AF sh:expression tests. for x in walk(path.join(dash_files_dir, 'expression')): for y in glob.glob(path.join(x[0], '*.test.ttl')): dash_expression_files.append((y, None)) + + @pytest.mark.parametrize('target_file, shacl_file', dash_expression_files) def test_dash_validate_expression(target_file, shacl_file): test_name = shacl_file or target_file try: val, _, v_text = pyshacl.validate( - target_file, shacl_graph=shacl_file, advanced=True, inference='rdfs', check_dash_result=True, debug=True, meta_shacl=False) + target_file, + shacl_graph=shacl_file, + advanced=True, + inference='rdfs', + check_dash_result=True, + debug=True, + meta_shacl=False, + ) except NotImplementedError as ne: for ani in ALLOWABLE_NOT_IMPLEMENTED: if test_name.endswith(ani): @@ -290,6 +358,7 @@ def test_dash_validate_expression(target_file, shacl_file): v_text = "" except ReportableRuntimeError as e: import traceback + print(e) traceback.print_tb(e.__traceback__) val = False @@ -307,16 +376,26 @@ def test_dash_validate_expression(target_file, shacl_file): print(v_text) + # Get all SHACLFunction tests for x in walk(path.join(dash_files_dir, 'function')): for y in glob.glob(path.join(x[0], '*.test.ttl')): dash_fn_files.append((y, None)) + + @pytest.mark.parametrize('target_file, shacl_file', dash_fn_files) def test_dash_validate_functions(target_file, shacl_file): test_name = shacl_file or target_file try: val, _, v_text = pyshacl.validate( - target_file, shacl_graph=shacl_file, advanced=True, inference='rdfs', check_dash_result=True, debug=True, meta_shacl=False) + target_file, + shacl_graph=shacl_file, + advanced=True, + inference='rdfs', + check_dash_result=True, + debug=True, + meta_shacl=False, + ) except NotImplementedError as ne: for ani in ALLOWABLE_NOT_IMPLEMENTED: if test_name.endswith(ani): @@ -330,6 +409,7 @@ def test_dash_validate_functions(target_file, shacl_file): v_text = "" except ReportableRuntimeError as e: import traceback + print(e) traceback.print_tb(e.__traceback__) val = False diff --git a/test/test_js/conftest.py b/test/test_js/conftest.py index 71821c6..dea9a8a 100644 --- a/test/test_js/conftest.py +++ b/test/test_js/conftest.py @@ -5,5 +5,6 @@ def pytest_runtest_setup(item): extras.dev_mode = True + def pytest_runtest_teardown(item, call=None): extras.dev_mode = False diff --git a/test/test_js/test_js_constraint.py b/test/test_js/test_js_constraint.py index 21db4b1..37c2585 100644 --- a/test/test_js/test_js_constraint.py +++ b/test/test_js/test_js_constraint.py @@ -1,5 +1,6 @@ from rdflib import Graph from pyshacl import validate, extras + shapes_graph = '''\ @prefix rdf: . @prefix rdfs: . @@ -33,11 +34,13 @@ extras.dev_mode = True + def test_js_constraint(): s1 = Graph().parse(data=shapes_graph, format="turtle") g1 = Graph().parse(data=data_graph, format="turtle") conforms, result_graph, result_text = validate(g1, shacl_graph=s1, advanced=True, debug=True, js=True) assert not conforms + if __name__ == "__main__": test_js_constraint() diff --git a/test/test_js/test_js_constraint_component.py b/test/test_js/test_js_constraint_component.py index b1a8877..a0c455b 100644 --- a/test/test_js/test_js_constraint_component.py +++ b/test/test_js/test_js_constraint_component.py @@ -1,5 +1,6 @@ from rdflib import Graph from pyshacl import validate + shapes_graph = '''\ @prefix rdf: . @prefix rdfs: . @@ -52,11 +53,13 @@ ex:postcode "1234" . ''' + def test_js_constraint_component(): s1 = Graph().parse(data=shapes_graph, format="turtle") g1 = Graph().parse(data=data_graph, format="turtle") conforms, result_graph, result_text = validate(g1, shacl_graph=s1, advanced=True, debug=True, js=True) assert not conforms + if __name__ == "__main__": test_js_constraint_component() diff --git a/test/test_js/test_js_constraint_path_component.py b/test/test_js/test_js_constraint_path_component.py index 20006a6..c404f0c 100644 --- a/test/test_js/test_js_constraint_path_component.py +++ b/test/test_js/test_js_constraint_path_component.py @@ -1,5 +1,6 @@ from rdflib import Graph from pyshacl import validate + shapes_graph = '''\ @prefix rdf: . @prefix rdfs: . @@ -50,11 +51,13 @@ ex:parent ex:Parent2 . ''' + def test_js_constraint_path_component(): s1 = Graph().parse(data=shapes_graph, format="turtle") g1 = Graph().parse(data=data_graph, format="turtle") conforms, result_graph, result_text = validate(g1, shacl_graph=s1, advanced=True, debug=True, js=True) assert not conforms + if __name__ == "__main__": test_js_constraint_path_component() diff --git a/test/test_js/test_js_function.py b/test/test_js/test_js_function.py index 0f88d38..5df9dc8 100644 --- a/test/test_js/test_js_function.py +++ b/test/test_js/test_js_function.py @@ -1,5 +1,6 @@ from rdflib import Graph from pyshacl import validate + shapes_graph = '''\ @prefix rdf: . @prefix rdfs: . @@ -96,11 +97,13 @@ ''' + def test_js_function(): s1 = Graph().parse(data=shapes_graph, format="turtle") g1 = Graph().parse(data=data_graph, format="turtle") conforms, result_graph, result_text = validate(g1, shacl_graph=s1, advanced=True, debug=True, js=True) assert not conforms + if __name__ == "__main__": test_js_function() diff --git a/test/test_js/test_js_rules.py b/test/test_js/test_js_rules.py index 4f73f5c..3192ca2 100644 --- a/test/test_js/test_js_rules.py +++ b/test/test_js/test_js_rules.py @@ -1,5 +1,6 @@ from rdflib import Graph from pyshacl import validate + shapes_graph = '''\ @prefix rdf: . @prefix rdfs: . @@ -36,11 +37,13 @@ ex:height 8 . ''' + def test_js_rules(): s1 = Graph().parse(data=shapes_graph, format="turtle") g1 = Graph().parse(data=data_graph, format="turtle") conforms, result_graph, result_text = validate(g1, shacl_graph=s1, advanced=True, debug=True, js=True) assert not conforms + if __name__ == "__main__": test_js_rules() diff --git a/test/test_js/test_js_target.py b/test/test_js/test_js_target.py index 5e79fb7..1ce92d2 100644 --- a/test/test_js/test_js_target.py +++ b/test/test_js/test_js_target.py @@ -1,5 +1,6 @@ from rdflib import Graph from pyshacl import validate + shapes_graph = '''\ @prefix dash: . @prefix ex: . @@ -70,11 +71,13 @@ ''' + def test_js_target(): s1 = Graph().parse(data=shapes_graph, format="turtle") g1 = Graph().parse(data=data_graph, format="turtle") conforms, result_graph, result_text = validate(g1, shacl_graph=s1, advanced=True, debug=True, js=True) assert not conforms + if __name__ == "__main__": test_js_target() diff --git a/test/test_js/test_js_target_type.py b/test/test_js/test_js_target_type.py index 416f435..fc98c43 100644 --- a/test/test_js/test_js_target_type.py +++ b/test/test_js/test_js_target_type.py @@ -1,5 +1,6 @@ from rdflib import Graph from pyshacl import validate + shapes_graph = '''\ @prefix dash: . @prefix ex: . @@ -111,11 +112,13 @@ ''' + def test_js_target_type(): s1 = Graph().parse(data=shapes_graph, format="turtle") g1 = Graph().parse(data=data_graph, format="turtle") conforms, result_graph, result_text = validate(g1, shacl_graph=s1, advanced=True, debug=True, js=True) assert not conforms + if __name__ == "__main__": test_js_target_type() diff --git a/test/test_schema_org.py b/test/test_schema_org.py index a408632..de52312 100644 --- a/test/test_schema_org.py +++ b/test/test_schema_org.py @@ -35,16 +35,26 @@ def schema_org(): dataGraph = rdflib.Graph().parse(data=data, format='ttl') - #print(dataGraph.serialize(format='ttl').decode('utf8')) + # print(dataGraph.serialize(format='ttl').decode('utf8')) shaclDS = rdflib.Dataset() shaclGraph = shaclDS.default_context shaclDS.graph(shaclGraph) shaclGraph.parse(data=shacl, format='ttl') - report = validate(dataGraph, shacl_graph=shaclDS, abort_on_first=False, inference='both', meta_shacl=False, debug=False, advanced=True, do_owl_imports=True) + report = validate( + dataGraph, + shacl_graph=shaclDS, + abort_on_first=False, + inference='both', + meta_shacl=False, + debug=False, + advanced=True, + do_owl_imports=True, + ) print(report[2]) + if __name__ == "__main__": schema_org()