summaryrefslogtreecommitdiff
path: root/test/test_namespace/test_namespacemanager.py
diff options
context:
space:
mode:
authorIwan Aucamp <aucampia@gmail.com>2023-03-26 12:53:29 +0200
committerGitHub <noreply@github.com>2023-03-26 12:53:29 +0200
commit57bb42886b57a37f1ba93a4d1b52651d978d049c (patch)
treeac75957fa29dc49c39618b01fcc9dda29bcb4ea9 /test/test_namespace/test_namespacemanager.py
parent4da67f9a17ffe8fa128afcdd2259e337bccafaa3 (diff)
downloadrdflib-57bb42886b57a37f1ba93a4d1b52651d978d049c.tar.gz
fix: restore the 6.1.1 default bound namespaces (#2313)
The namespaces bound by default by `rdflib.graph.Graph` and `rdflib.namespace.NamespaceManager` was reduced in version 6.2.0 of RDFLib, however, this also would cause code that worked with 6.1.1 to break, so this constituted a breaking change. This change restores the previous behaviour, binding the same namespaces as was bound in 6.1.1. To bind a reduced set of namespaces, the `bind_namespaces` parameter of `rdflib.graph.Graph` or `rdflib.namespace.NamespaceManager` can be used. - Closes <https://github.com/RDFLib/rdflib/issues/2103>.
Diffstat (limited to 'test/test_namespace/test_namespacemanager.py')
-rw-r--r--test/test_namespace/test_namespacemanager.py96
1 files changed, 91 insertions, 5 deletions
diff --git a/test/test_namespace/test_namespacemanager.py b/test/test_namespace/test_namespacemanager.py
index d79f0419..20cb9594 100644
--- a/test/test_namespace/test_namespacemanager.py
+++ b/test/test_namespace/test_namespacemanager.py
@@ -33,9 +33,41 @@ def test_core_prefixes_bound():
g = Graph()
# prefixes in Graph
- assert len(list(g.namespaces())) == len(_NAMESPACE_PREFIXES_CORE)
+ assert len(list(g.namespaces())) == len(
+ {**_NAMESPACE_PREFIXES_RDFLIB, **_NAMESPACE_PREFIXES_CORE}
+ )
pre = sorted([x[0] for x in list(g.namespaces())])
- assert pre == ["owl", "rdf", "rdfs", "xml", "xsd"]
+ assert pre == [
+ "brick",
+ "csvw",
+ "dc",
+ "dcam",
+ "dcat",
+ "dcmitype",
+ "dcterms",
+ "doap",
+ "foaf",
+ "geo",
+ "odrl",
+ "org",
+ "owl",
+ "prof",
+ "prov",
+ "qb",
+ "rdf",
+ "rdfs",
+ "schema",
+ "sh",
+ "skos",
+ "sosa",
+ "ssn",
+ "time",
+ "vann",
+ "void",
+ "wgs",
+ "xml",
+ "xsd",
+ ]
def test_rdflib_prefixes_bound():
@@ -176,6 +208,40 @@ def test_nman_bind_namespaces(
["selector", "expected_bindings"],
[
(
+ None,
+ {
+ "brick": "https://brickschema.org/schema/Brick#",
+ "csvw": "http://www.w3.org/ns/csvw#",
+ "dc": "http://purl.org/dc/elements/1.1/",
+ "dcat": "http://www.w3.org/ns/dcat#",
+ "dcmitype": "http://purl.org/dc/dcmitype/",
+ "dcterms": "http://purl.org/dc/terms/",
+ "dcam": "http://purl.org/dc/dcam/",
+ "doap": "http://usefulinc.com/ns/doap#",
+ "foaf": "http://xmlns.com/foaf/0.1/",
+ "odrl": "http://www.w3.org/ns/odrl/2/",
+ "geo": "http://www.opengis.net/ont/geosparql#",
+ "org": "http://www.w3.org/ns/org#",
+ "owl": "http://www.w3.org/2002/07/owl#",
+ "prof": "http://www.w3.org/ns/dx/prof/",
+ "prov": "http://www.w3.org/ns/prov#",
+ "qb": "http://purl.org/linked-data/cube#",
+ "rdf": "http://www.w3.org/1999/02/22-rdf-syntax-ns#",
+ "rdfs": "http://www.w3.org/2000/01/rdf-schema#",
+ "schema": "https://schema.org/",
+ "sh": "http://www.w3.org/ns/shacl#",
+ "skos": "http://www.w3.org/2004/02/skos/core#",
+ "sosa": "http://www.w3.org/ns/sosa/",
+ "ssn": "http://www.w3.org/ns/ssn/",
+ "time": "http://www.w3.org/2006/time#",
+ "vann": "http://purl.org/vocab/vann/",
+ "void": "http://rdfs.org/ns/void#",
+ "wgs": "https://www.w3.org/2003/01/geo/wgs84_pos#",
+ "xsd": "http://www.w3.org/2001/XMLSchema#",
+ "xml": "http://www.w3.org/XML/1998/namespace",
+ },
+ ),
+ (
"rdflib",
{
"brick": "https://brickschema.org/schema/Brick#",
@@ -208,19 +274,39 @@ def test_nman_bind_namespaces(
"xsd": "http://www.w3.org/2001/XMLSchema#",
"xml": "http://www.w3.org/XML/1998/namespace",
},
- )
+ ),
+ (
+ "core",
+ {
+ "owl": "http://www.w3.org/2002/07/owl#",
+ "rdf": "http://www.w3.org/1999/02/22-rdf-syntax-ns#",
+ "rdfs": "http://www.w3.org/2000/01/rdf-schema#",
+ "xsd": "http://www.w3.org/2001/XMLSchema#",
+ "xml": "http://www.w3.org/XML/1998/namespace",
+ },
+ ),
],
)
def test_bound_namespaces_subset(
- selector: Any, expected_bindings: Dict[str, str]
+ selector: Optional[Any], expected_bindings: Dict[str, str]
) -> None:
- graph = Graph(bind_namespaces=selector)
+ if selector is not None:
+ graph = Graph(bind_namespaces=selector)
+ else:
+ graph = Graph()
bound_namespaces = dict(
(key, str(value)) for key, value in graph.namespace_manager.namespaces()
)
assert (
expected_bindings.items() <= bound_namespaces.items()
), f"missing items {expected_bindings.items() - bound_namespaces.items()}"
+ empty_graph = Graph(bind_namespaces="none")
+ if selector is not None:
+ nman = NamespaceManager(empty_graph, bind_namespaces=selector)
+ else:
+ nman = NamespaceManager(empty_graph)
+ nman_bound_namespaces = dict((key, str(value)) for key, value in nman.namespaces())
+ assert bound_namespaces == nman_bound_namespaces
def test_compute_qname_no_generate() -> None: