def test_update_no_defined_by(capsys):
    onto_tool.main(['update', 'tests/issue-36-defined-by.ttl'])
    updated = capsys.readouterr().out
    graph = Graph()
    graph.parse(data=updated, format="turtle")
    assert len(graph) == 5
    assert len(list(graph.subject_objects(RDFS.isDefinedBy))) == 0
Esempio n. 2
0
def test_sparql_updates():
    onto_tool.main([
        '-k', 'bundle', '-v', 'output', 'tests-output/bundle/endpoint_sparql',
        'tests/bundle/sparql_update.yaml'
    ])

    with open('tests-output/bundle/endpoint_sparql/sparql_update_select.csv'
              ) as csvfile:
        actual = list(row for row in csv.DictReader(csvfile))
    expected = [
        {
            'person': 'http://example.com/John',
            'name': 'John'
        },
        {
            'person': 'http://example.com/Jane',
            'name': 'Jane'
        },
    ]
    assert actual == expected

    constructed_graph = Graph()
    constructed_graph.parse(
        'tests-output/bundle/endpoint_sparql/sparql_update_construct.xml',
        format='xml')
    labels = list(constructed_graph.subject_objects(SKOS.prefLabel))
    assert lists_equal(
        [(URIRef('http://example.com/John'), Literal('John Johnson')),
         (URIRef('http://example.com/Jane'), Literal('Jane Johnson'))], labels)
Esempio n. 3
0
def test_export_merge(capsys):
    onto_tool.main([
        'export',
        '-m', 'https://data.clientX.com/d/coreOntology', '2.0.0',
        '-b', 'strict',
        'tests/merge-subdomain.ttl', 'tests/merge-top.ttl'
    ])
    updated = capsys.readouterr().out
    graph = Graph()
    graph.parse(data=updated, format="turtle")
    assert lists_equal(
        list(graph.subjects(RDF.type, OWL.Ontology)),
        [URIRef('https://data.clientX.com/d/coreOntology')]
    )
    assert lists_equal(
        list(graph.subject_objects(OWL.imports)),
        [(URIRef('https://data.clientX.com/d/coreOntology'),
          URIRef('https://come.external.com/ontology1.3.0'))]
    )
    assert lists_equal(
        list(graph.subject_objects(OWL.versionIRI)),
        [(URIRef('https://data.clientX.com/d/coreOntology'),
          URIRef('https://data.clientX.com/d/coreOntology2.0.0'))]
    )
    assert lists_equal(
        list(graph.subject_objects(OWL.versionInfo)),
        [(URIRef('https://data.clientX.com/d/coreOntology'),
          Literal('Created by merge tool.', datatype=XSD.string))]
    )
    assert lists_equal(
        list(graph.subject_objects(RDFS.isDefinedBy)),
        [(URIRef('https://data.clientX.com/myProperty'),
          URIRef('https://data.clientX.com/d/coreOntology'))]
    )
Esempio n. 4
0
def test_multi_language():
    onto_tool.main([
        'graphic', '--predicate-threshold', '0', '--data',
        '-t', 'Multi Language Labels',
        '--no-image',
        '-o', 'tests-output/graphic/test_multi_lingual_en',
        'tests/graphic/multi_language.ttl'
    ])
    (instance_graph,) = pydot.graph_from_dot_file('tests-output/graphic/test_multi_lingual_en.dot')
    edges = list(sorted((e.get_source(), e.get_label(), e.get_destination()) for e in instance_graph.get_edges()))
    assert edges == [
        ('"http://example.com/Person"', 'likes', '"http://example.com/Dessert"')
    ]

    onto_tool.main([
        'graphic', '--predicate-threshold', '0', '--data',
        '-t', 'Multi Language Labels',
        '--no-image', '--label-language', 'fr',
        '-o', 'tests-output/graphic/test_multi_lingual_fr',
        'tests/graphic/multi_language.ttl'
    ])
    (instance_graph,) = pydot.graph_from_dot_file('tests-output/graphic/test_multi_lingual_fr.dot')
    edges = list(sorted((e.get_source(), e.get_label(), e.get_destination()) for e in instance_graph.get_edges()))
    assert edges == [
        ('"http://example.com/Person"', 'aime', '"http://example.com/Dessert"')
    ]
def test_debug_log(caplog):
    with caplog.at_level(logging.DEBUG):
        onto_tool.main([
            'bundle', '--debug', 'tests/bundle/logging.yaml'
        ])

    logs = caplog.text
    assert 'Running from tests' in logs
    assert 'DEBUG' in logs
def test_action_message(caplog):
    with caplog.at_level(logging.INFO):
        onto_tool.main([
            'bundle', 'tests/bundle/logging.yaml'
        ])

    logs = caplog.text
    assert 'Running from tests' in logs
    assert 'DEBUG' not in logs
Esempio n. 7
0
def test_verify_construct(caplog):
    onto_tool.main([
                       'graphic', '--data',
                       '-t', 'Local Instance Data',
                       '--no-image',
                       '-o', 'tests-output/graphic/test_instance'
                   ] + glob.glob('tests/graphic/*_ontology.ttl'))
    logs = caplog.text
    assert 'No data found' in logs
def test_missing_file_reported(caplog):
    with TemporaryDirectory() as tempdir:
        onto_tool.main([
            'bundle', '-v', 'output', tempdir, 'tests/bundle/broken_file_ref.yaml'
        ])

    logs = caplog.text
    assert 'missing_data.ttl' in logs
    assert 'missing_with' not in logs
def test_update_strict_defined_by(capsys):
    capsys.readouterr()
    onto_tool.main(['update', '-b', 'strict', 'tests/issue-36-defined-by.ttl'])
    updated = capsys.readouterr().out
    graph = Graph()
    graph.parse(data=updated, format="turtle")
    assert len(graph) == 6
    assert lists_equal(list(graph.subject_objects(RDFS.isDefinedBy)),
                       [(URIRef('https://data.clientX.com/myProperty'),
                         URIRef('https://data.clientX.com/d/ontoName'))])
def test_transform_shell(caplog):
    with caplog.at_level(logging.DEBUG):
        onto_tool.main([
            'bundle', '-v', 'output', 'tests-output/bundle',
            'tests/bundle/transform_shell.yaml'
        ])

    output = caplog.messages
    assert any(
        re.search(r'(java|openjdk) version ', message) for message in output)
def test_action_message(caplog):
    caplog.set_level(logging.INFO)
    onto_tool.main([
        'bundle', '-v', 'output', 'tests-output/bundle',
        'tests/bundle/message.yaml'
    ])

    logs = caplog.text
    print(logs)
    assert search(r'INFO.*Test SPARQL Query from tests', logs)
def test_transform_java():
    onto_tool.main([
        'bundle', '-v', 'output', 'tests-output/bundle', '-v', 'format',
        'rdf-xml', 'tests/bundle/transform_java.yaml'
    ])

    updated_graph = Graph()
    updated_graph.parse('tests-output/bundle/transform_sparql_data.xml',
                        format='xml')
    types = list(updated_graph.subject_objects(RDF.type))
    assert len(types) == 2
Esempio n. 13
0
def test_syntax_export(caplog):
    with raises(SystemExit) as wrapped_exit:
        onto_tool.main([
            'bundle', '-v', 'output', 'tests-output/bundle',
            'tests/bundle/syntax_error.yaml'
        ])
    assert wrapped_exit.type == SystemExit
    assert wrapped_exit.value.code == 1

    logs = caplog.text
    assert re.search(r'Error parsing .*malformed_rdf.ttl at 3', logs)
Esempio n. 14
0
def test_update_dependency(capsys):
    onto_tool.main([
        'update', '-d', 'https://data.clientX.com/d/coreOntology', '2.0.0',
        'tests/update-tests.ttl'
    ])
    updated = capsys.readouterr().out
    graph = Graph()
    graph.parse(data=updated, format="turtle")
    assert lists_equal(
        list(graph.subject_objects(OWL.imports)),
        [(URIRef('https://data.clientX.com/d/ontoName'),
          URIRef('https://data.clientX.com/d/coreOntology2.0.0'))])
Esempio n. 15
0
def test_local_instance():
    onto_tool.main([
        'graphic', '-t', 'Local Ontology', '--no-image', '-o',
        'tests-output/graphic/test_schema',
        'tests/graphic/domain_ontology.ttl',
        'tests/graphic/upper_ontology.ttl', 'tests/graphic/instance_data.ttl'
    ])
    (instance_graph,
     ) = pydot.graph_from_dot_file('tests-output/graphic/test_schema.dot')
    edges = list(
        sorted((e.get_source(), e.get_destination())
               for e in instance_graph.get_edges()))
    assert edges == [('Domain', 'Upper'), ('Instances', 'Domain')]
