1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42
|
"""
Verify evaluation of BIND expressions of different types. See
<http://www.w3.org/TR/sparql11-query/#rExpression>.
"""
import pytest
from rdflib import Graph, URIRef, Literal, Variable
def get_bind_tests():
base = "http://example.org/"
g = Graph()
g.add((URIRef(base + "thing"), URIRef(base + "ns#comment"), Literal("anything")))
def check(expr, var, obj):
r = g.query(
"""
prefix : <http://example.org/ns#>
select * where { ?s ?p ?o . %s } """
% expr
)
assert r.bindings[0][Variable(var)] == obj
yield (check, 'bind("thing" as ?name)', "name", Literal("thing"))
yield (
check,
"bind(<http://example.org/other> as ?other)",
"other",
URIRef("http://example.org/other"),
)
yield (
check,
"bind(:Thing as ?type)",
"type",
URIRef("http://example.org/ns#Thing"),
)
@pytest.mark.parametrize("checker, expr, var, obj", get_bind_tests())
def test_bind(checker, expr, var, obj) -> None:
checker(expr, var, obj)
|