1010
1111import pytest
1212from rdflib import Graph , URIRef
13+ from rdflib .namespace import RDF
1314
1415from web_algebra .operation import Operation
1516
1617DOC_URI = URIRef ("https://example.org/doc/" )
1718PROV_GENERATED_BY = URIRef ("http://www.w3.org/ns/prov#wasGeneratedBy" )
1819ACTIVITY_URI = URIRef ("https://example.org/activity/#this" )
20+ DOC_TYPE = URIRef ("https://example.org/T" )
1921
2022
2123class TestToGraph :
@@ -30,6 +32,20 @@ def test_dict_is_parsed_as_jsonld(self):
3032 assert isinstance (graph , Graph )
3133 assert (DOC_URI , PROV_GENERATED_BY , ACTIVITY_URI ) in graph
3234
35+ def test_top_level_array_is_parsed_as_jsonld (self ):
36+ # SPARQL DESCRIBE/CONSTRUCT over multiple subjects returns a top-level
37+ # JSON-LD array of nodes; to_graph must accept it, not raise.
38+ data = [
39+ {"@id" : str (DOC_URI ), "@type" : [str (DOC_TYPE )]},
40+ {"@id" : str (ACTIVITY_URI ), str (PROV_GENERATED_BY ): {"@id" : str (DOC_URI )}},
41+ ]
42+
43+ graph = Operation .to_graph (data )
44+
45+ assert isinstance (graph , Graph )
46+ assert (DOC_URI , RDF .type , DOC_TYPE ) in graph
47+ assert (ACTIVITY_URI , PROV_GENERATED_BY , DOC_URI ) in graph
48+
3349 def test_graph_passes_through_unchanged (self ):
3450 # An upstream op (e.g. CONSTRUCT) already produced a Graph — identity.
3551 g = Graph ()
0 commit comments