From 79a360cf15cb27d26d8085257c627d373732d721 Mon Sep 17 00:00:00 2001 From: zrgt Date: Wed, 8 Nov 2023 19:16:16 +0100 Subject: [PATCH] Fix of namespace and its tests - Use correct constraint ids for each NamespaceSet in tests, use 000 if not constraint id is suitable --- basyx/aas/model/base.py | 13 +++++++------ test/model/test_base.py | 6 +++--- 2 files changed, 10 insertions(+), 9 deletions(-) diff --git a/basyx/aas/model/base.py b/basyx/aas/model/base.py index 9d582a091..80060d68c 100644 --- a/basyx/aas/model/base.py +++ b/basyx/aas/model/base.py @@ -1767,10 +1767,10 @@ def remove_object_by_semantic_id(self, semantic_id: Reference) -> None: # TODO: Find a better solution for providing constraint ids ATTRIBUTES_CONSTRAINT_IDS = { - "id_short": 117, # Referable, + "id_short": 22, # Referable, "type": 21, # Qualifier, "name": 77, # Extension, - "semantic_id": 134, # model.OperationVariable + # "id_short": 134, # model.OperationVariable } @@ -1891,7 +1891,7 @@ def _validate_namespace_constraints(self, element: _NSO): if hasattr(element, key_attr_name): key_attr_value = self._get_attribute(element, key_attr_name, case_sensitive) self._check_attr_is_not_none(element, key_attr_name, key_attr_value) - self._check_value_is_not_in_backend(key_attr_name, key_attr_value, backend_dict, set_) + self._check_value_is_not_in_backend(element, key_attr_name, key_attr_value, backend_dict, set_) def _check_attr_is_not_none(self, element: _NSO, attr_name: str, attr): if attr is None: @@ -1901,13 +1901,14 @@ def _check_attr_is_not_none(self, element: _NSO, attr_name: str, attr): else: raise ValueError(f"{element!r} has attribute {attr_name}=None, which is not allowed!") - def _check_value_is_not_in_backend(self, attr_name: str, attr, backend_dict: Dict, set_: "NamespaceSet"): + def _check_value_is_not_in_backend(self, element: _NSO, attr_name: str, attr, + backend_dict: Dict[ATTRIBUTE_TYPES, _NSO], set_: "NamespaceSet"): if attr in backend_dict: if set_ is self: - text = f"Object with attribute (name='{attr_name}', value='{attr}') " \ + text = f"Object with attribute (name='{attr_name}', value='{getattr(element, attr_name)}') " \ f"is already present in this set of objects" else: - text = f"Object with attribute (name='{attr_name}', value='{attr}') " \ + text = f"Object with attribute (name='{attr_name}', value='{getattr(element, attr_name)}') " \ f"is already present in another set in the same namespace" raise AASConstraintViolation(ATTRIBUTES_CONSTRAINT_IDS.get(attr_name, 0), text) diff --git a/test/model/test_base.py b/test/model/test_base.py index ef894de50..13db21f95 100644 --- a/test/model/test_base.py +++ b/test/model/test_base.py @@ -374,7 +374,7 @@ def test_NamespaceSet(self) -> None: self.assertEqual( "Object with attribute (name='semantic_id', value='ExternalReference(key=(Key(" "type=GLOBAL_REFERENCE, value=http://acplt.org/Test1),))') is already present in this set of objects " - "(Constraint AASd-022)", + "(Constraint AASd-000)", str(cm.exception)) self.namespace.set2.add(self.prop5) self.namespace.set2.add(self.prop6) @@ -389,7 +389,7 @@ def test_NamespaceSet(self) -> None: self.assertEqual( "Object with attribute (name='semantic_id', value='" "ExternalReference(key=(Key(type=GLOBAL_REFERENCE, value=http://acplt.org/Test1),))')" - " is already present in another set in the same namespace (Constraint AASd-022)", + " is already present in another set in the same namespace (Constraint AASd-000)", str(cm.exception)) self.assertIs(self.prop1, self.namespace.set1.get("id_short", "Prop1")) @@ -456,7 +456,7 @@ def test_NamespaceSet(self) -> None: with self.assertRaises(model.AASConstraintViolation) as cm: self.namespace3.set1.add(self.qualifier1alt) self.assertEqual("Object with attribute (name='type', value='type1') is already present in this set " - "of objects (Constraint AASd-022)", + "of objects (Constraint AASd-021)", str(cm.exception)) def test_namespaceset_hooks(self) -> None: