From 6ac7d6c04be999cd1cb3e0000025e0c1ad180b20 Mon Sep 17 00:00:00 2001
From: MartinBelthle <102529366+MartinBelthle@users.noreply.github.com>
Date: Wed, 19 Jul 2023 16:51:34 +0200
Subject: [PATCH] fix(export): ZIP outputs are now uncompressed before export
 (#1656)

---
 antarest/study/storage/utils.py            | 13 +++++++++----
 tests/storage/integration/test_exporter.py |  4 +++-
 2 files changed, 12 insertions(+), 5 deletions(-)

diff --git a/antarest/study/storage/utils.py b/antarest/study/storage/utils.py
index d6cdd07192..3c9ee5d901 100644
--- a/antarest/study/storage/utils.py
+++ b/antarest/study/storage/utils.py
@@ -396,10 +396,15 @@ def export_study_flat(
         if output_list_filter is not None:
             os.mkdir(output_dest_path)
             for output in output_list_filter:
-                shutil.copytree(
-                    src=output_src_path / output,
-                    dst=output_dest_path / output,
-                )
+                zip_path = output_src_path / f"{output}.zip"
+                if zip_path.exists():
+                    with ZipFile(zip_path) as zf:
+                        zf.extractall(output_dest_path / output)
+                else:
+                    shutil.copytree(
+                        src=output_src_path / output,
+                        dst=output_dest_path / output,
+                    )
         else:
             shutil.copytree(
                 src=output_src_path,
diff --git a/tests/storage/integration/test_exporter.py b/tests/storage/integration/test_exporter.py
index 78709e69f2..355d5bf462 100644
--- a/tests/storage/integration/test_exporter.py
+++ b/tests/storage/integration/test_exporter.py
@@ -100,7 +100,9 @@ def test_exporter_file_no_output(
 
 
 @pytest.mark.parametrize("outputs", [True, False, "prout"])
-@pytest.mark.parametrize("output_list", [None, [], ["20201014-1427eco"]])
+@pytest.mark.parametrize(
+    "output_list", [None, [], ["20201014-1427eco"], ["20201014-1430adq-2"]]
+)
 @pytest.mark.parametrize("denormalize", [True, False])
 def test_export_flat(
     tmp_path: Path,