Skip to content

Commit 6cc824b

Browse files
Update pipeline
1 parent 0867eb7 commit 6cc824b

File tree

5 files changed

+73
-71
lines changed

5 files changed

+73
-71
lines changed

.github/workflows/push_request_check.yml

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,16 @@ jobs:
4242
cd core/esmf-aspect-meta-model-python
4343
poetry run download-test-models
4444
45-
- name: run tests
45+
- name: check test models
46+
run: |
47+
cd core/esmf-aspect-meta-model-python/tests/integration/java_models/resources
48+
ls
49+
cd valid
50+
ls
51+
cd org.eclipse.esmf.test
52+
ls
53+
54+
- name: run test*s
4655
run: |
4756
cd core/esmf-aspect-meta-model-python
4857
poetry run tox -e py310

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

Lines changed: 22 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
#
1010
# SPDX-License-Identifier: MPL-2.0
1111

12-
import typing
12+
from typing import Any, Dict, List, Optional, Union
1313

1414
import rdflib # type: ignore
1515

@@ -40,7 +40,7 @@ def _create_instance(self, element_node: Node) -> Enumeration:
4040

4141
return DefaultEnumeration(meta_model_base_attributes, data_type, values)
4242

43-
def __to_enum_node_value(self, value_node: Node) -> typing.Dict:
43+
def __to_enum_node_value(self, value_node: Node) -> Union[Dict, str]:
4444
"""
4545
This method instantiates one possible value of an enumeration.
4646
:param value_node: Node of the Graph that represents one enumeration value.
@@ -49,36 +49,37 @@ 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 = {}
52+
str_value: str = ""
53+
dict_value: Dict = {}
5354

54-
if isinstance(value_node, rdflib.Literal):
55+
if isinstance(value_node, rdflib.Literal) or (
56+
isinstance(value_node, rdflib.URIRef) and value_node.find("#") == -1
57+
):
5558
# value represents a simple data type
56-
value = value_node.toPython()
59+
str_value = value_node.toPython()
5760

5861
elif isinstance(value_node, rdflib.URIRef) or isinstance(value_node, rdflib.term.BNode):
5962
# value represents a complex data type
60-
value_node_properties = self._aspect_graph.predicate_objects(value_node)
61-
for property_urn, property_value in value_node_properties:
63+
dict_value = {}
64+
65+
for property_urn, property_value in self._aspect_graph.predicate_objects(value_node):
6266
if property_urn != rdflib.RDF.type and isinstance(property_urn, str):
6367
property_name = property_urn.split("#")[1]
64-
actual_value: typing.Optional[typing.Any]
68+
69+
actual_value: Optional[Any]
6570
if self.__is_collection_value(property_urn):
6671
actual_value = self.__instantiate_enum_collection(property_value)
6772
else:
6873
actual_value = self.__to_enum_node_value(property_value)
6974

7075
if property_name == "see":
71-
value.setdefault(property_name, []).append(actual_value)
76+
dict_value.setdefault(property_name, []).append(actual_value)
7277
else:
73-
value[property_name] = actual_value
78+
dict_value[property_name] = actual_value
7479

75-
if isinstance(value_node, rdflib.URIRef):
76-
if value_node.find("#") == -1:
77-
value = value_node.toPython()
78-
else:
79-
value_node_name = value_node.split("#")[1]
80-
value_key = self._samm.get_urn(SAMM.name).toPython()
81-
value[value_key] = value_node_name # type: ignore
80+
value_node_name = value_node.split("#")[1]
81+
value_key = self._samm.get_urn(SAMM.name).toPython()
82+
dict_value[value_key] = value_node_name # type: ignore
8283

8384
elif value_node == rdflib.namespace.RDF.nil:
8485
# illegal node type for enumeration value (e.g., Blank Node)
@@ -87,21 +88,23 @@ def __to_enum_node_value(self, value_node: Node) -> typing.Dict:
8788
f"a URI reference to a ComplexType. Values of type {type(value_node).__name__} are not allowed"
8889
)
8990

90-
return value
91+
return str_value or dict_value
9192

9293
def __is_collection_value(self, property_subject: str) -> bool:
9394
characteristic = self._aspect_graph.value( # type: ignore
9495
subject=property_subject,
9596
predicate=self._samm.get_urn(SAMM.characteristic),
9697
)
9798
characteristic_type = self._aspect_graph.value(subject=characteristic, predicate=rdflib.RDF.type)
99+
98100
return characteristic_type in self._sammc.collections_urns()
99101

100-
def __instantiate_enum_collection(self, value_list) -> typing.List[typing.Dict]:
102+
def __instantiate_enum_collection(self, value_list) -> List[Union[Dict, str]]:
101103
"""creates a collection as a child for enumeration characteristics"""
102104
value_node_list = RdfHelper.get_rdf_list_values(value_list, self._aspect_graph)
103105
values = []
104106
for value_node in value_node_list:
105107
value = self.__to_enum_node_value(value_node)
106108
values.append(value)
109+
107110
return values

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,10 @@
99
#
1010
# SPDX-License-Identifier: MPL-2.0
1111

12-
from rdflib.term import Node
1312
from typing import Any
1413

14+
from rdflib.term import Node
15+
1516
from esmf_aspect_meta_model_python.base.value import Value
1617
from esmf_aspect_meta_model_python.impl.default_value import DefaultValue
1718
from esmf_aspect_meta_model_python.loader.instantiator_base import InstantiatorBase

core/esmf-aspect-meta-model-python/tests/integration/java_models/test_loading_aspects.py

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,10 @@
1212
from scripts.constants import TestModelConstants
1313
from scripts.download_test_models import download_test_models
1414

15-
1615
# before start tests, download latest aspect test models with the next command
1716
# poetry run download-test-models
1817

18+
1919
def get_resources_folder_path() -> str:
2020
"""Get a path for storing test models."""
2121
base_path = Path(__file__).parents[3].absolute()
@@ -35,7 +35,7 @@ def check_resources_folder():
3535
def get_test_files():
3636
"""Get ttl models for testing."""
3737
resources_folder = get_resources_folder_path()
38-
search_pattern = join(resources_folder, TestModelConstants.FOLDER_TO_EXTRACT, '**', '*.ttl')
38+
search_pattern = join(resources_folder, TestModelConstants.FOLDER_TO_EXTRACT, "**", "*.ttl")
3939
test_model_files = glob(search_pattern, recursive=True)
4040

4141
return test_model_files
@@ -62,7 +62,7 @@ def check_load_aspect_model(test_models):
6262
terminal_width = get_terminal_width()
6363
message = " SAMMGraph.load_aspect_model "
6464
fill_num = round((terminal_width - len(message)) / 2)
65-
print("="*fill_num, message, "="*(terminal_width - len(message) - fill_num), "\n", sep="")
65+
print("=" * fill_num, message, "=" * (terminal_width - len(message) - fill_num), "\n", sep="")
6666

6767
for i, model_path in enumerate(test_models):
6868
model_name = os.path.splitext(os.path.basename(model_path))[0]
@@ -78,10 +78,12 @@ def check_load_aspect_model(test_models):
7878
except Exception as error:
7979
status = "\033[91mFAILED\033[0m"
8080
report["failed"] += 1
81-
report["errors"].append({
82-
"model_name": model_name,
83-
"error": error,
84-
})
81+
report["errors"].append(
82+
{
83+
"model_name": model_name,
84+
"error": error,
85+
}
86+
)
8587
else:
8688
status = "\033[92mSUCCESS\033[0m"
8789
report["passed"] += 1
@@ -124,10 +126,12 @@ def check_load_model_elements(test_models):
124126
except Exception as error:
125127
status = "\033[91mFAILED\033[0m"
126128
report["failed"] += 1
127-
report["errors"].append({
128-
"model_name": model_name,
129-
"error": error,
130-
})
129+
report["errors"].append(
130+
{
131+
"model_name": model_name,
132+
"error": error,
133+
}
134+
)
131135
else:
132136
status = "\033[92mSUCCESS\033[0m"
133137
report["passed"] += 1

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

Lines changed: 24 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,18 @@ def test_to_enum_node_value_node_is_literal(self, isinstance_mock):
6262
assert result == "node_value"
6363
value_node_mock.toPython.assert_called_once()
6464

65+
@mock.patch("esmf_aspect_meta_model_python.loader.instantiator.enumeration_instantiator.isinstance")
66+
def test_to_enum_node_value_node_is_ref(self, isinstance_mock):
67+
isinstance_mock.side_effect = (False, True)
68+
base_class_mock = mock.MagicMock(name="EnumerationInstantiator_class")
69+
value_node_mock = mock.MagicMock(name="value_node")
70+
value_node_mock.find.return_value = -1
71+
value_node_mock.toPython.return_value = "node_value"
72+
result = EnumerationInstantiator._EnumerationInstantiator__to_enum_node_value(base_class_mock, value_node_mock)
73+
74+
assert result == "node_value"
75+
value_node_mock.toPython.assert_called_once()
76+
6577
@mock.patch("esmf_aspect_meta_model_python.loader.instantiator.enumeration_instantiator.isinstance")
6678
def test_to_enum_node_value_node_is_URIRef_collection_value(self, isinstance_mock):
6779
isinstance_mock.side_effect = (False, True, True, True)
@@ -126,47 +138,20 @@ def test_to_enum_node_value_with_see_property(self, isinstance_mock):
126138
assert "value_key" in result
127139
assert result["value_key"] == "value_node_name"
128140
aspect_graph_mock.predicate_objects.assert_called_once_with("value_node#value_node_name")
129-
base_class_mock._EnumerationInstantiator__is_collection_value.assert_has_calls([
130-
mock.call("property_urn#see"),
131-
mock.call("property_urn#see"),
132-
])
133-
base_class_mock._EnumerationInstantiator__to_enum_node_value.assert_has_calls([
134-
mock.call("property_value_1"),
135-
mock.call("property_value_2"),
136-
])
137-
samm_mock.get_urn.assert_called_once_with(SAMM.name)
138-
value_mock.toPython.assert_called_once()
139-
140-
@mock.patch("esmf_aspect_meta_model_python.loader.instantiator.enumeration_instantiator.isinstance")
141-
def test_to_enum_node_value_node_is_URIRef_not_collection_value(self, isinstance_mock):
142-
isinstance_mock.side_effect = (False, True, True, True)
143-
base_class_mock = mock.MagicMock(name="EnumerationInstantiator_class")
144-
base_class_mock._EnumerationInstantiator__is_collection_value.return_value = False
145-
base_class_mock._EnumerationInstantiator__to_enum_node_value.return_value = "some_value"
146-
aspect_graph_mock = mock.MagicMock(name="aspect_graph")
147-
aspect_graph_mock.predicate_objects.return_value = [
148-
("property_urn#property_name", "property_value"),
149-
]
150-
base_class_mock._aspect_graph = aspect_graph_mock
151-
samm_mock = mock.MagicMock(name="SAMM")
152-
value_node_mock = mock.MagicMock(name="value_node")
153-
value_node_mock.find.return_value = -1
154-
value_node_mock.toPython.return_value = "value_node"
155-
result = EnumerationInstantiator._EnumerationInstantiator__to_enum_node_value(
156-
base_class_mock,
157-
value_node_mock,
158-
)
159-
160-
assert result == "value_node"
161-
aspect_graph_mock.predicate_objects.assert_called_once_with(value_node_mock)
162-
base_class_mock._EnumerationInstantiator__is_collection_value.assert_called_once_with(
163-
"property_urn#property_name",
141+
base_class_mock._EnumerationInstantiator__is_collection_value.assert_has_calls(
142+
[
143+
mock.call("property_urn#see"),
144+
mock.call("property_urn#see"),
145+
]
164146
)
165-
base_class_mock._EnumerationInstantiator__to_enum_node_value.assert_called_once_with(
166-
"property_value",
147+
base_class_mock._EnumerationInstantiator__to_enum_node_value.assert_has_calls(
148+
[
149+
mock.call("property_value_1"),
150+
mock.call("property_value_2"),
151+
]
167152
)
168-
value_node_mock.find.assert_called_once_with("#")
169-
value_node_mock.toPython.assert_called_once()
153+
samm_mock.get_urn.assert_called_once_with(SAMM.name)
154+
value_mock.toPython.assert_called_once()
170155

171156
@mock.patch("esmf_aspect_meta_model_python.loader.instantiator.enumeration_instantiator.isinstance")
172157
def test_to_enum_node_value_node_is_BNode(self, isinstance_mock):

0 commit comments

Comments
 (0)