From 45e356a4fab916eae6ffcc380e36fa195ebd08ad Mon Sep 17 00:00:00 2001 From: MartinBelthle Date: Thu, 28 Nov 2024 17:09:37 +0100 Subject: [PATCH] fix(export): allow export for zipped outputs (#2253) --- antarest/study/storage/abstract_storage_service.py | 2 +- tests/storage/business/test_export.py | 7 +++++++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/antarest/study/storage/abstract_storage_service.py b/antarest/study/storage/abstract_storage_service.py index 782eb5516f..ccaa477673 100644 --- a/antarest/study/storage/abstract_storage_service.py +++ b/antarest/study/storage/abstract_storage_service.py @@ -314,7 +314,7 @@ def export_output(self, metadata: T, output_id: str, target: Path) -> None: logger.info(f"Exporting output {output_id} from study {metadata.id}") path_output = Path(metadata.path) / "output" / output_id - path_output_zip = Path(metadata.path) / "output" / f"{output_id}.{ArchiveFormat.ZIP}" + path_output_zip = Path(metadata.path) / "output" / f"{output_id}{ArchiveFormat.ZIP}" if path_output_zip.exists(): shutil.copyfile(path_output_zip, target) diff --git a/tests/storage/business/test_export.py b/tests/storage/business/test_export.py index e9e37211e1..2fb4b91411 100644 --- a/tests/storage/business/test_export.py +++ b/tests/storage/business/test_export.py @@ -19,6 +19,7 @@ from py7zr import SevenZipFile from antarest.core.config import Config, StorageConfig +from antarest.core.utils.archives import ArchiveFormat, archive_dir from antarest.study.model import DEFAULT_WORKSPACE_NAME, RawStudy from antarest.study.storage.rawstudy.raw_study_service import RawStudyService @@ -162,3 +163,9 @@ def test_export_output(tmp_path: Path): zipf = ZipFile(export_path) assert "file_output.txt" in zipf.namelist() + + # asserts exporting a zipped output doesn't raise an error + output_path = root / "output" / output_id + target_path = root / "output" / f"{output_id}.zip" + archive_dir(output_path, target_path, True, ArchiveFormat.ZIP) + study_service.export_output(study, output_id, export_path)