From 776bbda9e5fc13555e22ef7c8fe016dd6beae7d8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Leon=20M=C3=B6ller?= Date: Wed, 13 Mar 2024 23:57:05 +0100 Subject: [PATCH 1/2] adapter.xml: change type of an exception to `AssertionError` The respective exception marks an error in the program, which should correctly be an `AssertionError`. --- basyx/aas/adapter/xml/xml_deserialization.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/basyx/aas/adapter/xml/xml_deserialization.py b/basyx/aas/adapter/xml/xml_deserialization.py index 31b5012fb..298ea6291 100644 --- a/basyx/aas/adapter/xml/xml_deserialization.py +++ b/basyx/aas/adapter/xml/xml_deserialization.py @@ -315,8 +315,8 @@ def _failsafe_construct_mandatory(element: etree.Element, constructor: Callable[ """ constructed = _failsafe_construct(element, constructor, False, **kwargs) if constructed is None: - raise TypeError("The result of a non-failsafe _failsafe_construct() call was None! " - "This is a bug in the Eclipse BaSyx Python SDK XML deserialization, please report it!") + raise AssertionError("The result of a non-failsafe _failsafe_construct() call was None! " + "This is a bug in the Eclipse BaSyx Python SDK XML deserialization, please report it!") return constructed From cbad1284ac69c0b9c19134353d5d5f48ecd41f42 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Leon=20M=C3=B6ller?= Date: Wed, 13 Mar 2024 23:59:37 +0100 Subject: [PATCH 2/2] test.adapter.xml: test deserialization without namespace prefixes --- test/adapter/xml/test_xml_deserialization.py | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/test/adapter/xml/test_xml_deserialization.py b/test/adapter/xml/test_xml_deserialization.py index 4ff06aa60..cf0814d13 100644 --- a/test/adapter/xml/test_xml_deserialization.py +++ b/test/adapter/xml/test_xml_deserialization.py @@ -333,6 +333,22 @@ def test_read_aas_xml_element(self) -> None: submodel = read_aas_xml_element(bytes_io, XMLConstructables.SUBMODEL) self.assertIsInstance(submodel, model.Submodel) + def test_no_namespace_prefix(self) -> None: + def xml(id_: str) -> str: + return f""" + + + + {id_} + + + + """ + + self._assertInExceptionAndLog(xml(""), f'{{{XML_NS_MAP["aas"]}}}id on line 5 has no text', KeyError, + logging.ERROR) + read_aas_xml_file(io.StringIO(xml("urn:x-test:test-submodel"))) + class XmlDeserializationStrippedObjectsTest(unittest.TestCase): def test_stripped_qualifiable(self) -> None: