Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added test for finding literal triples #183

Merged
merged 6 commits into from
Mar 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions docs/api_reference/testutils.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# testutils

::: tripper.testutils
48 changes: 48 additions & 0 deletions tests/test_triplestore.py
Original file line number Diff line number Diff line change
Expand Up @@ -277,3 +277,51 @@ def test_backend_sparqlwrapper_methods() -> None:
(EX.a, SKOS.prefLabel, Literal("An a class.", lang="en")),
]
)


# if True:
def test_find_literal_triples() -> None:
"""Test finding literals."""
pytest.importorskip("rdflib")

from tripper import RDF, XSD, Literal, Triplestore
from tripper.testutils import ontodir

ts = Triplestore("rdflib")
FAM = ts.bind("ex", "http://onto-ns.com/ontologies/examples/family#")
ts.parse(ontodir / "family.ttl")
ts.add_triples(
[
(FAM.Ola, RDF.type, FAM.Son),
(FAM.Ola, FAM.hasName, Literal("Ola")),
(FAM.Ola, FAM.hasAge, Literal(18)),
(FAM.Ola, FAM.hasWeight, Literal(68.5)),
(FAM.Kari, RDF.type, FAM.Dauther),
(FAM.Kari, FAM.hasName, Literal("Kari")),
(FAM.Kari, FAM.hasAge, Literal(18)),
(FAM.Kari, FAM.hasWeight, Literal(66.2)),
(FAM.Per, RDF.type, FAM.Father),
(FAM.Per, FAM.hasName, Literal("Per")),
(FAM.Per, FAM.hasAge, Literal(49)),
(FAM.Per, FAM.hasWeight, Literal(83.8)),
(FAM.Per, FAM.hasChild, FAM.Ola),
(FAM.Per, FAM.hasChild, FAM.Kari),
]
)
assert set(
ts.subjects(
predicate=FAM.hasAge,
object=Literal(18, datatype=XSD.integer),
)
) == set([FAM.Ola, FAM.Kari])

assert set(
ts.triples(
predicate=FAM.hasName,
object=Literal("Per", datatype=XSD.string),
)
) == set(
[
(FAM.Per, FAM.hasName, Literal("Per")),
]
)
12 changes: 12 additions & 0 deletions tripper/testutils.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
"""Motule primarly intended to be imported by tests.
It defines some directories and some utility functions that can be used
with or without conftest.
"""

from pathlib import Path

rootdir = Path(__file__).resolve().parent.parent
testdir = rootdir / "tests"
ontodir = testdir / "ontologies"
outdir = testdir / "output"
Loading