+51
-9
lines changedFilter options
+51
-9
lines changed Original file line number Diff line number Diff line change
@@ -229,6 +229,12 @@ def eval(
229
229
) -> Iterator[Tuple["_SubjectType", "_ObjectType"]]:
230
230
raise NotImplementedError()
231
231
232
+
def __hash__(self):
233
+
return hash(repr(self))
234
+
235
+
def __eq__(self, other):
236
+
return repr(self) == repr(other)
237
+
232
238
def __lt__(self, other: Any) -> bool:
233
239
if not isinstance(other, (Path, Node)):
234
240
raise TypeError(
Original file line number Diff line number Diff line change
@@ -3,13 +3,15 @@
3
3
4
4
import pytest
5
5
6
-
from rdflib import RDF, RDFS, Graph
6
+
from rdflib import RDF, RDFS, Graph, URIRef
7
+
from rdflib.namespace import DCAT, DCTERMS
7
8
from rdflib.paths import (
8
9
AlternativePath,
9
10
InvPath,
10
11
MulPath,
11
12
NegatedPath,
12
13
OneOrMore,
14
+
Path,
13
15
SequencePath,
14
16
ZeroOrMore,
15
17
ZeroOrOne,
@@ -71,3 +73,45 @@ def test_paths_n3(
71
73
logging.debug("path = %s", path)
72
74
assert path.n3() == no_nsm
73
75
assert path.n3(nsm) == with_nsm
76
+
77
+
78
+
def test_mulpath_n3():
79
+
uri = "http://example.com/foo"
80
+
n3 = (URIRef(uri) * ZeroOrMore).n3()
81
+
assert n3 == "<" + uri + ">*"
82
+
83
+
84
+
@pytest.mark.parametrize(
85
+
["lhs", "rhs"],
86
+
[
87
+
(DCTERMS.temporal / DCAT.endDate, DCTERMS.temporal / DCAT.endDate),
88
+
(SequencePath(DCTERMS.temporal, DCAT.endDate), DCTERMS.temporal / DCAT.endDate),
89
+
],
90
+
)
91
+
def test_eq(lhs: Path, rhs: Path) -> None:
92
+
logging.debug("lhs = %s/%r, rhs = %s/%r", type(lhs), lhs, type(rhs), rhs)
93
+
assert lhs == rhs
94
+
95
+
96
+
@pytest.mark.parametrize(
97
+
["lhs", "rhs"],
98
+
[
99
+
(DCTERMS.temporal / DCAT.endDate, DCTERMS.temporal / DCAT.endDate),
100
+
(SequencePath(DCTERMS.temporal, DCAT.endDate), DCTERMS.temporal / DCAT.endDate),
101
+
],
102
+
)
103
+
def test_hash(lhs: Path, rhs: Path) -> None:
104
+
logging.debug("lhs = %s/%r, rhs = %s/%r", type(lhs), lhs, type(rhs), rhs)
105
+
assert hash(lhs) == hash(rhs)
106
+
107
+
108
+
@pytest.mark.parametrize(
109
+
["insert_path", "check_path"],
110
+
[
111
+
(DCTERMS.temporal / DCAT.endDate, DCTERMS.temporal / DCAT.endDate),
112
+
(SequencePath(DCTERMS.temporal, DCAT.endDate), DCTERMS.temporal / DCAT.endDate),
113
+
],
114
+
)
115
+
def test_dict_key(insert_path: Path, check_path: Path) -> None:
116
+
d = {insert_path: "foo"}
117
+
assert d[check_path] == "foo"
You can’t perform that action at this time.
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4