Esempio n. 16
0
def test_export_strip_versions(capsys):
    onto_tool.main([
        'export', '-s',
        'tests/update-tests.ttl'
    ])
    updated = capsys.readouterr().out
    graph = Graph()
    graph.parse(data=updated, format="turtle")
    assert lists_equal(
        list(graph.subject_objects(OWL.imports)),
        [(URIRef('https://data.clientX.com/d/ontoName'),
          URIRef('https://data.clientX.com/d/coreOntology'))]
    )
Esempio n. 17
0
def test_each_file():
    onto_tool.main([
        'bundle', '-v', 'output', 'tests-output/bundle',
        'tests/bundle/sparql-each.yaml'
    ])

    # Verify CONSTRUCT
    constructed_graph = Graph()
    constructed_graph.parse(
        'tests-output/bundle/each/construct/upper_ontology.ttl',
        format='turtle')
    labels = list(constructed_graph.subject_objects(SKOS.prefLabel))
    assert len(labels) == 5
    constructed_graph = Graph()
    constructed_graph.parse(
        'tests-output/bundle/each/construct/domain_ontology.ttl',
        format='turtle')
    labels = list(constructed_graph.subject_objects(SKOS.prefLabel))
    assert len(labels) == 6

    # Verify SELECT
    with open('tests-output/bundle/each/select/upper_ontology.csv') as csvfile:
        actual = list(row['label'] for row in csv.DictReader(csvfile))
    expected = [
        "Person", "Upper Ontology", "has phone number", "is friend of",
        "is private"
    ]
    assert actual == expected
    with open(
            'tests-output/bundle/each/select/domain_ontology.csv') as csvfile:
        actual = list(row['label'] for row in csv.DictReader(csvfile))
    expected = [
        "Domain Ontology", "School", "Student", "Teacher", "teaches",
        "works for"
    ]
    assert actual == expected

    # Verify UPDATE
    assert actual == expected
    constructed_graph = Graph()
    constructed_graph.parse(
        'tests-output/bundle/each/update/upper_ontology.ttl', format='turtle')
    labels = list(constructed_graph.subject_objects(SKOS.prefLabel))
    assert len(labels) == 5
    assert not list(constructed_graph.subject_objects(RDFS.label))
    constructed_graph = Graph()
    constructed_graph.parse(
        'tests-output/bundle/each/update/domain_ontology.ttl', format='turtle')
    labels = list(constructed_graph.subject_objects(SKOS.prefLabel))
    assert len(labels) == 6
    assert not list(constructed_graph.subject_objects(RDFS.label))
def test_transform_sparql():
    onto_tool.main([
        'bundle', '-v', 'output', 'tests-output/bundle', '-v', 'lang', 'en',
        'tests/bundle/transform_sparql.yaml'
    ])

    updated_graph = Graph()
    updated_graph.parse('tests-output/bundle/transform_sparql_data_en.ttl',
                        format='turtle')
    without_lang = [
        label for label in updated_graph.objects(None, SKOS.prefLabel)
        if label.language != 'en'
    ]
    assert len(without_lang) == 0
Esempio n. 19
0
def test_update_version(capsys):
    onto_tool.main([
        'update', '-v', '2.0.0', '--version-info', "Release 2.0.0",
        'tests/update-tests.ttl'
    ])
    updated = capsys.readouterr().out
    graph = Graph()
    graph.parse(data=updated, format="turtle")
    assert lists_equal(list(graph.subject_objects(OWL.versionIRI)),
                       [(URIRef('https://data.clientX.com/d/ontoName'),
                         URIRef('https://data.clientX.com/d/ontoName2.0.0'))])
    assert lists_equal(list(graph.subject_objects(OWL.versionInfo)),
                       [(URIRef('https://data.clientX.com/d/ontoName'),
                         Literal('Release 2.0.0', datatype=XSD.string))])
Esempio n. 20
0
def test_versioned_defined_by(capsys):
    onto_tool.main([
        'export',
        '-m', 'https://data.clientX.com/d/coreOntology', '2.0.0',
        '-b', 'strict',
        '--versioned-definedBy',
        'tests/merge-subdomain.ttl', 'tests/merge-top.ttl'
    ])
    updated = capsys.readouterr().out
    graph = Graph()
    graph.parse(data=updated, format="turtle")
    assert lists_equal(
        list(graph.subject_objects(RDFS.isDefinedBy)),
        [(URIRef('https://data.clientX.com/myProperty'),
          URIRef('https://data.clientX.com/d/coreOntology2.0.0'))]
    )
