Skip to content

Commit

Permalink
Merge branch 'eclipse-esmf:main' into #43-state-initiator-implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
thec0dewriter authored Aug 12, 2024
2 parents 2f63f2f + 5e97f21 commit 293bf65
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 32 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@

from rdflib import Graph

from scripts.samm.download_samm_release import main as download_samm_release


class BaseMetaModelResolver(ABC):
"""Interface for meta-model resolver class."""
Expand Down Expand Up @@ -51,19 +49,6 @@ def _get_samm_files_path(self, meta_model_version: str) -> List[str]:

return samm_files

def get_samm_files(self, meta_model_version: str) -> List[str]:
"""Check and collect paths to SAMM files.
:param meta_model_version: meta-model version
:return: List of all path to SAMM files for the given meta-model version
"""
samm_files = self._get_samm_files_path(meta_model_version)
if not samm_files:
download_samm_release()
samm_files = self._get_samm_files_path(meta_model_version)

return samm_files

@staticmethod
def validate_file(file_path: str):
"""Validate a SAMM file.
Expand All @@ -89,6 +74,6 @@ def parse(self, aspect_graph: Graph, meta_model_version: str):
:param aspect_graph: RDF Graph
:param meta_model_version: version of the meta-model to extract the right SAMM turtle files
"""
for file_path in self.get_samm_files(meta_model_version):
for file_path in self._get_samm_files_path(meta_model_version):
self.validate_file(file_path)
aspect_graph.parse(file_path, format="turtle")
Original file line number Diff line number Diff line change
Expand Up @@ -24,18 +24,6 @@ def test_init_with_defaults(self, path_mock):
assert result._base_path == "parent_3"
path_mock.assert_called_once()

@mock.patch("esmf_aspect_meta_model_python.resolver.meta_model.glob")
@mock.patch("esmf_aspect_meta_model_python.resolver.meta_model.join")
def test_get_samm_files(self, join_mock, glob_mock):
join_mock.return_value = "path_template"
glob_mock.return_value = ["samm_file_1", "samm_file_2"]
aspect_resolver = AspectMetaModelResolver("base_path")
aspect_resolver.samm_folder_path = "samm_folder_path"
result = aspect_resolver.get_samm_files("meta_model_version")

assert sorted(result) == ["samm_file_1", "samm_file_2"]
join_mock.assert_called_once_with("base_path", "samm_folder_path", "**", "meta_model_version", "*.ttl")

@mock.patch("esmf_aspect_meta_model_python.resolver.meta_model.exists")
def test_validate_file(self, exists_mock):
exists_mock.return_value = False
Expand All @@ -49,14 +37,14 @@ def test_validate_file(self, exists_mock):
exists_mock.assert_called_once_with("file_path")

@mock.patch("esmf_aspect_meta_model_python.resolver.meta_model.AspectMetaModelResolver.validate_file")
@mock.patch("esmf_aspect_meta_model_python.resolver.meta_model.AspectMetaModelResolver.get_samm_files")
def test_parse(self, get_samm_files_mock, validate_file_mock):
get_samm_files_mock.return_value = ["samm_file_path"]
@mock.patch("esmf_aspect_meta_model_python.resolver.meta_model.AspectMetaModelResolver._get_samm_files_path")
def test_parse(self, get_samm_files_path_mock, validate_file_mock):
get_samm_files_path_mock.return_value = ["samm_file_path"]
aspect_graph_mock = mock.MagicMock(name="graph")
aspect_resolver = AspectMetaModelResolver("base_path")
result = aspect_resolver.parse(aspect_graph_mock, "meta_model_version")

assert result is None
get_samm_files_mock.assert_called_once_with("meta_model_version")
get_samm_files_path_mock.assert_called_once_with("meta_model_version")
validate_file_mock.assert_called_once_with("samm_file_path")
aspect_graph_mock.parse.assert_called_once_with("samm_file_path", format="turtle")

0 comments on commit 293bf65

Please sign in to comment.