Skip to content

Commit 2d2bee1

Browse files
Oleksandr Muzyka (EPAM)Oleksandr Muzyka (EPAM)
authored andcommitted
- Refactor SAMM CLI path retrieval for cross-platform compatibility
- Add archive extraction functionality to download_samm_cli - Add SAMM CLI installation and native dependencies to CI workflow - Refactor resource path in test_cli_functions to improve clarity and maintainability - Stop running tests after the first failure - Upgrade JAVA_CLI_VERSION from 2.10.2 to 2.11.1
1 parent c5aaf25 commit 2d2bee1

File tree

7 files changed

+32
-12
lines changed

7 files changed

+32
-12
lines changed

.github/workflows/push_request_check.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ jobs:
3535
cd core/esmf-aspect-meta-model-python
3636
poetry install
3737
poetry run download-samm-release
38+
poetry run download-samm-cli
3839
poetry build
3940
4041
- name: run tests

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

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
# file, You can obtain one at https://mozilla.org/MPL/2.0/.
99
#
1010
# SPDX-License-Identifier: MPL-2.0
11+
import platform
1112
import subprocess
1213

1314
from os.path import exists, join
@@ -33,9 +34,14 @@ def __init__(self):
3334
def _get_client_path():
3435
"""Get path to the SAMM CLI executable file."""
3536
base_path = Path(__file__).resolve()
36-
cli_path = join(base_path.parents[2], "samm-cli", "samm.exe")
37+
cli_dir = join(base_path.parents[2], "samm-cli")
3738

38-
return cli_path
39+
if platform.system() == "Windows":
40+
cli_file = "samm.exe"
41+
else:
42+
cli_file = "samm" # Unix-like systems
43+
44+
return join(cli_dir, cli_file)
3945

4046
@staticmethod
4147
def _format_argument(key: str, value: Any) -> str:
@@ -327,7 +333,8 @@ def to_sql(self, path_to_model, *args, capture=False, **kwargs):
327333
"""
328334
return self._call_function(SAMMCLICommands.TO_SQL, path_to_model, *args, capture=capture, **kwargs)
329335

330-
# def to_aas(self, path_to_model, *args, capture=False, **kwargs): # FIXME: https://github.com/eclipse-esmf/esmf-sdk/issues/802
336+
# FIXME: https://github.com/eclipse-esmf/esmf-sdk/issues/802
337+
# def to_aas(self, path_to_model, *args, capture=False, **kwargs):
331338
# """Generate an Asset Administration Shell (AAS) submodel template from an Aspect Model.
332339
#
333340
# param path_to_model: local path to the aspect model file (*.ttl)

core/esmf-aspect-meta-model-python/scripts/constants.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414

1515

1616
SAMM_VERSION = "2.2.0"
17-
JAVA_CLI_VERSION = "2.10.2"
17+
JAVA_CLI_VERSION = "2.11.1"
1818

1919

2020
class SAMMCliConstants:

core/esmf-aspect-meta-model-python/scripts/download_samm_cli.py

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
"""
77

88
import os
9+
import tarfile
910
from pathlib import Path
1011
import platform
1112
import requests
@@ -35,6 +36,8 @@ def download_archive_file(url, archive_file):
3536
with open(archive_file, "wb") as f:
3637
print("Downloading %s" % archive_file)
3738
response = requests.get(url, allow_redirects=True, stream=True)
39+
response.raise_for_status() # Fail fast if HTTP error
40+
3841
content_len = response.headers.get('content-length')
3942

4043
if content_len is None:
@@ -55,6 +58,18 @@ def download_archive_file(url, archive_file):
5558
sys.stdout.flush()
5659

5760

61+
def extract_archive(archive_file, dest_dir):
62+
"""Extract archive depending on its file type."""
63+
if archive_file.endswith(".zip"):
64+
with zipfile.ZipFile(archive_file) as archive:
65+
archive.extractall(dest_dir)
66+
elif archive_file.endswith((".tar.gz", ".tgz")):
67+
with tarfile.open(archive_file, mode="r:gz") as archive:
68+
archive.extractall(dest_dir)
69+
else:
70+
raise ValueError(f"Unsupported archive format: {archive_file}")
71+
72+
5873
def download_samm_cli():
5974
try:
6075
samm_cli_file_name = get_samm_cli_file_name()
@@ -70,10 +85,7 @@ def download_samm_cli():
7085
print("\nSAMM CLI archive file downloaded")
7186

7287
print("Start extracting files")
73-
archive = zipfile.ZipFile(archive_file)
74-
for file in archive.namelist():
75-
archive.extract(file, "samm-cli")
76-
archive.close()
88+
extract_archive(archive_file, os.path.join(dir_path, "samm-cli"))
7789
print("Done extracting files.")
7890

7991
print("Deleting SAMM CLI archive file.")

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121

2222
from esmf_aspect_meta_model_python.samm_cli.base import SammCli
2323

24-
RESOURCE_PATH = os.getcwd() / Path("tests/integration/resources/org.eclipse.esmf.test.general/2.1.0")
24+
RESOURCE_PATH = Path(__file__).parent / "resources" / "org.eclipse.esmf.test.general" / "2.1.0"
2525

2626

2727
@pytest.fixture(scope="module")

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ def test_get_client_path(_, path_mock, join_mock):
6363

6464
assert result == "cli_path"
6565
path_mock.resolve.assert_called_once()
66-
join_mock.assert_called_once_with("parent_2", "samm-cli", "samm.exe")
66+
join_mock.assert_has_calls([mock.call('parent_2', 'samm-cli'), mock.call('cli_path', 'samm')])
6767

6868

6969
@mock.patch(f"{BASE_PATH}.download_samm_cli")

core/esmf-aspect-meta-model-python/tox.ini

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ description = Run the tests
1111
commands_pre = poetry install
1212
commands =
1313
poetry run pytest {posargs: \
14-
-s -vv \
14+
-x -s -vv \
1515
--cov=esmf_aspect_meta_model_python/ \
1616
--cov-fail-under=85 \
1717
tests/ \
@@ -42,4 +42,4 @@ known_first_party = esmf_aspect_meta_model_python, tests
4242
line_length = 120
4343
lines_between_types = 1
4444
multi_line_output = 3
45-
sections = STDLIB, THIRDPARTY, FIRSTPARTY, LOCALFOLDER
45+
sections = STDLIB, THIRDPARTY, FIRSTPARTY, LOCALFOLDER

0 commit comments

Comments
 (0)