Skip to content

Commit d74f736

Browse files
authored
#109: Added flag which allows to select compression strategy of SLC during export (#111)
fixes #109
1 parent 2b6d85d commit d74f736

File tree

5 files changed

+90
-18
lines changed

5 files changed

+90
-18
lines changed

doc/changes/unreleased.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,8 @@
33

44
## Refactorings
55

6-
- #106: Updated dependencies
6+
- #106: Updated dependencies
7+
8+
## Features
9+
10+
- #109: Added flag which allows to select compression strategy of SLC during export

exasol/python_extension_common/deployment/language_container_builder.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
from typing import Callable
99

1010
from exasol.slc import api # type: ignore
11+
from exasol.slc.models.compression_strategy import CompressionStrategy
1112
from exasol.slc.models.export_container_result import (
1213
ExportContainerResult, # type: ignore
1314
)
@@ -125,7 +126,9 @@ def build(self) -> dict[str, ImageInfo]:
125126
image_info = api.build(flavor_path=(str(self.flavor_path),), goal=("release",))
126127
return image_info
127128

128-
def export(self, export_path: str | Path | None = None) -> ExportContainerResult:
129+
def export(
130+
self, export_path: str | Path | None = None, compression_strategy=CompressionStrategy.GZIP
131+
) -> ExportContainerResult:
129132
"""
130133
Exports the container into an archive.
131134
"""
@@ -143,6 +146,7 @@ def export(self, export_path: str | Path | None = None) -> ExportContainerResult
143146
flavor_path=(str(self.flavor_path),),
144147
output_directory=str(self._output_path),
145148
export_path=str(export_path),
149+
compression_strategy=compression_strategy,
146150
)
147151
return export_result
148152

test/integration/deployment/test_language_container_builder.py

Lines changed: 34 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@
22
from pathlib import Path
33
from test.utils.db_utils import assert_udf_running
44

5+
import pytest
6+
from exasol.slc.models.compression_strategy import CompressionStrategy
7+
58
from exasol.python_extension_common.deployment.language_container_builder import (
69
LanguageContainerBuilder,
710
find_path_backwards,
@@ -32,22 +35,43 @@ def test_prepare_flavor_extra():
3235
assert container_builder.requirements_file.read_text().startswith(dummy_req)
3336

3437

35-
def test_language_container_builder(deployer_factory, db_schema, language_alias):
38+
@pytest.fixture(scope="session")
39+
def language_container_builder():
3640
project_directory = find_path_backwards("pyproject.toml", __file__).parent
3741

38-
with ExitStack() as stack:
39-
# Build the SLC
40-
container_builder = stack.enter_context(LanguageContainerBuilder("test_container"))
42+
with LanguageContainerBuilder("test_container") as container_builder:
43+
# Prepare the SLC
4144
container_builder.prepare_flavor(project_directory)
42-
export_result = container_builder.export()
43-
export_info = export_result.export_infos[str(container_builder.flavor_path)]["release"]
45+
yield container_builder
46+
47+
48+
@pytest.fixture(
49+
scope="session",
50+
params=[
51+
(CompressionStrategy.GZIP, ".tar.gz"),
52+
(CompressionStrategy.NONE, ".tar"),
53+
],
54+
ids=["with_gzip_compression", "no_compression"],
55+
)
56+
def slc_container_file_path(request, language_container_builder):
57+
compression_strategy = request.param[0]
58+
expected_container_file_suffix = request.param[1]
59+
60+
export_result = language_container_builder.export(compression_strategy=compression_strategy)
61+
export_info = export_result.export_infos[str(language_container_builder.flavor_path)]["release"]
62+
container_file_path = Path(export_info.cache_file)
63+
assert container_file_path.name.endswith(
64+
expected_container_file_suffix
65+
), f"Expected container file suffix {expected_container_file_suffix} does not match {container_file_path}"
66+
return container_file_path
4467

45-
container_file_path = Path(export_info.cache_file)
4668

47-
# Deploy the SCL
48-
deployer = stack.enter_context(deployer_factory(create_test_schema=True))
69+
def test_language_container_builder(
70+
language_container_builder, deployer_factory, db_schema, language_alias, slc_container_file_path
71+
):
72+
with deployer_factory(db_schema) as deployer:
4973
deployer.run(
50-
container_file=Path(container_file_path), alter_system=True, allow_override=True
74+
container_file=Path(slc_container_file_path), alter_system=True, allow_override=True
5175
)
5276

5377
# Verify that the deployed SLC works.

test/unit/deployment/test_language_container_builder.py

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,13 @@
11
import re
2+
from unittest.mock import (
3+
MagicMock,
4+
call,
5+
)
26

37
import pytest
8+
from _pytest.monkeypatch import MonkeyPatch
9+
from exasol.slc import api
10+
from exasol.slc.models.compression_strategy import CompressionStrategy
411

512
from exasol.python_extension_common.deployment.language_container_builder import (
613
LanguageContainerBuilder,
@@ -33,3 +40,33 @@ def test_copy_slc_flavor(tmp_path):
3340
flavor_base = tmp_path / "flavor_base"
3441
assert flavor_base.exists()
3542
assert len(list(flavor_base.rglob("*"))) == 7
43+
44+
45+
@pytest.fixture
46+
def mock_export(monkeypatch: MonkeyPatch) -> MagicMock:
47+
mock_function_to_mock = MagicMock()
48+
monkeypatch.setattr(api, "export", mock_function_to_mock)
49+
return mock_function_to_mock
50+
51+
52+
@pytest.mark.parametrize(
53+
"compression_strategy",
54+
[
55+
(CompressionStrategy.GZIP),
56+
(CompressionStrategy.NONE),
57+
],
58+
)
59+
def test_export(mock_export, tmp_path, compression_strategy):
60+
project_directory = find_path_backwards("pyproject.toml", __file__).parent
61+
with LanguageContainerBuilder("test_container") as builder:
62+
builder.prepare_flavor(project_directory)
63+
builder.export(tmp_path, compression_strategy=compression_strategy)
64+
expected_calls = [
65+
call(
66+
flavor_path=(str(builder.flavor_path),),
67+
output_directory=str(builder._output_path),
68+
export_path=str(tmp_path),
69+
compression_strategy=compression_strategy,
70+
),
71+
]
72+
assert mock_export.has_calls(expected_calls)

version.py

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
1-
# ATTENTION:
2-
# This file is generated by exasol/toolbox/nox/_package_version.py when using:
3-
# * either "poetry run -- nox -s project:fix"
4-
# * or "poetry run -- nox version:check -- --fix"
5-
# Do not edit this file manually!
6-
# If you need to change the version, do so in the pyproject.toml, e.g. by using `poetry version X.Y.Z`.
1+
"""ATTENTION:
2+
This file is generated by exasol/toolbox/nox/_package_version.py when using:
3+
* either "poetry run -- nox -s project:fix"
4+
* or "poetry run -- nox -s version:check -- --fix"
5+
Do not edit this file manually!
6+
If you need to change the version, do so in the pyproject.toml, e.g. by using
7+
`poetry version X.Y.Z`.
8+
"""
9+
710
MAJOR = 0
811
MINOR = 10
912
PATCH = 0

0 commit comments

Comments
 (0)