Skip to content

Commit

Permalink
test_xml_deserialization: add tests for _tag_replace_namespace
Browse files Browse the repository at this point in the history
  • Loading branch information
JAB1305 committed Jul 12, 2024
1 parent ce1568f commit 8663890
Showing 1 changed file with 28 additions and 0 deletions.
28 changes: 28 additions & 0 deletions test/adapter/xml/test_xml_deserialization.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
from lxml import etree
from typing import Iterable, Type, Union

from basyx.aas.adapter.xml.xml_deserialization import _tag_replace_namespace


def _xml_wrap(xml: str) -> str:
return f'<aas:environment xmlns:aas="{XML_NS_MAP["aas"]}">{xml}</aas:environment>'
Expand Down Expand Up @@ -449,3 +451,29 @@ def construct_submodel(cls, element: etree._Element, object_class=EnhancedSubmod
self.assertIsInstance(submodel, EnhancedSubmodel)
assert isinstance(submodel, EnhancedSubmodel)
self.assertEqual(submodel.enhanced_attribute, "fancy!")


class TestTagReplaceNamespace(unittest.TestCase):
def test_known_namespace(self):
tag = '{https://admin-shell.io/aas/3/0}tag'
expected = 'aas:tag'
self.assertEqual(_tag_replace_namespace(tag, XML_NS_MAP), expected)

def test_empty_prefix(self):
# Empty prefix should not be replaced as otherwise it would apply everywhere
tag = '{https://admin-shell.io/aas/3/0}tag'
nsmap = {"": "https://admin-shell.io/aas/3/0"}
expected = '{https://admin-shell.io/aas/3/0}tag'
self.assertEqual(_tag_replace_namespace(tag, nsmap), expected)

def test_empty_namespace(self):
# Empty namespaces should also have no effect
tag = '{https://admin-shell.io/aas/3/0}tag'
nsmap = {"aas": ""}
expected = '{https://admin-shell.io/aas/3/0}tag'
self.assertEqual(_tag_replace_namespace(tag, nsmap), expected)

def test_unknown_namespace(self):
tag = '{http://unknownnamespace.com}unknown'
expected = '{http://unknownnamespace.com}unknown' # Unknown namespace should remain unchanged
self.assertEqual(_tag_replace_namespace(tag, XML_NS_MAP), expected)

0 comments on commit 8663890

Please sign in to comment.