Skip to content

Commit e1879a3

Browse files
Oleksandr Muzyka (EPAM)Oleksandr Muzyka (EPAM)
authored andcommitted
refactor: use default (latest) SAMM version and update tests
- Replaced SAMM version retrieval with default (latest) version - Updated integration tests from 2.1.0 → 2.2.0
1 parent 22d4318 commit e1879a3

File tree

83 files changed

+338
-450
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

83 files changed

+338
-450
lines changed

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

Lines changed: 5 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,13 @@
88
# file, You can obtain one at https://mozilla.org/MPL/2.0/.
99
#
1010
# SPDX-License-Identifier: MPL-2.0
11-
1211
from pathlib import Path
1312
from typing import List, Optional, Union
1413

1514
from rdflib import RDF, Graph, Node
1615

16+
import esmf_aspect_meta_model_python.constants as const
17+
1718
from esmf_aspect_meta_model_python import utils
1819
from esmf_aspect_meta_model_python.adaptive_graph import AdaptiveGraph
1920
from esmf_aspect_meta_model_python.base.aspect import Aspect
@@ -35,19 +36,15 @@ def __init__(self):
3536
self.samm_graph = Graph()
3637
self._cache = DefaultElementCache()
3738

38-
self.samm_version = None
39+
self.samm_version = const.SAMM_VERSION
3940
self.aspect = None
4041
self.model_elements = None
4142
self._samm = None
4243
self._reader = None
4344

4445
def __str__(self) -> str:
4546
"""Object string representation."""
46-
str_data = "SAMMGraph"
47-
if self.samm_version:
48-
str_data += f" v{self.samm_version}"
49-
50-
return str_data
47+
return f"SAMMGraph v{self.samm_version}"
5148

