diff options
Diffstat (limited to 'test/test_issue733.py')
-rw-r--r-- | test/test_issue733.py | 78 |
1 files changed, 78 insertions, 0 deletions
diff --git a/test/test_issue733.py b/test/test_issue733.py new file mode 100644 index 00000000..bffeb400 --- /dev/null +++ b/test/test_issue733.py @@ -0,0 +1,78 @@ +""" +Issue 715 - path query chaining issue +Some incorrect matches were found when using oneOrMore ('+') and +zeroOrMore ('*') property paths and specifying neither the +subject or the object. +""" + +from rdflib import URIRef, Graph +import unittest + +from rdflib.namespace import RDF, RDFS, NamespaceManager, Namespace + + +class TestIssue733(unittest.TestCase): + + def test_issue_733(self): + g = Graph() + example = Namespace('http://example.org/') + g.add((example.S, example.P, example.O1)) + g.add((example.S, example.P, example.O2)) + q = ''' + prefix ex:<http://example.org/> + select ?st ?ot ?gt where { + {SELECT (count(*) as ?st) where { + ?s ?p ?o . + FILTER (?s=ex:S) + }} + {SELECT (count(*) as ?ot) where { + ?s ?p ?o . + FILTER (?o=ex:O1) + }} + {SELECT (count(*) as ?gt) where { + ?s ?p ?o . + FILTER (?o!=ex:O1 && ?s!=ex:O2) + }} + } + ''' + res = g.query(q) + assert len(res) == 1 + results = [[lit.toPython() for lit in line] for line in res] + assert results[0][0]== 2 + assert results[0][1] == 1 + assert results[0][2] == 1 + + def test_issue_733_independant(self): + g = Graph() + example = Namespace('http://example.org/') + g.add((example.S, example.P, example.O1)) + g.add((example.S, example.P, example.O2)) + q = ''' + prefix ex:<http://example.org/> + select ?st where { + {SELECT (count(*) as ?st) where { + ?s ?p ?o . + FILTER (?s=ex:S) + }} + } + ''' + res = g.query(q) + assert len(res) == 1 + results = [[lit.toPython() for lit in line] for line in res] + assert results[0][0] == 2 + q = ''' + prefix ex:<http://example.org/> + select ?st where { + {SELECT (count(*) as ?st) where { + ?s ?p ?o . + FILTER (?o=ex:O1) + }} + } + ''' + res = g.query(q) + results = [[lit.toPython() for lit in line] for line in res] + assert results[0][0] == 1 + + +if __name__ == "__main__": + unittest.main() |