diff --git a/tests/test_sparql.py b/tests/test_sparql.py index ef7e163..4146c49 100644 --- a/tests/test_sparql.py +++ b/tests/test_sparql.py @@ -1,7 +1,7 @@ import json import unittest -from rdflib import RDF, ConjunctiveGraph, Graph, Namespace +from rdflib import RDF, ConjunctiveGraph, Dataset, Graph, Namespace EX = Namespace("http://example.com/") @@ -33,7 +33,6 @@ def test_select_query_graph(self): g = Graph("Oxigraph") g.add((EX.foo, RDF.type, EX.Entity)) result = g.query("SELECT ?s WHERE { ?s ?p ?o }") - self.assertEqual(len(result), 1) self.assertEqual( json.loads(result.serialize(format="json").decode("utf-8")), { @@ -46,7 +45,30 @@ def test_select_query_conjunctive(self): g = ConjunctiveGraph("Oxigraph") g.add((EX.foo, RDF.type, EX.Entity)) result = g.query("SELECT ?s WHERE { ?s ?p ?o }") - self.assertEqual(len(result), 1) + self.assertEqual( + json.loads(result.serialize(format="json").decode("utf-8")), + { + "results": {"bindings": [{"s": {"type": "uri", "value": "http://example.com/foo"}}]}, + "head": {"vars": ["s"]}, + }, + ) + + def test_select_query_dataset(self): + g = Dataset("Oxigraph") + g.add((EX.foo, RDF.type, EX.Entity)) + result = g.query("SELECT ?s WHERE { ?s ?p ?o }") + self.assertEqual( + json.loads(result.serialize(format="json").decode("utf-8")), + { + "results": {"bindings": [{"s": {"type": "uri", "value": "http://example.com/foo"}}]}, + "head": {"vars": ["s"]}, + }, + ) + + def test_select_query_dataset_default_union(self): + g = Dataset("Oxigraph", default_union=True) + g.add((EX.foo, RDF.type, EX.Entity, EX.graph)) + result = g.query("SELECT ?s WHERE { ?s ?p ?o }") self.assertEqual( json.loads(result.serialize(format="json").decode("utf-8")), { @@ -59,12 +81,41 @@ def test_construct_query(self): g = ConjunctiveGraph("Oxigraph") g.add((EX.foo, RDF.type, EX.Entity)) result = g.query("CONSTRUCT WHERE { ?s ?p ?o }") - self.assertEqual(len(result), 1) self.assertEqual( result.serialize(format="ntriples").strip(), b" .", ) + def test_insert_where_update_graph(self): + g = Graph("Oxigraph") + g.add((EX.foo, RDF.type, EX.Entity)) + g.update("INSERT { ?s a } WHERE { ?s a }") + self.assertIn((EX.foo, RDF.type, EX.Entity2), g) + + def test_insert_where_update_conjunctive_graph(self): + g = ConjunctiveGraph("Oxigraph") + g.add((EX.foo, RDF.type, EX.Entity, EX.g)) + g.update("INSERT { ?s a } WHERE { ?s a }") + self.assertIn((EX.foo, RDF.type, EX.Entity2), g) + + def test_insert_where_update_dataset_named_graph(self): + g = Dataset("Oxigraph") + g.add((EX.foo, RDF.type, EX.Entity, EX.g)) + g.update("INSERT { ?s a } WHERE { GRAPH ?g { ?s a } }") + self.assertIn((EX.foo, RDF.type, EX.Entity2, g), g) # RDFlib issue #2019 + + def test_insert_where_update_dataset_default_graph(self): + g = Dataset("Oxigraph") + g.add((EX.foo, RDF.type, EX.Entity)) + g.update("INSERT { ?s a } WHERE { ?s a }") + self.assertIn((EX.foo, RDF.type, EX.Entity2, g.identifier), g) # RDFlib issue #2019 + + def test_insert_where_update_dataset_default_union(self): + g = Dataset("Oxigraph", default_union=True) + g.add((EX.foo, RDF.type, EX.Entity, EX.g)) + g.update("INSERT { ?s a } WHERE { ?s a }") + self.assertIn((EX.foo, RDF.type, EX.Entity2, g.identifier), g) # RDFlib issue #2019 + if __name__ == "__main__": unittest.main()