-
Notifications
You must be signed in to change notification settings - Fork 565
/
Copy pathtest_uriref_literal_comparison.py
69 lines (56 loc) · 2.54 KB
/
test_uriref_literal_comparison.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
from rdflib.graph import Graph
from rdflib.namespace import RDF
from rdflib.plugins.parsers.rdfxml import CORE_SYNTAX_TERMS
from rdflib.term import BNode, Literal, URIRef
"""
Ah... it's coming back to me...
[6:32p] eikeon: think it's so transitivity holds...
[6:32p] eikeon: if a==b and b==c then a should == c
[6:32p] eikeon: "foo"==Literal("foo")
[6:33p] eikeon: We don't want URIRef("foo")==Literal("foo")
[6:33p] eikeon: But if we have URIRef("foo")=="foo" then it implies it.
[6:33p] chimezie: yes, definately not the other RDFLib 'typed' RDF (and N3) terms
[6:34p] eikeon: Why do you need URIRef("foo")=="foo" ?
[6:34p] chimezie: i'm just wondering if a URI and a string with the same lexical value, are by definition 'different'
[6:35p] eikeon: Think so, actually. Think of trying to serialize some triples.
[6:36p] eikeon: If they are the same you'd serialize them the same, no?
[6:36p] chimezie: I guess I was thinking of a 'string' in a native datatype sense, not in the RDF sense (where they would be distinctly different)
[6:37p] eikeon: We should try and brain dump some of this...
[6:37p] eikeon: it look a fairly long time to work out.
[6:37p] eikeon: But think we finally landed in the right spot.
[6:38p] eikeon: I know many of the backends break if URIRef("foo")==Literal("foo")
[6:39p] eikeon: And if we want "foo"==Literal("foo") --- then we really can't have URIRef("foo") also == "foo"
"""
class TestIdentifierEquality:
def setup_method(self):
self.uriref = URIRef("http://example.org/")
self.bnode = BNode()
self.literal = Literal("http://example.org/")
self.python_literal = "http://example.org/"
self.python_literal_2 = "foo"
def test_a(self):
assert self.uriref != self.literal
def test_b(self):
assert self.literal != self.uriref
def test_c(self):
assert self.uriref != self.python_literal
def test_d(self):
assert self.python_literal != self.uriref
def test_e(self):
assert self.literal != self.python_literal
def test_e2(self):
assert self.literal.eq(self.python_literal)
def test_f(self):
assert self.python_literal != self.literal
def test_g(self):
assert "foo" not in CORE_SYNTAX_TERMS
def test_h(self):
assert (
URIRef("http://www.w3.org/1999/02/22-rdf-syntax-ns#RDF")
in CORE_SYNTAX_TERMS
)
def test_i(self):
g = Graph()
g.add((self.uriref, RDF.value, self.literal))
g.add((self.uriref, RDF.value, self.uriref))
assert len(g) == 2