Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

model.base: fix ModelReference.resolve() error messages for elements contained in SubmodelElementLists #128

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion basyx/aas/model/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -1012,13 +1012,14 @@ def resolve(self, provider_: "provider.AbstractObjectProvider") -> _RT:
# the `is_submodel_element_list` branch, but mypy doesn't infer types based on isinstance checks
# stored in boolean variables.
item = item.value[int(key.value)] # type: ignore
resolved_keys[-1] += f"[{key.value}]"
else:
item = item.get_referable(key.value)
resolved_keys.append(item.id_short)
except (KeyError, IndexError) as e:
raise KeyError("Could not resolve {} {} at {}".format(
"index" if is_submodel_element_list else "id_short", key.value, " / ".join(resolved_keys)))\
from e
resolved_keys.append(item.id_short)

# Check type
if not isinstance(item, self.type):
Expand Down
4 changes: 2 additions & 2 deletions test/model/test_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -832,7 +832,7 @@ def get_identifiable(self, identifier: Identifier) -> Identifiable:
model.Property)
with self.assertRaises(TypeError) as cm_3:
ref4.resolve(DummyObjectProvider())
self.assertEqual("Object retrieved at urn:x-test:submodel / list / collection / prop is not a Namespace",
self.assertEqual("Object retrieved at urn:x-test:submodel / list[0] / prop is not a Namespace",
str(cm_3.exception))

with self.assertRaises(AttributeError) as cm_4:
Expand Down Expand Up @@ -863,7 +863,7 @@ def get_identifiable(self, identifier: Identifier) -> Identifiable:

with self.assertRaises(KeyError) as cm_8:
ref8.resolve(DummyObjectProvider())
self.assertEqual("'Could not resolve id_short prop_false at urn:x-test:submodel / list / collection'",
self.assertEqual("'Could not resolve id_short prop_false at urn:x-test:submodel / list[0]'",
str(cm_8.exception))

with self.assertRaises(ValueError) as cm_9:
Expand Down
Loading