|
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" |
0 commit comments