summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorNicholas Car <nick@kurrawong.net>2020-03-12 14:06:57 +1000
committerGitHub <noreply@github.com>2020-03-12 14:06:57 +1000
commit24c01e2ce1f699b6ce4c818eea2d13bd4285a60d (patch)
tree526fd4e70fc7ce0c5d9b78a7b09f3a74c26ac9c1 /test
parent138a4811b181ce3ae6f978575679c5b7777cc3dd (diff)
parente8e020bbe7b9bae2df259ba30fd3e06f98b44450 (diff)
downloadrdflib-24c01e2ce1f699b6ce4c818eea2d13bd4285a60d.tar.gz
Merge pull request #946 from JervenBolleman/issue733
#733 adding a test case, which I think matches the reported issue.
Diffstat (limited to 'test')
-rw-r--r--test/test_issue733.py78
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()