Skip to content
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
16 changes: 0 additions & 16 deletions core/esmf-aspect-meta-model-python/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -218,19 +218,3 @@ poetry run tox -e pep8
# run tests
poetry run tox -e py310
```

## GitHub actions

There are two actions on the GitHub repo:
- [Check New Pull Request](../../.github/workflows/push_request_check.yml)
- [Build release](../../.github/workflows/tagged_release.yml)

### Check New Pull Request
This action run after creation or updating a pull request and run all automation tests with tox command.

### Build release
Prepare and publish a new release for the `esmf-aspect-model-loader` to the PyPi:
[esmf-aspect-model-loader](https://pypi.org/project/esmf-aspect-model-loader/.)

A list of the available releases on the GitHub:
[Releases](https://github.com/eclipse-esmf/esmf-sdk-py-aspect-model-loader/releases).
Original file line number Diff line number Diff line change
Expand Up @@ -49,13 +49,14 @@ def __to_enum_node_value(self, value_node: Node) -> typing.Dict:
- If value_node is a URIRef it will represent a value of a ComplexType
:return: the one generated value of the enumeration
"""
value = {}

if isinstance(value_node, rdflib.Literal):
# value represents a simple data type
return value_node.toPython()
value = value_node.toPython()

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

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

return value

def __is_collection_value(self, property_subject: str) -> bool:
characteristic = self._aspect_graph.value( # type: ignore
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,11 @@ def to_python(self, aspect_urn: URIRef | str = "") -> List[Aspect]:
"""Convert SAMM graph to Python objects."""
base_nodes = self.get_base_nodes(aspect_urn)
if not base_nodes:
raise ValueError(f"Could not found Aspect node by the URN {aspect_urn}.")
error_message = "Could not found Aspect node in the model"
if aspect_urn:
error_message += f" by the URN {aspect_urn}"

raise ValueError(error_message)

model_element_factory = ModelElementFactory(self._samm_version, self._graph, self._cache)
aspect_elements = model_element_factory.create_all_graph_elements(base_nodes)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ def _validate_samm_version(samm_version: str):
"""
if not samm_version:
raise ValueError("SAMM version not found in the Graph.")
elif samm_version != SammUnitsGraph.SAMM_VERSION:
elif samm_version > SammUnitsGraph.SAMM_VERSION:
raise ValueError(f"{samm_version} is not supported SAMM version.")

def _get_samm_version_from_graph(self):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ def test_to_enum_node_value_node_is_URIRef_not_collection_value(self, isinstance

@mock.patch("esmf_aspect_meta_model_python.loader.instantiator.enumeration_instantiator.isinstance")
def test_to_enum_node_value_node_is_URIRef_raise_exception(self, isinstance_mock):
isinstance_mock.side_effect = (False, False)
isinstance_mock.side_effect = (False, False, False)
base_class_mock = mock.MagicMock(name="EnumerationInstantiator_class")
with pytest.raises(TypeError) as error:
EnumerationInstantiator._EnumerationInstantiator__to_enum_node_value(base_class_mock, "value_node")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,9 @@ def test_validate_samm_version_no_version(self):
def test_validate_samm_version_not_supported_version(self, samm_units_graph_mock):
samm_units_graph_mock.SAMM_VERSION = "2"
with pytest.raises(ValueError) as error:
ResolverInterface._validate_samm_version("1")
ResolverInterface._validate_samm_version("3")

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

def test_get_samm_version_from_graph(self):
graph_mock = mock.MagicMock(name="graph")
Expand Down