コード例 #1
0
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))
コード例 #2
0
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))
コード例 #3
0
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)
コード例 #4
0
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)
コード例 #5
0
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")
コード例 #6
0
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)
コード例 #7
0
def test_good_strings():
    c = Cheka(data_graph_ttl=DATA_RDF, profiles_graph_ttl=PROFILES_RDF)
コード例 #8
0
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
コード例 #9
0
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
コード例 #10
0
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"))
コード例 #11
0
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"))
コード例 #12
0
ファイル: cli.py プロジェクト: datadavev/cheka
    validation_type.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
    )

    validation_type.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
    )

    validation_type.add_argument(
        '-r', '--get-remotes',
        help='If set, tells Cheka to try and look up profile information, e.g. validators, via the profile\'s URI.',
        type=str
    )

    args = parser.parse_args()

    c = Cheka(args.data.name, args.profiles.name)
    v = c.validate(profile_uri=args.uri)  # TODO: read from any of the validation_type values
    if v[0]:
        pprint.pprint('valid')
    else:
        pprint.pprint('invalid')
        pprint.pprint(v[2])
コード例 #13
0
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)
コード例 #14
0

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()
コード例 #15
0
def test_good_strings():
    c = Cheka(DATA_RDF, PROFILES_RDF)
コード例 #16
0
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")
コード例 #17
0
def test_bad_paths():
    with pytest.raises(ValueError):
        c = Cheka("BORKED", join(dirname(__file__), "test_01_p.ttl"))
コード例 #18
0
def test_good_paths():
    c = Cheka(join(dirname(__file__), "test_01_d.ttl"),
              join(dirname(__file__), "test_01_p.ttl"))
コード例 #19
0
def test_bad_strings():
    with pytest.raises(ValueError):
        c = Cheka("blah", PROFILES_RDF)
コード例 #20
0
ファイル: cli.py プロジェクト: andrewmackie/cheka
        '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])
コード例 #21
0
def test_bad_strings():
    with pytest.raises(ValueError):
        c = Cheka(data_graph_ttl="blah", profiles_graph_ttl=PROFILES_RDF)
コード例 #22
0
def setup():
    global c
    c = Cheka('test_02_d.ttl', 'test_01_p.ttl')
コード例 #23
0
ファイル: test_shacl_normal.py プロジェクト: Simo-climb/cheka
def setup():
    global c
    g = Graph()
    c = Cheka(data_graph_ttl="x", profiles_graph_obj=g)