Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

change tests to use urn:example #1654

Merged
merged 1 commit into from Jan 9, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
14 changes: 7 additions & 7 deletions test/test_conjunctivegraph_generators.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,13 @@
).read()


michel = URIRef("urn:michel")
tarek = URIRef("urn:tarek")
bob = URIRef("urn:bob")
likes = URIRef("urn:likes")
hates = URIRef("urn:hates")
pizza = URIRef("urn:pizza")
cheese = URIRef("urn:cheese")
michel = URIRef("urn:example:michel")
tarek = URIRef("urn:example:tarek")
bob = URIRef("urn:example:bob")
likes = URIRef("urn:example:likes")
hates = URIRef("urn:example:hates")
pizza = URIRef("urn:example:pizza")
cheese = URIRef("urn:example:cheese")


def add_stuff(graph):
Expand Down
16 changes: 8 additions & 8 deletions test/test_dataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,17 +49,17 @@ def setUp(self):

if self.store != "SPARQLUpdateStore":
self.graph.open(self.tmppath, create=True)
self.michel = URIRef("urn:michel")
self.tarek = URIRef("urn:tarek")
self.bob = URIRef("urn:bob")
self.likes = URIRef("urn:likes")
self.hates = URIRef("urn:hates")
self.pizza = URIRef("urn:pizza")
self.michel = URIRef("urn:example:michel")
self.tarek = URIRef("urn:example:tarek")
self.bob = URIRef("urn:example:bob")
self.likes = URIRef("urn:example:likes")
self.hates = URIRef("urn:example:hates")
self.pizza = URIRef("urn:example:pizza")
self.cheese = URIRef("urn:cheese")

# Use regular URIs because SPARQL endpoints like Fuseki alter short names
self.c1 = URIRef("urn:context-1")
self.c2 = URIRef("urn:context-2")
self.c1 = URIRef("urn:example:context-1")
self.c2 = URIRef("urn:example:context-2")

# delete the graph for each test!
self.graph.remove((None, None, None))
Expand Down
14 changes: 7 additions & 7 deletions test/test_dataset_generators.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@
).read()


michel = URIRef("urn:michel")
tarek = URIRef("urn:tarek")
bob = URIRef("urn:bob")
likes = URIRef("urn:likes")
hates = URIRef("urn:hates")
pizza = URIRef("urn:pizza")
cheese = URIRef("urn:cheese")
michel = URIRef("urn:example:michel")
tarek = URIRef("urn:example:tarek")
bob = URIRef("urn:example:bob")
likes = URIRef("urn:example:likes")
hates = URIRef("urn:example:hates")
pizza = URIRef("urn:example:pizza")
cheese = URIRef("urn:example:cheese")


def add_stuff(graph):
Expand Down
14 changes: 7 additions & 7 deletions test/test_graph.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,13 @@ def setUp(self):
self.tmppath = mkdtemp()
self.graph.open(self.tmppath, create=True)

self.michel = URIRef("michel")
self.tarek = URIRef("tarek")
self.bob = URIRef("bob")
self.likes = URIRef("likes")
self.hates = URIRef("hates")
self.pizza = URIRef("pizza")
self.cheese = URIRef("cheese")
self.michel = URIRef("urn:example:michel")
self.tarek = URIRef("urn:example:tarek")
self.bob = URIRef("urn:example:bob")
self.likes = URIRef("urn:example:likes")
self.hates = URIRef("urn:example:hates")
self.pizza = URIRef("urn:example:pizza")
self.cheese = URIRef("urn:example:cheese")

def tearDown(self):
self.graph.close()
Expand Down
14 changes: 7 additions & 7 deletions test/test_graph_generators.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import os
from rdflib import Graph, URIRef

michel = URIRef("urn:michel")
tarek = URIRef("urn:tarek")
bob = URIRef("urn:bob")
likes = URIRef("urn:likes")
hates = URIRef("urn:hates")
pizza = URIRef("urn:pizza")
cheese = URIRef("urn:cheese")
michel = URIRef("urn:example:michel")
tarek = URIRef("urn:example:tarek")
bob = URIRef("urn:example:bob")
likes = URIRef("urn:example:likes")
hates = URIRef("urn:example:hates")
pizza = URIRef("urn:example:pizza")
cheese = URIRef("urn:example:cheese")

