From 4da67f9a17ffe8fa128afcdd2259e337bccafaa3 Mon Sep 17 00:00:00 2001 From: Iwan Aucamp Date: Sat, 25 Mar 2023 18:47:59 +0100 Subject: [PATCH] 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 . --- rdflib/tools/defined_namespace_creator.py | 2 +- .../test_definednamespace_creator.py | 15 +++++++++++++++ 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/rdflib/tools/defined_namespace_creator.py b/rdflib/tools/defined_namespace_creator.py index 1076cd6e0..dcc6a3be7 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 8866a05d9..3a76dbc18 100644 --- a/test/test_namespace/test_definednamespace_creator.py +++ b/test/test_namespace/test_definednamespace_creator.py @@ -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(): """ @@ -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]