Skip to content

Commit

Permalink
examples.data._helper: disable comparison of unordered `SubmodelEleme…
Browse files Browse the repository at this point in the history
…ntList`

Since direct children of `SubmodelElementList` don't have an identifying
attribute anymore (AASd-120), they cannot be compared because it is
impossible to know which SubmodelElement should be compared against
which other element. Maybe this can be implemented again in the future,
when hashing is implemented for all SubmodelElements, but for now we
raise a `NotImplementedError`.

A test-case for this behavior is added and `order_relevant` is set to
`true` in all example files.
  • Loading branch information
jkhsjdhjs committed Oct 12, 2023
1 parent 927f125 commit cc11346
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 17 deletions.
15 changes: 8 additions & 7 deletions basyx/aas/examples/data/_helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -386,13 +386,14 @@ def check_submodel_element_list_equal(self, object_: model.SubmodelElementList,
self.check_attribute_equal(object_, 'type_value_list_element', expected_value.type_value_list_element)
self.check_contained_element_length(object_, 'value', object_.type_value_list_element,
len(expected_value.value))
if object_.order_relevant:
# compare ordered
for se1, se2 in zip(object_.value, expected_value.value):
self._check_submodel_element(se1, se2)
else:
# compare unordered
self._check_submodel_elements_equal_unordered(object_, expected_value)
if not object_.order_relevant or not expected_value.order_relevant:
# It is impossible to compare SubmodelElementLists with order_relevant=False, since it is impossible
# to know which element should be compared against which other element.
raise NotImplementedError("A SubmodelElementList with order_relevant=False cannot be compared!")

# compare ordered
for se1, se2 in zip(object_.value, expected_value.value):
self._check_submodel_element(se1, se2)

def check_relationship_element_equal(self, object_: model.RelationshipElement,
expected_value: model.RelationshipElement):
Expand Down
4 changes: 2 additions & 2 deletions basyx/aas/examples/data/example_submodel_template.py
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,7 @@ def create_example_submodel_template() -> model.Submodel:
semantic_id_list_element=model.ExternalReference((model.Key(type_=model.KeyTypes.GLOBAL_REFERENCE,
value='http://acplt.org/SubmodelElementCollections/'
'ExampleSubmodelElementCollection'),)),
order_relevant=False,
order_relevant=True,
category='PARAMETER',
description=model.MultiLanguageTextType({'en-US': 'Example SubmodelElementList object',
'de': 'Beispiel SubmodelElementList Element'}),
Expand All @@ -267,7 +267,7 @@ def create_example_submodel_template() -> model.Submodel:
semantic_id_list_element=model.ExternalReference((model.Key(type_=model.KeyTypes.GLOBAL_REFERENCE,
value='http://acplt.org/SubmodelElementCollections/'
'ExampleSubmodelElementCollection'),)),
order_relevant=False,
order_relevant=True,
category='PARAMETER',
description=model.MultiLanguageTextType({'en-US': 'Example SubmodelElementList object',
'de': 'Beispiel SubmodelElementList Element'}),
Expand Down
2 changes: 1 addition & 1 deletion basyx/aas/model/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
from ..backend import backends

if TYPE_CHECKING:
from . import provider, submodel
from . import provider

DataTypeDefXsd = Type[datatypes.AnyXSDType]
ValueDataType = datatypes.AnyXSDType # any xsd atomic type (from .datatypes)
Expand Down
10 changes: 3 additions & 7 deletions test/examples/test_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,18 +103,14 @@ def test_submodel_element_list_checker(self):
# Don't set protected attributes like this in production code!
list_._order_relevant = False
checker = AASDataChecker(raise_immediately=False)
checker.check_submodel_element_list_equal(list_, list_expected)
with self.assertRaises(NotImplementedError) as cm:
checker.check_submodel_element_list_equal(list_, list_expected)
self.assertEqual("A SubmodelElementList with order_relevant=False cannot be compared!", str(cm.exception))
self.assertEqual(1, sum(1 for _ in checker.failed_checks))
checker_iterator = checker.failed_checks
self.assertEqual("FAIL: Attribute order_relevant of SubmodelElementList[test_list] must be == True "
"(value=False)", repr(next(checker_iterator)))

# Don't set protected attributes like this in production code!
list_expected._order_relevant = False
checker = AASDataChecker(raise_immediately=False)
checker.check_submodel_element_list_equal(list_, list_expected)
self.assertEqual(0, sum(1 for _ in checker.failed_checks))

# value_type_list_element
list_ = model.SubmodelElementList(
id_short='test_list',
Expand Down

0 comments on commit cc11346

Please sign in to comment.