Skip to content

Commit

Permalink
Fix of namespace and its tests
Browse files Browse the repository at this point in the history
- Use correct constraint ids for each NamespaceSet in tests, use 000 if not constraint id is suitable
  • Loading branch information
zrgt committed Nov 8, 2023
1 parent a0184e5 commit ddc425b
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 9 deletions.
13 changes: 7 additions & 6 deletions basyx/aas/model/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -1771,10 +1771,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
}


Expand Down Expand Up @@ -1895,7 +1895,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:
Expand All @@ -1905,13 +1905,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)

Expand Down
6 changes: 3 additions & 3 deletions test/model/test_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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"))
Expand Down Expand Up @@ -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:
Expand Down

0 comments on commit ddc425b

Please sign in to comment.