-
Notifications
You must be signed in to change notification settings - Fork 543
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1002 from sa-bpelakh/1001-construct-init-bindings
CONSTRUCT resolve with initBindings fixes #1001
- Loading branch information
Showing
2 changed files
with
44 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
from rdflib import Graph, URIRef, Literal, BNode | ||
from rdflib.plugins.sparql import prepareQuery | ||
from rdflib.compare import isomorphic | ||
|
||
import unittest | ||
from nose.tools import eq_ | ||
|
||
class TestConstructInitBindings(unittest.TestCase): | ||
|
||
def test_construct_init_bindings(self): | ||
""" | ||
This is issue https://github.com/RDFLib/rdflib/issues/1001 | ||
""" | ||
|
||
g1 = Graph() | ||
|
||
q_str = (""" | ||
PREFIX : <urn:ns1:> | ||
CONSTRUCT { | ||
?uri :prop1 ?val1; | ||
:prop2 ?c . | ||
} | ||
WHERE { | ||
bind(uri(concat("urn:ns1:", ?a)) as ?uri) | ||
bind(?b as ?val1) | ||
} | ||
""") | ||
q_prepared = prepareQuery(q_str) | ||
|
||
expected = [ | ||
(URIRef('urn:ns1:A'),URIRef('urn:ns1:prop1'), Literal('B')), | ||
(URIRef('urn:ns1:A'),URIRef('urn:ns1:prop2'), Literal('C')) | ||
] | ||
results = g1.query(q_prepared, initBindings={ | ||
'a': Literal('A'), | ||
'b': Literal('B'), | ||
'c': Literal('C') | ||
}) | ||
|
||
eq_(sorted(results, key=lambda x: str(x[1])), expected) |