@@ -36,7 +36,6 @@ def test_select_query_graph(self):
36
36
g = Graph ("Oxigraph" )
37
37
g .add ((EX .foo , RDF .type , EX .Entity ))
38
38
result = g .query ("SELECT ?s WHERE { ?s ?p ?o }" )
39
- self .assertEqual (len (result ), 1 )
40
39
self .assertEqual (
41
40
json .loads (result .serialize (format = "json" ).decode ("utf-8" )),
42
41
{
@@ -49,7 +48,6 @@ def test_select_query_conjunctive(self):
49
48
g = ConjunctiveGraph ("Oxigraph" )
50
49
g .add ((EX .foo , RDF .type , EX .Entity ))
51
50
result = g .query ("SELECT ?s WHERE { ?s ?p ?o }" )
52
- self .assertEqual (len (result ), 1 )
53
51
self .assertEqual (
54
52
json .loads (result .serialize (format = "json" ).decode ("utf-8" )),
55
53
{
@@ -63,7 +61,18 @@ def test_select_query_dataset(self):
63
61
g = Dataset ("Oxigraph" )
64
62
g .add ((EX .foo , RDF .type , EX .Entity ))
65
63
result = g .query ("SELECT ?s WHERE { ?s ?p ?o }" )
66
- self .assertEqual (len (result ), 1 )
64
+ self .assertEqual (
65
+ json .loads (result .serialize (format = "json" ).decode ("utf-8" )),
66
+ {
67
+ "results" : {"bindings" : [{"s" : {"type" : "uri" , "value" : "http://example.com/foo" }}]},
68
+ "head" : {"vars" : ["s" ]},
69
+ },
70
+ )
71
+
72
+ def test_select_query_dataset_default_union (self ):
73
+ g = Dataset ("Oxigraph" , default_union = True )
74
+ g .add ((EX .foo , RDF .type , EX .Entity , EX .graph ))
75
+ result = g .query ("SELECT ?s WHERE { ?s ?p ?o }" )
67
76
self .assertEqual (
68
77
json .loads (result .serialize (format = "json" ).decode ("utf-8" )),
69
78
{
@@ -76,12 +85,63 @@ def test_construct_query(self):
76
85
g = ConjunctiveGraph ("Oxigraph" )
77
86
g .add ((EX .foo , RDF .type , EX .Entity ))
78
87
result = g .query ("CONSTRUCT WHERE { ?s ?p ?o }" )
79
- self .assertEqual (len (result ), 1 )
80
88
self .assertEqual (
81
89
result .serialize (format = "ntriples" ).strip (),
82
90
b"<http://example.com/foo> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://example.com/Entity> ." ,
83
91
)
84
92
93
+ def test_select_query_init_bindings (self ):
94
+ g = Graph ("Oxigraph" )
95
+ result = g .query ("SELECT ?s WHERE {}" , initBindings = {"s" : EX .foo })
96
+ self .assertEqual (
97
+ json .loads (result .serialize (format = "json" ).decode ("utf-8" )),
98
+ {
99
+ "results" : {"bindings" : [{"s" : {"type" : "uri" , "value" : "http://example.com/foo" }}]},
100
+ "head" : {"vars" : ["s" ]},
101
+ },
102
+ )
103
+
104
+ def test_select_query_init_namespace (self ):
105
+ g = Graph ("Oxigraph" )
106
+ result = g .query ("SELECT (ex:foo AS ?s) WHERE {}" , initNs = {"ex" : "http://example.com/" })
107
+ self .assertEqual (
108
+ json .loads (result .serialize (format = "json" ).decode ("utf-8" )),
109
+ {
110
+ "results" : {"bindings" : [{"s" : {"type" : "uri" , "value" : "http://example.com/foo" }}]},
111
+ "head" : {"vars" : ["s" ]},
112
+ },
113
+ )
114
+
115
+ def test_insert_where_update_graph (self ):
116
+ g = Graph ("Oxigraph" )
117
+ g .add ((EX .foo , RDF .type , EX .Entity ))
118
+ g .update ("INSERT { ?s a <http://example.com/Entity2> } WHERE { ?s a <http://example.com/Entity> }" )
119
+ self .assertIn ((EX .foo , RDF .type , EX .Entity2 ), g )
120
+
121
+ def test_insert_where_update_conjunctive_graph (self ):
122
+ g = ConjunctiveGraph ("Oxigraph" )
123
+ g .add ((EX .foo , RDF .type , EX .Entity , EX .g ))
124
+ g .update ("INSERT { ?s a <http://example.com/Entity2> } WHERE { ?s a <http://example.com/Entity> }" )
125
+ self .assertIn ((EX .foo , RDF .type , EX .Entity2 ), g )
126
+
127
+ def test_insert_where_update_dataset_named_graph (self ):
128
+ g = Dataset ("Oxigraph" )
129
+ g .add ((EX .foo , RDF .type , EX .Entity , EX .g ))
130
+ g .update ("INSERT { ?s a <http://example.com/Entity2> } WHERE { GRAPH ?g { ?s a <http://example.com/Entity> } }" )
131
+ self .assertIn ((EX .foo , RDF .type , EX .Entity2 , g ), g ) # RDFlib issue #2019
132
+
133
+ def test_insert_where_update_dataset_default_graph (self ):
134
+ g = Dataset ("Oxigraph" )
135
+ g .add ((EX .foo , RDF .type , EX .Entity ))
136
+ g .update ("INSERT { ?s a <http://example.com/Entity2> } WHERE { ?s a <http://example.com/Entity> }" )
137
+ self .assertIn ((EX .foo , RDF .type , EX .Entity2 , g .identifier ), g ) # RDFlib issue #2019
138
+
139
+ def test_insert_where_update_dataset_default_union (self ):
140
+ g = Dataset ("Oxigraph" , default_union = True )
141
+ g .add ((EX .foo , RDF .type , EX .Entity , EX .g ))
142
+ g .update ("INSERT { ?s a <http://example.com/Entity2> } WHERE { ?s a <http://example.com/Entity> }" )
143
+ self .assertIn ((EX .foo , RDF .type , EX .Entity2 , g .identifier ), g ) # RDFlib issue #2019
144
+
85
145
86
146
if __name__ == "__main__" :
87
147
unittest .main ()
0 commit comments