diff options
author | Joern Hees <dev@joernhees.de> | 2016-03-18 11:28:40 +0100 |
---|---|---|
committer | Gunnar Aastrand Grimnes <gromgull@gmail.com> | 2017-01-20 10:32:17 +0100 |
commit | 738e19ba8dee6250756d225fe99fafef32e282f9 (patch) | |
tree | a7ca81e28460cb4cadd56c31f6524239607fc36d | |
parent | acc6ed3e3548a75541607ec753d05d5061028465 (diff) | |
download | rdflib-738e19ba8dee6250756d225fe99fafef32e282f9.tar.gz |
test for #607
-rw-r--r-- | test/test_issue607.py | 59 |
1 files changed, 59 insertions, 0 deletions
diff --git a/test/test_issue607.py b/test/test_issue607.py new file mode 100644 index 00000000..3ae1a179 --- /dev/null +++ b/test/test_issue607.py @@ -0,0 +1,59 @@ +# test for https://github.com/RDFLib/rdflib/issues/607 + +from rdflib import Graph, URIRef, Literal, Namespace +from rdflib.namespace import FOAF, RDF + +X = Namespace("http://example.org/") + +sample_data = ''' +@prefix x: <http://example.org/> . + +x:a x:p x:b . +x:b x:p x:c . +x:x x:p x:y . +''' + +g = Graph().parse(data=sample_data, format='n3') +assert len(g) == 3 + + +# find 2 hop chain (this works) +q = ''' +select ?a ?b ?c where { + ?a x:p ?b . + ?b x:p ?c . +} +''' +expected = [(X.a, X.b, X.c)] +res = sorted(g.query(q)) +assert res == expected, '\nexpected: %s\ngot : %s' % (expected, res) + + +# find 2 hop chain with subquery (doesn't work) +q = ''' +select ?a ?b ?c where { + ?a x:p ?b . + { + select ?b ?c where { + ?b x:p ?c . + } + } +} +''' +res = sorted(g.query(q)) +assert res == expected, '\nexpected: %s\ngot : %s' % (expected, res) + + +# find 2 hop chain with subquery, exec subquery first (works) +q = ''' +select ?a ?b ?c where { + { + select ?b ?c where { + ?b x:p ?c . + } + } + ?a x:p ?b . +} +''' +res = sorted(g.query(q)) +assert res == expected, '\nexpected: %s\ngot : %s' % (expected, res) |