5249
def __repr__(self) -> str:
5350
"""Object representation."""
@@ -59,7 +56,7 @@ def _get_rdf_graph(self, input_data: Union[str, Path], input_type: Optional[str]
5956
"""Read the RDF graph from the given input data.
6057
6158
This method initializes the `InputHandler` with the provided input data and type,
62-
retrieves the reader, sets the SAMM version, and reads the RDF graph into `self.rdf_graph`.
59+
retrieves the reader, and reads the RDF graph into `self.rdf_graph`.
6360
6461
Args:
6562
input_data (Union[str, Path]): The input data to read the RDF graph from. This can be a file path or a str.
@@ -69,25 +66,8 @@ def _get_rdf_graph(self, input_data: Union[str, Path], input_type: Optional[str]
6966
None
7067
"""
7168
self._reader = InputHandler(input_data, input_type).get_reader()
72-
self._reader.set_samm_version(input_data)
7369
self.rdf_graph = self._reader.read(input_data)
7470

75-
def _get_samm_version(self):
76-
"""Retrieve and set the SAMM version from the RDF graph.
77-
78-
This method extracts the SAMM version from the RDF graph and assigns it to the `samm_version` attribute.
79-
If the SAMM version is not found, it raises a ValueError.
80-
81-
Raises:
82-
ValueError: If the SAMM version is not found in the RDF graph.
83-
"""
84-
self.samm_version = self._reader.samm_version
85-
86-
if not self.samm_version:
87-
raise ValueError(
88-
f"SAMM version number was not found in graph. Could not process RDF graph {self.rdf_graph}."
89-
)
90-
9171
def _get_samm(self):
9272
"""Initialize the SAMM object with the current SAMM version."""
9373
self._samm = SAMM(self.samm_version)
@@ -115,7 +95,6 @@ def parse(self, input_data: Union[str, Path], input_type: Optional[str] = None):
11595
SAMMGraph: The instance of the SAMMGraph with the parsed data.
11696
"""
11797
self._get_rdf_graph(input_data, input_type)
118-
self._get_samm_version()
11998
self._get_samm()
12099
self._get_samm_graph()
121100

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

Lines changed: 3 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@
1313
from pathlib import Path
1414
from typing import Union
1515

16-
from esmf_aspect_meta_model_python import utils
16+
import esmf_aspect_meta_model_python.constants as const
17+
1718
from esmf_aspect_meta_model_python.adaptive_graph import AdaptiveGraph
1819
from esmf_aspect_meta_model_python.samm_meta_model import SammUnitsGraph
1920

@@ -35,7 +36,7 @@ class ResolverInterface(ABC):
3536
def __init__(self):
3637
self.graph = AdaptiveGraph()
3738
self.samm_graph = None
38-
self.samm_version = ""
39+
self.samm_version = const.SAMM_VERSION
3940

4041
@abstractmethod
4142
def read(self, input_data: Union[str, Path]):
@@ -70,22 +71,5 @@ def _validate_samm_version(samm_version: str):
7071
elif samm_version > SammUnitsGraph.SAMM_VERSION:
7172
raise ValueError(f"{samm_version} is not supported SAMM version.")
7273

73-
def set_samm_version(self, steam_input: Union[str, Path]) -> None:
74-
"""
75-
Sets the SAMM version by extracting it from the specified file.
76-
77-
This method uses the AdaptiveGraph class to extract the SAMM version from the given file.
78-
There is also a validation against known SAMM versions to ensure the version is supported and recognized.
79-
80-
Args:
81-
steam_input (Union[str, Path]): The path to the file from which the SAMM version is to be extracted.
82-
83-
Raises:
84-
ValueError: If the extracted version is not supported or if it is not found in the file.
85-
"""
86-
version = utils.get_samm_version_from_input(steam_input)
87-
self._validate_samm_version(version)
88-
self.samm_version = version
89-
9074
def prepare_aspect_model(self, graph: AdaptiveGraph):
9175
"""Resolve all additional graph elements if needed."""

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ def read(self, data_string: Union[str, Path]):
3232
Returns:
3333
RDFGraph: An object representing the RDF graph constructed from the input data.
3434
"""
35-
self.graph = AdaptiveGraph(samm_version=self.samm_version)
35+
self.graph = AdaptiveGraph()
3636
self.graph.parse(data=str(data_string) if isinstance(data_string, Path) else data_string)
3737

3838
return self.graph

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

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ def read(self, file_path: Union[str, Path]) -> AdaptiveGraph:
5151
self.file_path = file_path
5252

5353
self.validate_file(self.file_path)
54-
self.graph = AdaptiveGraph(samm_version=self.samm_version)
54+
self.graph = AdaptiveGraph()
5555
self.graph.parse(source=self.file_path)
5656

5757
return self.graph
@@ -169,9 +169,3 @@ def prepare_aspect_model(self, graph: AdaptiveGraph):
169169
folder_dependencies: Dict[str, List[str]] = {}
170170

171171
self._get_dependency_files(file_dependencies, folder_dependencies, self.file_path)
172-
173-
def set_samm_version(self, file_path: Union[str, Path]) -> None:
174-
"""
175-
Converts the file path to a Path object and calls the parent class method to set the SAMM version.
176-
"""
177-
return super().set_samm_version(Path(file_path))

core/esmf-aspect-meta-model-python/esmf_aspect_meta_model_python/utils.py

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -37,13 +37,3 @@ def has_version_mismatch_in_graph(graph: Graph, samm_version: str) -> bool:
3737
def has_version_mismatch_from_input(input_source: Union[str, pathlib.Path], samm_version: str) -> bool:
3838
"""Detect SAMM version mismatch from an input source (path or Turtle string)."""
3939
return has_version_mismatch_in_graph(_parse_graph_from_input(input_source), samm_version=samm_version)
40-
41-
42-
def get_samm_version_from_input(input_source: Union[str, pathlib.Path]) -> str:
43-
"""Retrieve the SAMM version from the provided input source (path or Turtle string)."""
44-
version = ""
45-
46-
for v in get_samm_versions_from_graph(_parse_graph_from_input(input_source)):
47-
version = v
48-
49-
return version

core/esmf-aspect-meta-model-python/tests/integration/aspect_model_loader/resources/org.eclipse.esmf.test.characteristics/2.1.0/AspectWithBlankNode.ttl renamed to core/esmf-aspect-meta-model-python/tests/integration/aspect_model_loader/resources/org.eclipse.esmf.test.characteristics/2.2.0/AspectWithBlankNode.ttl

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

12-
@prefix : <urn:samm:org.eclipse.esmf.test.characteristics:2.1.0#> .
13-
@prefix samm: <urn:samm:org.eclipse.esmf.samm:meta-model:2.1.0#> .
14-
@prefix samm-c: <urn:samm:org.eclipse.esmf.samm:characteristic:2.1.0#> .
12+
@prefix : <urn:samm:org.eclipse.esmf.test.characteristics:2.2.0#> .
13+
@prefix samm: <urn:samm:org.eclipse.esmf.samm:meta-model:2.2.0#> .
14+
@prefix samm-c: <urn:samm:org.eclipse.esmf.samm:characteristic:2.2.0#> .
1515
@prefix xsd: <http://www.w3.org/2001/XMLSchema#> .
1616

1717
:AspectWithBlankNode a samm:Aspect ;

core/esmf-aspect-meta-model-python/tests/integration/aspect_model_loader/resources/org.eclipse.esmf.test.characteristics/2.1.0/AspectWithCode.ttl renamed to core/esmf-aspect-meta-model-python/tests/integration/aspect_model_loader/resources/org.eclipse.esmf.test.characteristics/2.2.0/AspectWithCode.ttl

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

12-
@prefix : <urn:samm:org.eclipse.esmf.test.characteristics:2.1.0#> .
13-
@prefix samm: <urn:samm:org.eclipse.esmf.samm:meta-model:2.1.0#> .
14-
@prefix samm-c: <urn:samm:org.eclipse.esmf.samm:characteristic:2.1.0#> .
12+
@prefix : <urn:samm:org.eclipse.esmf.test.characteristics:2.2.0#> .
13+
@prefix samm: <urn:samm:org.eclipse.esmf.samm:meta-model:2.2.0#> .
14+
@prefix samm-c: <urn:samm:org.eclipse.esmf.samm:characteristic:2.2.0#> .
1515
@prefix xsd: <http://www.w3.org/2001/XMLSchema#> .
16-
@prefix unit: <urn:samm:org.eclipse.esmf.samm:unit:2.1.0#> .
16+
@prefix unit: <urn:samm:org.eclipse.esmf.samm:unit:2.2.0#> .
1717

1818
:AspectWithCode a samm:Aspect ;
1919
samm:properties ( :testProperty ) ;

core/esmf-aspect-meta-model-python/tests/integration/aspect_model_loader/resources/org.eclipse.esmf.test.characteristics/2.1.0/AspectWithCollection.ttl renamed to core/esmf-aspect-meta-model-python/tests/integration/aspect_model_loader/resources/org.eclipse.esmf.test.characteristics/2.2.0/AspectWithCollection.ttl

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

12-
@prefix : <urn:samm:org.eclipse.esmf.test.characteristics:2.1.0#> .
13-
@prefix samm: <urn:samm:org.eclipse.esmf.samm:meta-model:2.1.0#> .
14-
@prefix samm-c: <urn:samm:org.eclipse.esmf.samm:characteristic:2.1.0#> .
12+
@prefix : <urn:samm:org.eclipse.esmf.test.characteristics:2.2.0#> .
13+
@prefix samm: <urn:samm:org.eclipse.esmf.samm:meta-model:2.2.0#> .
14+
@prefix samm-c: <urn:samm:org.eclipse.esmf.samm:characteristic:2.2.0#> .
1515
@prefix xsd: <http://www.w3.org/2001/XMLSchema#> .
16-
@prefix unit: <urn:samm:org.eclipse.esmf.samm:unit:2.1.0#> .
16+
@prefix unit: <urn:samm:org.eclipse.esmf.samm:unit:2.2.0#> .
1717

1818
:AspectWithCollection a samm:Aspect ;
1919
samm:preferredName "Test Aspect"@en ;

core/esmf-aspect-meta-model-python/tests/integration/aspect_model_loader/resources/org.eclipse.esmf.test.characteristics/2.1.0/AspectWithCollectionWithElementCharacteristic.ttl renamed to core/esmf-aspect-meta-model-python/tests/integration/aspect_model_loader/resources/org.eclipse.esmf.test.characteristics/2.2.0/AspectWithCollectionWithElementCharacteristic.ttl

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

12-
@prefix : <urn:samm:org.eclipse.esmf.test.characteristics:2.1.0#> .
13-
@prefix samm: <urn:samm:org.eclipse.esmf.samm:meta-model:2.1.0#> .
14-
@prefix samm-c: <urn:samm:org.eclipse.esmf.samm:characteristic:2.1.0#> .
12+
@prefix : <urn:samm:org.eclipse.esmf.test.characteristics:2.2.0#> .
13+
@prefix samm: <urn:samm:org.eclipse.esmf.samm:meta-model:2.2.0#> .
14+
@prefix samm-c: <urn:samm:org.eclipse.esmf.samm:characteristic:2.2.0#> .
1515
@prefix xsd: <http://www.w3.org/2001/XMLSchema#> .
16-
@prefix unit: <urn:samm:org.eclipse.esmf.samm:unit:2.1.0#> .
16+
@prefix unit: <urn:samm:org.eclipse.esmf.samm:unit:2.2.0#> .
1717

1818
:AspectWithCollectionWithElementCharacteristic a samm:Aspect ;
1919
samm:preferredName "Test Aspect"@en ;

core/esmf-aspect-meta-model-python/tests/integration/aspect_model_loader/resources/org.eclipse.esmf.test.characteristics/2.1.0/AspectWithDuration.ttl renamed to core/esmf-aspect-meta-model-python/tests/integration/aspect_model_loader/resources/org.eclipse.esmf.test.characteristics/2.2.0/AspectWithDuration.ttl

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

12-
@prefix : <urn:samm:org.eclipse.esmf.test.characteristics:2.1.0#> .
13-
@prefix samm: <urn:samm:org.eclipse.esmf.samm:meta-model:2.1.0#> .
14-
@prefix samm-c: <urn:samm:org.eclipse.esmf.samm:characteristic:2.1.0#> .
12+
@prefix : <urn:samm:org.eclipse.esmf.test.characteristics:2.2.0#> .
13+
@prefix samm: <urn:samm:org.eclipse.esmf.samm:meta-model:2.2.0#> .
14+
@prefix samm-c: <urn:samm:org.eclipse.esmf.samm:characteristic:2.2.0#> .
1515
@prefix xsd: <http://www.w3.org/2001/XMLSchema#> .
16-
@prefix unit: <urn:samm:org.eclipse.esmf.samm:unit:2.1.0#> .
16+
@prefix unit: <urn:samm:org.eclipse.esmf.samm:unit:2.2.0#> .
1717

1818
:AspectWithDuration a samm:Aspect ;
1919
samm:properties ( :testProperty ) ;

0 commit comments

Comments
 (0)