summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorIwan Aucamp <aucampia@gmail.com>2023-03-25 18:47:59 +0100
committerGitHub <noreply@github.com>2023-03-25 18:47:59 +0100
commit4da67f9a17ffe8fa128afcdd2259e337bccafaa3 (patch)
treeedb2b7b078f7aa4502f74a5564ef779cb66a7a73
parentd7883eb494673d0fb09efa3bced983ebb48b6961 (diff)
downloadrdflib-4da67f9a17ffe8fa128afcdd2259e337bccafaa3.tar.gz
fix: reference to global inside `get_target_namespace_elements` (#2311)
`get_target_namespace_elements` references the `args` global, which is not defined if the function is called from outside the module. This commit fixes that instead referencing the argument passed to the function. - Closes <https://github.com/RDFLib/rdflib/issues/2072>.
-rw-r--r--rdflib/tools/defined_namespace_creator.py2
-rw-r--r--test/test_namespace/test_definednamespace_creator.py15
2 files changed, 16 insertions, 1 deletions
diff --git a/rdflib/tools/defined_namespace_creator.py b/rdflib/tools/defined_namespace_creator.py
index 1076cd6e..dcc6a3be 100644
--- a/rdflib/tools/defined_namespace_creator.py
+++ b/rdflib/tools/defined_namespace_creator.py
@@ -106,7 +106,7 @@ def get_target_namespace_elements(
for e in elements:
desc = e[1].replace("\n", " ")
elements_strs.append(
- f" {e[0].replace(args.target_namespace, '')}: URIRef # {desc}\n"
+ f" {e[0].replace(target_namespace, '')}: URIRef # {desc}\n"
)
return elements, elements_strs
diff --git a/test/test_namespace/test_definednamespace_creator.py b/test/test_namespace/test_definednamespace_creator.py
index 8866a05d..3a76dbc1 100644
--- a/test/test_namespace/test_definednamespace_creator.py
+++ b/test/test_namespace/test_definednamespace_creator.py
@@ -2,6 +2,9 @@ import subprocess
import sys
from pathlib import Path
+from rdflib.graph import Graph
+from rdflib.tools.defined_namespace_creator import get_target_namespace_elements
+
def test_definednamespace_creator_qb():
"""
@@ -163,3 +166,15 @@ def test_definednamespace_creator_multiple_comments():
# cleanup
Path.unlink(Path("_MULTILINESTRINGEXAMPLE.py"))
+
+
+def test_get_target_namespace_elements(rdfs_graph: Graph) -> None:
+ elements = get_target_namespace_elements(
+ rdfs_graph, "http://www.w3.org/2000/01/rdf-schema#"
+ )
+ assert 2 == len(elements)
+ assert 16 == len(elements[0])
+ assert (
+ "http://www.w3.org/2000/01/rdf-schema#Class",
+ "The class of classes.",
+ ) in elements[0]