timblcardn3 = open(
os.path.join(os.path.dirname(__file__), "consistent_test_data", "timbl-card.n3")
Expand Down
6 changes: 3 additions & 3 deletions test/test_nquads.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,9 @@ def test_serialize(self):
uri1 = URIRef("http://example.org/mygraph1")
uri2 = URIRef("http://example.org/mygraph2")

bob = URIRef("urn:bob")
likes = URIRef("urn:likes")
pizza = URIRef("urn:pizza")
bob = URIRef("urn:example:bob")
likes = URIRef("urn:example:likes")
pizza = URIRef("urn:example:pizza")

g.get_context(uri1).add((bob, likes, pizza))
g.get_context(uri2).add((bob, likes, pizza))
Expand Down
80 changes: 40 additions & 40 deletions test/test_sparqlupdatestore.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,16 +21,16 @@

# THIS WILL DELETE ALL DATA IN THE /db dataset

michel = URIRef("urn:michel")
tarek = URIRef("urn:tarek")
bob = URIRef("urn:bob")
likes = URIRef("urn:likes")
hates = URIRef("urn:hates")
pizza = URIRef("urn:pizza")
cheese = URIRef("urn:cheese")
michel = URIRef("urn:example:michel")
tarek = URIRef("urn:example:tarek")
bob = URIRef("urn:example:bob")
likes = URIRef("urn:example:likes")
hates = URIRef("urn:example:hates")
pizza = URIRef("urn:example:pizza")
cheese = URIRef("urn:example:cheese")

graphuri = URIRef("urn:graph")
othergraphuri = URIRef("urn:othergraph")
graphuri = URIRef("urn:example:graph")
othergraphuri = URIRef("urn:example:othergraph")

try:
assert len(urlopen(HOST).read()) > 0
Expand Down Expand Up @@ -68,15 +68,15 @@ def testSimpleGraph(self):
self.assertEqual(3, len(g), "graph contains 3 triples")
self.assertEqual(1, len(g2), "other graph contains 1 triple")

r = g.query("SELECT * WHERE { ?s <urn:likes> <urn:pizza> . }")
r = g.query("SELECT * WHERE { ?s <urn:example:likes> <urn:example:pizza> . }")
self.assertEqual(2, len(list(r)), "two people like pizza")

r = g.triples((None, likes, pizza))
self.assertEqual(2, len(list(r)), "two people like pizza")

# Test initBindings
r = g.query(
"SELECT * WHERE { ?s <urn:likes> <urn:pizza> . }", initBindings={"s": tarek}
"SELECT * WHERE { ?s <urn:example:likes> <urn:example:pizza> . }", initBindings={"s": tarek},
)
self.assertEqual(1, len(list(r)), "i was asking only about tarek")

Expand All @@ -88,7 +88,7 @@ def testSimpleGraph(self):

g2.add((tarek, likes, pizza))
g.remove((tarek, likes, pizza))
r = g.query("SELECT * WHERE { ?s <urn:likes> <urn:pizza> . }")
r = g.query("SELECT * WHERE { ?s <urn:example:likes> <urn:example:pizza> . }")
self.assertEqual(1, len(list(r)), "only bob likes pizza")

def testConjunctiveDefault(self):
Expand Down Expand Up @@ -117,11 +117,11 @@ def testConjunctiveDefault(self):
"%s" % list(self.graph),
)

r = self.graph.query("SELECT * WHERE { ?s <urn:likes> <urn:pizza> . }")
r = self.graph.query("SELECT * WHERE { ?s <urn:example:likes> <urn:example:pizza> . }")
self.assertEqual(2, len(list(r)), "two people like pizza")

r = self.graph.query(
"SELECT * WHERE { ?s <urn:likes> <urn:pizza> . }", initBindings={"s": tarek}
"SELECT * WHERE { ?s <urn:example:likes> <urn:example:pizza> . }", initBindings={"s": tarek},
)
self.assertEqual(1, len(list(r)), "i was asking only about tarek")

Expand All @@ -133,12 +133,12 @@ def testConjunctiveDefault(self):

g2.remove((bob, likes, pizza))

r = self.graph.query("SELECT * WHERE { ?s <urn:likes> <urn:pizza> . }")
r = self.graph.query("SELECT * WHERE { ?s <urn:example:likes> <urn:example:pizza> . }")
self.assertEqual(1, len(list(r)), "only tarek likes pizza")

def testUpdate(self):
self.graph.update(
"INSERT DATA { GRAPH <urn:graph> { <urn:michel> <urn:likes> <urn:pizza> . } }"
"INSERT DATA { GRAPH <urn:example:graph> { <urn:example:michel> <urn:example:likes> <urn:example:pizza> . } }"
)

g = self.graph.get_context(graphuri)
Expand All @@ -147,7 +147,7 @@ def testUpdate(self):
def testUpdateWithInitNs(self):
self.graph.update(
"INSERT DATA { GRAPH ns:graph { ns:michel ns:likes ns:pizza . } }",
initNs={"ns": URIRef("urn:")},
initNs={"ns": URIRef("urn:example:")},
)

g = self.graph.get_context(graphuri)
Expand All @@ -159,11 +159,11 @@ def testUpdateWithInitNs(self):

def testUpdateWithInitBindings(self):
self.graph.update(
"INSERT { GRAPH <urn:graph> { ?a ?b ?c . } } WherE { }",
"INSERT { GRAPH <urn:example:graph> { ?a ?b ?c . } } WherE { }",
initBindings={
"a": URIRef("urn:michel"),
"b": URIRef("urn:likes"),
"c": URIRef("urn:pizza"),
"a": URIRef("urn:example:michel"),
"b": URIRef("urn:example:likes"),
"c": URIRef("urn:example:pizza"),
},
)

Expand All @@ -176,17 +176,17 @@ def testUpdateWithInitBindings(self):

def testUpdateWithBlankNode(self):
self.graph.update(
"INSERT DATA { GRAPH <urn:graph> { _:blankA <urn:type> <urn:Blank> } }"
"INSERT DATA { GRAPH <urn:example:graph> { _:blankA <urn:example:type> <urn:example:Blank> } }"
)
g = self.graph.get_context(graphuri)
for t in g.triples((None, None, None)):
self.assertTrue(isinstance(t[0], BNode))
self.assertEqual(t[1].n3(), "<urn:type>")
self.assertEqual(t[2].n3(), "<urn:Blank>")
self.assertEqual(t[1].n3(), "<urn:example:type>")
self.assertEqual(t[2].n3(), "<urn:example:Blank>")

def testUpdateWithBlankNodeSerializeAndParse(self):
self.graph.update(
"INSERT DATA { GRAPH <urn:graph> { _:blankA <urn:type> <urn:Blank> } }"
"INSERT DATA { GRAPH <urn:example:graph> { _:blankA <urn:example:type> <urn:example:Blank> } }"
)
g = self.graph.get_context(graphuri)
string = g.serialize(format="ntriples")
Expand All @@ -199,13 +199,13 @@ def testUpdateWithBlankNodeSerializeAndParse(self):

def testMultipleUpdateWithInitBindings(self):
self.graph.update(
"INSERT { GRAPH <urn:graph> { ?a ?b ?c . } } WHERE { };"
"INSERT { GRAPH <urn:graph> { ?d ?b ?c . } } WHERE { }",
"INSERT { GRAPH <urn:example:graph> { ?a ?b ?c . } } WHERE { };"
"INSERT { GRAPH <urn:example:graph> { ?d ?b ?c . } } WHERE { }",
initBindings={
"a": URIRef("urn:michel"),
"b": URIRef("urn:likes"),
"c": URIRef("urn:pizza"),
"d": URIRef("urn:bob"),
"a": URIRef("urn:example:michel"),
"b": URIRef("urn:example:likes"),
"c": URIRef("urn:example:pizza"),
"d": URIRef("urn:example:bob"),
},
)

Expand All @@ -218,7 +218,7 @@ def testMultipleUpdateWithInitBindings(self):

def testNamedGraphUpdate(self):
g = self.graph.get_context(graphuri)
r1 = "INSERT DATA { <urn:michel> <urn:likes> <urn:pizza> }"
r1 = "INSERT DATA { <urn:example:michel> <urn:example:likes> <urn:example:pizza> }"
g.update(r1)
self.assertEqual(
set(g.triples((None, None, None))),
Expand All @@ -227,8 +227,8 @@ def testNamedGraphUpdate(self):
)

r2 = (
"DELETE { <urn:michel> <urn:likes> <urn:pizza> } "
+ "INSERT { <urn:bob> <urn:likes> <urn:pizza> } WHERE {}"
"DELETE { <urn:example:michel> <urn:example:likes> <urn:example:pizza> } "
+ "INSERT { <urn:example:bob> <urn:example:likes> <urn:example:pizza> } WHERE {}"
)
g.update(r2)
self.assertEqual(
Expand All @@ -245,7 +245,7 @@ def testNamedGraphUpdate(self):
for tricky_str in tricky_strs:
r3 = (
"""INSERT { ?b <urn:says> "%s" }
WHERE { ?b <urn:likes> <urn:pizza>} """
WHERE { ?b <urn:example:likes> <urn:example:pizza>} """
% tricky_str
)
g.update(r3)
Expand All @@ -272,7 +272,7 @@ def testNamedGraphUpdate(self):
r4strings.append("'''10: ad adsfj \n { \n sadfj'''")

r4 = "\n".join(
["INSERT DATA { <urn:michel> <urn:says> %s } ;" % s for s in r4strings]
["INSERT DATA { <urn:example:michel> <urn:says> %s } ;" % s for s in r4strings]
)
g.update(r4)
values = set()
Expand All @@ -297,19 +297,19 @@ def testNamedGraphUpdate(self):
# (commenting out the end of the block).
# The ' must not be interpreted as the start of a string, causing the }
# in the literal to be identified as the end of the block.
r5 = """INSERT DATA { <urn:michel> <urn:hates> <urn:foo'bar?baz;a=1&b=2#fragment>, "'}" }"""
r5 = """INSERT DATA { <urn:example:michel> <urn:example:hates> <urn:example:foo'bar?baz;a=1&b=2#fragment>, "'}" }"""

g.update(r5)
values = set()
for v in g.objects(michel, hates):
values.add(str(v))
self.assertEqual(values, set(["urn:foo'bar?baz;a=1&b=2#fragment", "'}"]))
self.assertEqual(values, set(["urn:example:foo'bar?baz;a=1&b=2#fragment", "'}"]))

# Comments
r6 = """
INSERT DATA {
<urn:bob> <urn:hates> <urn:bob> . # No closing brace: }
<urn:bob> <urn:hates> <urn:michel>.
<urn:example:bob> <urn:example:hates> <urn:example:bob> . # No closing brace: }
<urn:example:bob> <urn:example:hates> <urn:example:michel>.
}
#Final { } comment"""

Expand Down