Skip to content

Commit 1885bf9

Browse files
Oleksandr Muzyka (EPAM)Oleksandr Muzyka (EPAM)
authored andcommitted
Refactor SAMM CLI, add archive extraction, update CI & version bump
- Refactor SAMM CLI path retrieval for cross-platform compatibility - Enhance SAMM CLI functions with capture output option and update tests - 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
1 parent 0790810 commit 1885bf9

File tree

7 files changed

+393
-134
lines changed

7 files changed

+393
-134
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: 89 additions & 48 deletions
Large diffs are not rendered by default.

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

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
"""Download SAMM CLI.
22
3-
Windows: https://github.com/eclipse-esmf/esmf-sdk/releases/download/v2.10.2/samm-cli-2.10.2-windows-x86_64.zip
4-
Linux: https://github.com/eclipse-esmf/esmf-sdk/releases/download/v2.10.2/samm-cli-2.10.2-linux-x86_64.tar.gz
5-
JAR: https://github.com/eclipse-esmf/esmf-sdk/releases/download/v2.10.2/samm-cli-2.10.2.jar
3+
Windows: https://github.com/eclipse-esmf/esmf-sdk/releases/download/v2.11.1/samm-cli-2.11.1-windows-x86_64.zip
4+
Linux: https://github.com/eclipse-esmf/esmf-sdk/releases/download/v2.11.1/samm-cli-2.11.1-linux-x86_64.tar.gz
5+
JAR: https://github.com/eclipse-esmf/esmf-sdk/releases/download/v2.11.1/samm-cli-2.11.1.jar
66
"""
77

88
import os
99
import platform
1010
import sys
11+
import tarfile
1112
import zipfile
1213

1314
from pathlib import Path
@@ -37,6 +38,8 @@ def download_archive_file(url, archive_file):
3738
with open(archive_file, "wb") as f:
3839
print("Downloading %s" % archive_file)
3940
response = requests.get(url, allow_redirects=True, stream=True)
41+
response.raise_for_status() # Fail fast if HTTP error
42+
4043
content_len = response.headers.get("content-length")
4144

4245
if content_len is None:
@@ -57,6 +60,18 @@ def download_archive_file(url, archive_file):
5760
sys.stdout.flush()
5861

5962

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

7489
print("Start extracting files")
75-
archive = zipfile.ZipFile(archive_file)
76-
extracted_files_path = os.path.join(dir_path, "samm-cli")
77-
for file in archive.namelist():
78-
archive.extract(file, extracted_files_path)
79-
archive.close()
90+
extract_archive(archive_file, dest_dir=os.path.join(dir_path, "samm-cli"))
8091
print("Done extracting files")
8192

8293
print("Deleting SAMM CLI archive file")

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

Lines changed: 32 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,13 @@
1+
# Copyright (c) 2023 Robert Bosch Manufacturing Solutions GmbH
2+
#
3+
# See the AUTHORS file(s) distributed with this work for additional
4+
# information regarding authorship.
5+
#
6+
# This Source Code Form is subject to the terms of the Mozilla Public
7+
# License, v. 2.0. If a copy of the MPL was not distributed with this
8+
# file, You can obtain one at https://mozilla.org/MPL/2.0/.
9+
#
10+
# SPDX-License-Identifier: MPL-2.0
111
"""Integration tests for SAMM CLI functions."""
212

313
import json
@@ -11,7 +21,7 @@
1121

1222
from esmf_aspect_meta_model_python.samm_cli.base import SammCli
1323

14-
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"
1525

1626

1727
@pytest.fixture(scope="module")
@@ -41,18 +51,29 @@ def samm_cli():
4151
class TestSammCliIntegration:
4252
"""Integration tests for SAMM CLI transformations."""
4353

44-
def test_prettyprint(self, samm_cli, file_path, temp_output_dir):
45-
"""Test pretty-printing the model."""
46-
output_file = os.path.join(temp_output_dir, "prettyprinted.ttl")
54+
class TestPrettyPrint:
55+
"""Test pretty-printing functionality."""
4756

48-
samm_cli.prettyprint(file_path, output=output_file)
57+
def test_file_output(self, samm_cli, file_path, temp_output_dir):
58+
"""Test pretty-printing to a file."""
59+
output_file = os.path.join(temp_output_dir, "prettyprinted.ttl")
4960

50-
assert os.path.exists(output_file)
51-
assert os.path.getsize(output_file) > 0
52-
with open(output_file, "r") as f:
53-
content = f.read()
54-
assert "@prefix" in content
55-
assert ":SampleAspect" in content
61+
samm_cli.prettyprint(file_path, output=output_file)
62+
63+
assert os.path.exists(output_file)
64+
assert os.path.getsize(output_file) > 0
65+
with open(output_file, "r") as f:
66+
content = f.read()
67+
assert "@prefix" in content
68+
assert ":SampleAspect" in content
69+
70+
def test_capture_output(self, samm_cli, file_path):
71+
"""Test pretty-printing with captured output."""
72+
prettyprinted_content = samm_cli.prettyprint(file_path, capture=True)
73+
74+
assert isinstance(prettyprinted_content, str)
75+
assert "@prefix" in prettyprinted_content
76+
assert ":SampleAspect" in prettyprinted_content
5677

5778
def test_to_json(self, samm_cli, file_path, temp_output_dir):
5879
"""Test generating example JSON payload."""

0 commit comments

Comments
 (0)