Esempio n. 21
0
def test_sparql_queries():
    onto_tool.main([
        'bundle', '-v', 'output', 'tests-output/bundle',
        'tests/bundle/sparql.yaml'
    ])
    with open('tests-output/bundle/sparql.csv') as csvfile:
        actual = list(row for row in csv.DictReader(csvfile))
    expected = [{
        's': 'https://data.clientX.com/d/topOntology',
        'p': 'http://www.w3.org/1999/02/22-rdf-syntax-ns#type',
        'o': 'http://www.w3.org/2002/07/owl#Ontology'
    }, {
        's': 'https://data.clientX.com/d/topOntology',
        'p': 'http://www.w3.org/2000/01/rdf-schema#definedBy',
        'o': 'urn:test-sparql-queries'
    }]
    assert actual == expected
Esempio n. 22
0
def test_local_instance():
    onto_tool.main([
        'graphic', '--predicate-threshold', '0', '--data',
        '-t', 'Local Instance Data',
        '--no-image',
        '-o', 'tests-output/graphic/test_instance',
        'tests/graphic/domain_ontology.ttl',
        'tests/graphic/upper_ontology.ttl',
        'tests/graphic/instance_data.ttl'
    ])
    (instance_graph,) = pydot.graph_from_dot_file('tests-output/graphic/test_instance.dot')
    edges = list(sorted((e.get_source(), e.get_destination()) for e in instance_graph.get_edges()))
    assert edges == [
        ('"http://example.com/Student"', '"http://example.com/Person"'),
        ('"http://example.com/Teacher"', '"http://example.com/School"'),
        ('"http://example.com/Teacher"', '"http://example.com/Student"')
    ]
Esempio n. 23
0
def test_inheritance():
    onto_tool.main([
                       'graphic', '--predicate-threshold', '0', '--data',
                       '-t', 'Inheritance is Difficult',
                       '--no-image',
                       '-o', 'tests-output/graphic/test_inheritance',
                       'tests/graphic/inheritance_hierarchy.ttl'
                   ])
    (instance_graph,) = pydot.graph_from_dot_file('tests-output/graphic/test_inheritance.dot')
    edges = list(sorted((e.get_source(), e.get_label() or '', e.get_destination()) for e in instance_graph.get_edges()))
    assert edges == [
        ('"http://example.org/Person"', 'memberOf', '"http://example.org/Organization"'),
        ('"http://example.org/Professor"', '', '"http://example.org/Person"'),
        ('"http://example.org/Professor"', 'memberOf', '"http://example.org/SocialClub"'),
        ('"http://example.org/Professor"', 'residesAt', '"http://example.org/SingleFamilyHome"'),
        ('"http://example.org/Student"', '', '"http://example.org/Person"'),
        ('"http://example.org/Student"', 'memberOf', '"http://example.org/Fraternity"'),
        ('"http://example.org/Student"', 'residesAt', '"http://example.org/Apartment"')
    ]
    assert 'age' in instance_graph.get_node('"http://example.org/Person"')[0].get_label()
    assert 'age' not in instance_graph.get_node('"http://example.org/Student"')[0].get_label()
Esempio n. 24
0
def test_concentration():
    # First, with concentration
    onto_tool.main([
        'graphic', '--predicate-threshold', '0', '--data',
        '--debug',
        '-t', 'Looney Tunes',
        '--no-image',
        '-o', 'tests-output/graphic/concentration',
        'tests/graphic/concentration.ttl'
    ])
    (instance_graph,) = pydot.graph_from_dot_file('tests-output/graphic/concentration.dot')
    assert 1 == sum(1 for e in instance_graph.get_edges() if e.get_label() == 'playsWith')

    # Then, without
    onto_tool.main([
        'graphic', '--predicate-threshold', '0', '--data',
        '-t', 'Looney Tunes',
        '--no-image',
        '--link-concentrator-threshold', '0',
        '-o', 'tests-output/graphic/concentration',
        'tests/graphic/concentration.ttl'
    ])
    (instance_graph,) = pydot.graph_from_dot_file('tests-output/graphic/concentration.dot')
    assert 4 == sum(1 for e in instance_graph.get_edges() if e.get_label() == 'playsWith')