-
Notifications
You must be signed in to change notification settings - Fork 543
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add the ability to pass a NamespaceManager to the n3 method on Paths …
…just like for Terms
- Loading branch information
Showing
2 changed files
with
54 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
from rdflib import Graph | ||
from rdflib import RDF, RDFS | ||
from rdflib.paths import ZeroOrMore, OneOrMore, ZeroOrOne | ||
import pytest | ||
|
||
|
||
g = Graph() | ||
nsm = g.namespace_manager | ||
|
||
|
||
@pytest.mark.parametrize( | ||
"path, no_nsm, with_nsm", | ||
[ | ||
(~RDF.type, f"^<{RDF.type}>", "^rdf:type"), | ||
( | ||
RDF.type / RDFS.subClassOf, | ||
f"<{RDF.type}>/<{RDFS.subClassOf}>", | ||
"rdf:type/rdfs:subClassOf", | ||
), | ||
( | ||
RDF.type | RDFS.subClassOf, | ||
f"<{RDF.type}>|<{RDFS.subClassOf}>", | ||
"rdf:type|rdfs:subClassOf", | ||
), | ||
(-RDF.type, f"!(<{RDF.type}>)", "!(rdf:type)"), | ||
(RDFS.subClassOf * ZeroOrMore, f"<{RDFS.subClassOf}>*", "rdfs:subClassOf*"), | ||
(RDFS.subClassOf * OneOrMore, f"<{RDFS.subClassOf}>+", "rdfs:subClassOf+"), | ||
(RDFS.subClassOf * ZeroOrOne, f"<{RDFS.subClassOf}>?", "rdfs:subClassOf?"), | ||
( | ||
RDF.type / RDFS.subClassOf * "*", | ||
f"<{RDF.type}>/<{RDFS.subClassOf}>*", | ||
"rdf:type/rdfs:subClassOf*", | ||
), | ||
( | ||
-(RDF.type | RDFS.subClassOf), | ||
f"!(<{RDF.type}>|<{RDFS.subClassOf}>)", | ||
"!(rdf:type|rdfs:subClassOf)", | ||
), | ||
], | ||
) | ||
def test_paths_n3(path, no_nsm, with_nsm): | ||
assert path.n3() == no_nsm | ||
assert path.n3(nsm) == with_nsm |