summaryrefslogtreecommitdiff
path: root/test/test_issue381.py
diff options
context:
space:
mode:
authorPierre-Antoine Champin <pchampin@liris.cnrs.fr>2015-09-28 11:12:31 +0200
committerPierre-Antoine Champin <pchampin@liris.cnrs.fr>2015-09-28 11:12:31 +0200
commitf4bcab1684953cbd193310215605dbae81523450 (patch)
tree6c5a275cc4f04e60e025877bebbd751672b9c87b /test/test_issue381.py
parent12596d839fce8e93ee1bc91cb257a4df11924b4e (diff)
downloadrdflib-f4bcab1684953cbd193310215605dbae81523450.tar.gz
fixed issue #381
Diffstat (limited to 'test/test_issue381.py')
-rw-r--r--test/test_issue381.py119
1 files changed, 119 insertions, 0 deletions
diff --git a/test/test_issue381.py b/test/test_issue381.py
new file mode 100644
index 00000000..4fc48e8c
--- /dev/null
+++ b/test/test_issue381.py
@@ -0,0 +1,119 @@
+from rdflib import BNode, Graph, Namespace
+from rdflib.compare import isomorphic
+
+NS = Namespace("http://example.org/")
+
+def test_no_spurious_semicolon():
+ sparql = """
+ PREFIX : <http://example.org/>
+ CONSTRUCT {
+ :a :b :c ; :d :e .
+ } WHERE {}
+ """
+ expected = Graph()
+ expected.addN( t+(expected,) for t in [
+ (NS.a, NS.b, NS.c),
+ (NS.a, NS.d, NS.e),
+ ])
+ got = Graph().query(sparql).graph
+ assert isomorphic(got, expected), got.serialize(format="turtle")
+
+def test_one_spurious_semicolon():
+ sparql = """
+ PREFIX : <http://example.org/>
+ CONSTRUCT {
+ :a :b :c ; :d :e ; .
+ } WHERE {}
+ """
+ expected = Graph()
+ expected.addN( t+(expected,) for t in [
+ (NS.a, NS.b, NS.c),
+ (NS.a, NS.d, NS.e),
+ ])
+ got = Graph().query(sparql).graph
+ assert isomorphic(got, expected), got.serialize(format="turtle")
+
+def test_one_spurious_semicolon_no_perdiod():
+ sparql = """
+ PREFIX : <http://example.org/>
+ CONSTRUCT {
+ :a :b :c ; :d :e ;
+ } WHERE {}
+ """
+ expected = Graph()
+ expected.addN( t+(expected,) for t in [
+ (NS.a, NS.b, NS.c),
+ (NS.a, NS.d, NS.e),
+ ])
+ got = Graph().query(sparql).graph
+ assert isomorphic(got, expected), got.serialize(format="turtle")
+
+def test_two_spurious_semicolons_no_period():
+ sparql = """
+ PREFIX : <http://example.org/>
+ CONSTRUCT {
+ :a :b :c ; :d :e ; ;
+ } WHERE {}
+ """
+ expected = Graph()
+ expected.addN( t+(expected,) for t in [
+ (NS.a, NS.b, NS.c),
+ (NS.a, NS.d, NS.e),
+ ])
+ got = Graph().query(sparql).graph
+ assert isomorphic(got, expected), got.serialize(format="turtle")
+
+def test_one_spurious_semicolons_bnode():
+ sparql = """
+ PREFIX : <http://example.org/>
+ CONSTRUCT {
+ [ :b :c ; :d :e ; ]
+ } WHERE {}
+ """
+ expected = Graph()
+ expected.addN( t+(expected,) for t in [
+ (BNode("a"), NS.b, NS.c),
+ (BNode("a"), NS.d, NS.e),
+ ])
+ got = Graph().query(sparql).graph
+ assert isomorphic(got, expected), got.serialize(format="turtle")
+
+def test_pathological():
+ """
+ This test did not raise an exception,
+ but generated a graph completely different from the expected one.
+ """
+ sparql = """
+ PREFIX : <http://example.org/>
+ CONSTRUCT {
+ :a :b :c ; ;
+ :d :e ; ;
+ :f :g ;
+ } WHERE {}
+ """
+ expected = Graph()
+ expected.addN( t+(expected,) for t in [
+ (NS.a, NS.b, NS.c),
+ (NS.a, NS.d, NS.e),
+ (NS.a, NS.f, NS.g),
+ ])
+ got = Graph().query(sparql).graph
+ assert isomorphic(got, expected), got.serialize(format="turtle")
+
+def test_mixing_spurious_semicolons_and_commas():
+ sparql = """
+ PREFIX : <http://example.org/>
+ CONSTRUCT {
+ :a :b :c ; ;
+ :d :e, :f
+ } WHERE {}
+ """
+ expected = Graph()
+ expected.addN( t+(expected,) for t in [
+ (NS.a, NS.b, NS.c),
+ (NS.a, NS.d, NS.e),
+ (NS.a, NS.d, NS.f),
+ ])
+ got = Graph().query(sparql).graph
+ assert isomorphic(got, expected), got.serialize(format="turtle")
+