Skip to content

Commit

Permalink
fix: reference to global inside get_target_namespace_elements (#2311)
Browse files Browse the repository at this point in the history
`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 <#2072>.
  • Loading branch information
aucampia committed Mar 25, 2023
1 parent d7883eb commit 4da67f9
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
2 changes: 1 addition & 1 deletion rdflib/tools/defined_namespace_creator.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
15 changes: 15 additions & 0 deletions test/test_namespace/test_definednamespace_creator.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@
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():
"""
Expand Down Expand Up @@ -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]

0 comments on commit 4da67f9

Please sign in to comment.