Skip to content

Commit 88710a6

Browse files
authored
Merge pull request #51 from bci-oss/fix-datatype-bug
Fix error: update enumeration instantiator logic
2 parents 8642428 + d3061d3 commit 88710a6

File tree

6 files changed

+20
-29
lines changed

6 files changed

+20
-29
lines changed

core/esmf-aspect-meta-model-python/README.md

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -218,19 +218,3 @@ poetry run tox -e pep8
218218
# run tests
219219
poetry run tox -e py310
220220
```
221-
222-
## GitHub actions
223-
224-
There are two actions on the GitHub repo:
225-
- [Check New Pull Request](../../.github/workflows/push_request_check.yml)
226-
- [Build release](../../.github/workflows/tagged_release.yml)
227-
228-
### Check New Pull Request
229-
This action run after creation or updating a pull request and run all automation tests with tox command.
230-
231-
### Build release
232-
Prepare and publish a new release for the `esmf-aspect-model-loader` to the PyPi:
233-
[esmf-aspect-model-loader](https://pypi.org/project/esmf-aspect-model-loader/.)
234-
235-
A list of the available releases on the GitHub:
236-
[Releases](https://github.com/eclipse-esmf/esmf-sdk-py-aspect-model-loader/releases).

core/esmf-aspect-meta-model-python/esmf_aspect_meta_model_python/loader/instantiator/enumeration_instantiator.py

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -49,13 +49,14 @@ def __to_enum_node_value(self, value_node: Node) -> typing.Dict:
4949
- If value_node is a URIRef it will represent a value of a ComplexType
5050
:return: the one generated value of the enumeration
5151
"""
52+
value = {}
53+
5254
if isinstance(value_node, rdflib.Literal):
5355
# value represents a simple data type
54-
return value_node.toPython()
56+
value = value_node.toPython()
5557

5658
elif isinstance(value_node, rdflib.URIRef):
5759
# value represents a complex data type
58-
value = {}
5960
value_node_properties = self._aspect_graph.predicate_objects(value_node)
6061
for property_urn, property_value in value_node_properties:
6162
if property_urn != rdflib.RDF.type and isinstance(property_urn, str):
@@ -70,14 +71,16 @@ def __to_enum_node_value(self, value_node: Node) -> typing.Dict:
7071
value_node_name = value_node.split("#")[1]
7172
value_key = self._samm.get_urn(SAMM.name).toPython()
7273
value[value_key] = value_node_name # type: ignore
73-
return value
7474

7575
else:
76-
# illegal node type for enumeration value (e.g., Blank Node)
77-
raise TypeError(
78-
f"Every value of an enumeration must either be a Literal (string, int, etc.) or "
79-
f"a URI reference to a ComplexType. Values of type {type(value_node).__name__} are not allowed"
80-
)
76+
if not isinstance(value_node, rdflib.term.BNode) or value_node == rdflib.namespace.RDF.nil:
77+
# illegal node type for enumeration value (e.g., Blank Node)
78+
raise TypeError(
79+
f"Every value of an enumeration must either be a Literal (string, int, etc.) or "
80+
f"a URI reference to a ComplexType. Values of type {type(value_node).__name__} are not allowed"
81+
)
82+
83+
return value
8184

8285
def __is_collection_value(self, property_subject: str) -> bool:
8386
characteristic = self._aspect_graph.value( # type: ignore

core/esmf-aspect-meta-model-python/esmf_aspect_meta_model_python/loader/samm_graph.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,11 @@ def to_python(self, aspect_urn: URIRef | str = "") -> List[Aspect]:
107107
"""Convert SAMM graph to Python objects."""
108108
base_nodes = self.get_base_nodes(aspect_urn)
109109
if not base_nodes:
110-
raise ValueError(f"Could not found Aspect node by the URN {aspect_urn}.")
110+
error_message = "Could not found Aspect node in the model"
111+
if aspect_urn:
112+
error_message += f" by the URN {aspect_urn}"
113+
114+
raise ValueError(error_message)
111115

112116
model_element_factory = ModelElementFactory(self._samm_version, self._graph, self._cache)
113117
aspect_elements = model_element_factory.create_all_graph_elements(base_nodes)

core/esmf-aspect-meta-model-python/esmf_aspect_meta_model_python/resolver/base.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ def _validate_samm_version(samm_version: str):
7676
"""
7777
if not samm_version:
7878
raise ValueError("SAMM version not found in the Graph.")
79-
elif samm_version != SammUnitsGraph.SAMM_VERSION:
79+
elif samm_version > SammUnitsGraph.SAMM_VERSION:
8080
raise ValueError(f"{samm_version} is not supported SAMM version.")
8181

8282
def _get_samm_version_from_graph(self):

core/esmf-aspect-meta-model-python/tests/unit/loader/instantiators/test_enumeration_instantiator.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ def test_to_enum_node_value_node_is_URIRef_not_collection_value(self, isinstance
136136

137137
@mock.patch("esmf_aspect_meta_model_python.loader.instantiator.enumeration_instantiator.isinstance")
138138
def test_to_enum_node_value_node_is_URIRef_raise_exception(self, isinstance_mock):
139-
isinstance_mock.side_effect = (False, False)
139+
isinstance_mock.side_effect = (False, False, False)
140140
base_class_mock = mock.MagicMock(name="EnumerationInstantiator_class")
141141
with pytest.raises(TypeError) as error:
142142
EnumerationInstantiator._EnumerationInstantiator__to_enum_node_value(base_class_mock, "value_node")

core/esmf-aspect-meta-model-python/tests/unit/resolver/test_base.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,9 @@ def test_validate_samm_version_no_version(self):
3232
def test_validate_samm_version_not_supported_version(self, samm_units_graph_mock):
3333
samm_units_graph_mock.SAMM_VERSION = "2"
3434
with pytest.raises(ValueError) as error:
35-
ResolverInterface._validate_samm_version("1")
35+
ResolverInterface._validate_samm_version("3")
3636

37-
assert str(error.value) == "1 is not supported SAMM version."
37+
assert str(error.value) == "3 is not supported SAMM version."
3838

3939
def test_get_samm_version_from_graph(self):
4040
graph_mock = mock.MagicMock(name="graph")

0 commit comments

Comments
 (0)