Ver Fonte

fix: export to an existing folder when override is False should raise ExportFolderAlreadyExists exception

trgiangdo há 1 ano atrás
pai
commit
29c0e46afc

+ 10 - 0
taipy/core/exceptions/exceptions.py

@@ -373,6 +373,16 @@ class FileCannotBeRead(Exception):
     """Raised when a file cannot be read."""
 
 
+class ExportFolderAlreadyExists(Exception):
+    """Raised when the export folder already exists."""
+
+    def __init__(self, folder_path: str, scenario_id: str):
+        self.message = (
+            f"Folder '{folder_path}' already exists and can not be used to export scenario '{scenario_id}'."
+            " Please use the 'override' parameter to override it."
+        )
+
+
 class SQLQueryCannotBeExecuted(Exception):
     """Raised when an SQL Query cannot be executed."""
 

+ 2 - 5
taipy/core/taipy.py

@@ -41,6 +41,7 @@ from .data.data_node import DataNode
 from .data.data_node_id import DataNodeId
 from .exceptions.exceptions import (
     DataNodeConfigIsNotGlobal,
+    ExportFolderAlreadyExists,
     ModelNotFound,
     NonExistingVersion,
     VersionIsNotProductionVersion,
@@ -973,11 +974,7 @@ def export_scenario(
             __logger.warn(f"Override the existing folder '{folder_path}'")
             shutil.rmtree(folder_path, ignore_errors=True)
         else:
-            __logger.error(
-                f"Folder '{folder_path}' already exists and can not be used to export scenario '{scenario_id}'."
-                " Please use the 'override' parameter to override it."
-            )
-            raise SystemExit()
+            raise ExportFolderAlreadyExists(str(folder_path), scenario_id)
 
     for data_node_id in entity_ids.data_node_ids:
         _DataManagerFactory._build_manager()._export(data_node_id, folder_path, include_data)

+ 2 - 2
tests/core/test_taipy/test_export.py

@@ -17,7 +17,7 @@ import pytest
 
 import taipy.core.taipy as tp
 from taipy import Config, Frequency, Scope
-from taipy.core.exceptions import InvalidExportPath
+from taipy.core.exceptions import ExportFolderAlreadyExists, InvalidExportPath
 
 
 @pytest.fixture(scope="function", autouse=True)
@@ -133,7 +133,7 @@ def test_export_scenario_override_existing_files():
     tp.submit(scenario_2)
 
     # Export the submitted scenario_2 to the same folder should raise an error
-    with pytest.raises(SystemExit):
+    with pytest.raises(ExportFolderAlreadyExists):
         tp.export_scenario(scenario_2.id, "./tmp/exp_scenario")
 
     # Export the submitted scenario_2 without a cycle and override the existing files