def test_bad_graphs(): dg = "not a graph" pg = Graph().parse(data=PROFILES_RDF, format="turtle") with pytest.raises(AssertionError): c = Cheka(data_graph_obj=dg, profiles_graph_obj=pg) # fail on an empty graph with pytest.raises(AssertionError): dg = Graph() c = Cheka(data_graph_obj=dg, profiles_graph_obj=pg)
def test_combine_validators(data_rdf, profiles_rdf): c = Cheka(data_graph_ttl=data_rdf, profiles_graph_ttl=profiles_rdf) c._get_artifact_uris() c._dereference_artifact_uris() c._make_shapes_graph() assert (len(c.sg) == 60)
def test_strategies(): # invalid strategy with pytest.raises(ValueError): c = Cheka( data_graph_file_path=join(dirname(__file__), "test_01_d.ttl"), profiles_graph_file_path=join(dirname(__file__), "test_01_p.ttl"), ).validate(strategy="other")
def test_profile_artifact_uris(data_rdf, profiles_rdf): expected = _get_artifact_uris_for_profile( Graph().parse(data=profiles_rdf, format="turtle"), profile_uri="http://example.org/profile/Profile_C") c = Cheka(data_graph_ttl=data_rdf, profiles_graph_ttl=profiles_rdf) c._get_artifact_uris(profile_uri="http://example.org/profile/Profile_C") assert set(c.artifact_uris) == set(expected), \ "Expected:\n<{}>\nbut got:\n<{}>".format(">, <".join(expected), ">, <".join(c.artifact_uris))
def test_all_artifact_uris(data_rdf, profiles_rdf): expected = _get_all_artifact_uris_sparql(Graph().parse(data=profiles_rdf, format="turtle")) c = Cheka(data_graph_ttl=data_rdf, profiles_graph_ttl=profiles_rdf) c._get_artifact_uris() assert set(c.artifact_uris) == set(expected), \ "Expected:\n<{}>\nbut got:\n<{}>".format(">, <".join(expected), ">, <".join(c.artifact_uris))
def test_artifact_dereferencing(data_rdf, profiles_rdf): c = Cheka(data_graph_ttl=data_rdf, profiles_graph_ttl=profiles_rdf) c._get_artifact_uris() c._dereference_artifact_uris() for uri in c.artifact_uris: file_name = uri.replace("file://", "").replace(Cheka.VALIDATORS_DIR, "").split("/")[-1] file_path = join(Cheka.VALIDATORS_DIR, file_name) assert isfile(file_path)
def test_shacl_fail(data_rdf, profiles_rdf): c = Cheka(data_graph_ttl=data_rdf, profiles_graph_ttl=profiles_rdf) x = c.validate() assert "A void:Dataset must have a dcterms:created property indicating an xsd:date or xsd:dateTime" in x[2] assert x[3] is None
def test_bad_paths(): with pytest.raises(FileNotFoundError): c = Cheka(data_graph_file_path="BORKED", profiles_graph_file_path=join(dirname(__file__), "test_01_p.ttl"))
def test_good_paths(): c = Cheka(data_graph_file_path=join(dirname(__file__), "test_01_d.ttl"), profiles_graph_file_path=join(dirname(__file__), "test_01_p.ttl"))
def test_validate_simple(): # should be true since the dataset has a title (<A>) and a creator (<B>) t1 = c.validate(profile_uri='http://example.org/profile/Profile_B') print(t1) assert t1[0], t1[2] # should be false since the dataset does not have a created date (<C>) t2 = c.validate(profile_uri='http://example.org/profile/Profile_C') assert not t2[0], t2[2] # should be false since the dataset claims conformance with <C> but has no created date t3 = c.validate() assert not t3[0], t3[2] if __name__ == "__main__": import logging logging.basicConfig(level=logging.INFO) c = Cheka('test_01_d.ttl', 'test_01_p.ttl') c.get_remote_profiles = True # print(c._get_profiles_hierarchy("http://example.org/profile/Profile_C")) import pprint # pprint.pprint(c.validate()) pprint.pprint( c.validate(strategy="profile", profile_uri="http://example.org/profile/Profile_C")) # c.clear_cache()
def test_strategies(): # invalid strategy with pytest.raises(ValueError): c = Cheka(join(dirname(__file__), "test_01_d.ttl"), join(dirname(__file__), "test_01_p.ttl")).validate(strategy="other")
def test_bad_paths(): with pytest.raises(ValueError): c = Cheka("BORKED", join(dirname(__file__), "test_01_p.ttl"))
def test_good_paths(): c = Cheka(join(dirname(__file__), "test_01_d.ttl"), join(dirname(__file__), "test_01_p.ttl"))
def test_bad_strings(): with pytest.raises(ValueError): c = Cheka("blah", PROFILES_RDF)
def test_good_strings(): c = Cheka(DATA_RDF, PROFILES_RDF)
def test_shacl_pass(data_rdf2, profiles_rdf): c = Cheka(data_graph_ttl=data_rdf2, profiles_graph_ttl=profiles_rdf) x = c.validate() assert x[0] # i.e. valid
def test_good_strings(): c = Cheka(data_graph_ttl=DATA_RDF, profiles_graph_ttl=PROFILES_RDF)
def test_bad_strings(): with pytest.raises(ValueError): c = Cheka(data_graph_ttl="blah", profiles_graph_ttl=PROFILES_RDF)
'extract validating Profile Resources.', type=lambda x: is_valid_file(parser, x), required=True) parser.add_argument( '-i', '--instance-uri', help= 'The specific profile URI that you wish to validate the data graph against. This need not be set, in which' 'case, Cheka will look for conformance claims (dct:conformsTo) in the data graph.', type=str) parser.add_argument( '-u', '--profile-uri', help= 'The specific profile URI that you wish to validate the data graph against. This need not be set, in which' 'case, Cheka will look for conformance claims (dct:conformsTo) in the data graph.', type=str) args = parser.parse_args() # do stuff c = Cheka(args.data.name, args.profiles.name) v = c.validate(profile_uri=args.uri) if v[0]: pprint.pprint('valid') else: pprint.pprint('invalid') pprint.pprint(v[2])
def test_good_graphs(): dg = Graph().parse(data=DATA_RDF, format="turtle") pg = Graph().parse(data=PROFILES_RDF, format="turtle") c = Cheka(data_graph_obj=dg, profiles_graph_obj=pg)
def setup(): global c c = Cheka('test_02_d.ttl', 'test_01_p.ttl')
def setup(): global c g = Graph() c = Cheka(data_graph_ttl="x", profiles_graph_obj=g)