Skip to content
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions rdflib/paths.py
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,12 @@ def eval(
) -> Iterator[Tuple["_SubjectType", "_ObjectType"]]:
raise NotImplementedError()

def __hash__(self):
return hash(repr(self))

def __eq__(self, other):
return repr(self) == repr(other)

def __lt__(self, other: Any) -> bool:
if not isinstance(other, (Path, Node)):
raise TypeError(
Expand Down
8 changes: 0 additions & 8 deletions test/test_mulpath_n3.py

This file was deleted.

46 changes: 45 additions & 1 deletion test/test_paths_n3.py → test/test_path.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,15 @@

import pytest

from rdflib import RDF, RDFS, Graph
from rdflib import RDF, RDFS, Graph, URIRef
from rdflib.namespace import DCAT, DCTERMS
from rdflib.paths import (
AlternativePath,
InvPath,
MulPath,
NegatedPath,
OneOrMore,
Path,
SequencePath,
ZeroOrMore,
ZeroOrOne,
Expand Down Expand Up @@ -71,3 +73,45 @@ def test_paths_n3(
logging.debug("path = %s", path)
assert path.n3() == no_nsm
assert path.n3(nsm) == with_nsm


def test_mulpath_n3():
uri = "http://example.com/foo"
n3 = (URIRef(uri) * ZeroOrMore).n3()
assert n3 == "<" + uri + ">*"


@pytest.mark.parametrize(
["lhs", "rhs"],
[
(DCTERMS.temporal / DCAT.endDate, DCTERMS.temporal / DCAT.endDate),
(SequencePath(DCTERMS.temporal, DCAT.endDate), DCTERMS.temporal / DCAT.endDate),
],
)
def test_eq(lhs: Path, rhs: Path) -> None:
logging.debug("lhs = %s/%r, rhs = %s/%r", type(lhs), lhs, type(rhs), rhs)
assert lhs == rhs


@pytest.mark.parametrize(
["lhs", "rhs"],
[
(DCTERMS.temporal / DCAT.endDate, DCTERMS.temporal / DCAT.endDate),
(SequencePath(DCTERMS.temporal, DCAT.endDate), DCTERMS.temporal / DCAT.endDate),
],
)
def test_hash(lhs: Path, rhs: Path) -> None:
logging.debug("lhs = %s/%r, rhs = %s/%r", type(lhs), lhs, type(rhs), rhs)
assert hash(lhs) == hash(rhs)


@pytest.mark.parametrize(
["insert_path", "check_path"],
[
(DCTERMS.temporal / DCAT.endDate, DCTERMS.temporal / DCAT.endDate),
(SequencePath(DCTERMS.temporal, DCAT.endDate), DCTERMS.temporal / DCAT.endDate),
],
)
def test_dict_key(insert_path: Path, check_path: Path) -> None:
d = {insert_path: "foo"}
assert d[check_path] == "foo"