Ensure generated SPARQL queries are syntactically valid
This commit is contained in:
@ -160,7 +160,7 @@ class Table:
|
||||
yield SparqlVariable(f"{prefix}{i}")
|
||||
|
||||
subject = SparqlVariable("subject")
|
||||
columns = ", ".join(f"?{field.id}" for field in self.fields)
|
||||
columns = " ".join(f"?{field.id}" for field in self.fields)
|
||||
statements = "\n ".join(
|
||||
field.sparql(subject, SparqlVariable(field.id), new_var(field.id).__next__)
|
||||
for field in self.fields
|
||||
|
@ -20,7 +20,7 @@ import rdflib
|
||||
from glowtables.table import Language, LiteralField, Table
|
||||
|
||||
|
||||
def test_single_literal() -> None:
|
||||
def test_single_literal(rdflib_sparql) -> None:
|
||||
name_field = LiteralField(
|
||||
"display_name",
|
||||
{Language("en"): "Name"},
|
||||
@ -41,8 +41,10 @@ def test_single_literal() -> None:
|
||||
"""
|
||||
)
|
||||
|
||||
rdflib_sparql.query(table.sparql())
|
||||
|
||||
def test_two_literals() -> None:
|
||||
|
||||
def test_two_literals(rdflib_sparql) -> None:
|
||||
name_field = LiteralField(
|
||||
"display_name",
|
||||
{Language("en"): "Name"},
|
||||
@ -60,7 +62,7 @@ def test_two_literals() -> None:
|
||||
|
||||
assert table.sparql() == textwrap.dedent(
|
||||
"""
|
||||
SELECT ?display_name, ?frequency
|
||||
SELECT ?display_name ?frequency
|
||||
WHERE {
|
||||
?subject <http://example.org/type> <http://example.org/CPU>.
|
||||
?subject <http://example.org/display-name> ?display_name.
|
||||
@ -69,8 +71,10 @@ def test_two_literals() -> None:
|
||||
"""
|
||||
)
|
||||
|
||||
rdflib_sparql.query(table.sparql())
|
||||
|
||||
def test_default_value() -> None:
|
||||
|
||||
def test_default_value(rdflib_sparql) -> None:
|
||||
name_field = LiteralField(
|
||||
"display_name",
|
||||
{Language("en"): "Name"},
|
||||
@ -92,6 +96,8 @@ def test_default_value() -> None:
|
||||
"""
|
||||
)
|
||||
|
||||
rdflib_sparql.query(table.sparql())
|
||||
|
||||
|
||||
def test_field_id_subject() -> None:
|
||||
name_field = LiteralField(
|
||||
|
Reference in New Issue
Block a user