Skip to content

Commit

Permalink
improves
Browse files Browse the repository at this point in the history
  • Loading branch information
WolfgangFahl committed Oct 31, 2024
1 parent 429c1ac commit 3a6ff00
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 1 deletion.
3 changes: 3 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ maintainers = [
readme = "README.md"
license= "Apache-2.0"
dependencies = [
# https://pypi.org/project/rdflib/
"rdflib>=7.1.0",
# https://pypi.org/project/SPARQLWrapper/
"SPARQLWrapper>=2.0.0",
#"SPARQLWrapper==1.8.5",
# https://pypi.org/project/ratelimit/
Expand Down
29 changes: 28 additions & 1 deletion tests/test_linkml.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
"""

from rdflib.namespace import XSD
from rdflib import Graph
from rdflib.plugins.sparql import prepareQuery

from lodstorage.linkml_gen import LinkMLGen, Schema
from lodstorage.rdf import RDFDumper
Expand All @@ -17,7 +19,7 @@ class TestLinkMLConversion(Basetest):
Test class for generating LinkML YAML schema from Python data models.
"""

def setUp(self, debug=False, profile=True):
def setUp(self, debug=True, profile=True):
super().setUp(debug=debug, profile=profile)
# Retrieve the data model instances
royals_samples = Sample.get("royals")
Expand Down Expand Up @@ -102,3 +104,28 @@ def test_rdf_dumper(self):
# Optionally, save the RDF graph to a file
with open("/tmp/royals_rdf_output.ttl", "w") as rdf_file:
rdf_file.write(rdf_output)

# Load the serialized RDF output into an RDFLib graph
rdf_graph = Graph()
rdf_graph.parse(data=rdf_output, format="turtle")

# Perform SPARQL queries to verify the RDF content
query = prepareQuery("""
SELECT ?subject ?predicate ?object
WHERE {
?subject ?predicate ?object .
}
LIMIT 10
""")

results = rdf_graph.query(query)

# Example assertions for the query results
assert len(results) > 0, "No triples found in the RDF graph"

for row in results:
if self.debug:
print(row)
assert row.subject is not None
assert row.predicate is not None
assert row.object is not None

0 comments on commit 3a6ff00

Please sign in to comment.