|
@@ -14,24 +14,30 @@ from unittest import mock
|
|
import pytest
|
|
import pytest
|
|
|
|
|
|
from taipy.common.config import Config
|
|
from taipy.common.config import Config
|
|
|
|
+from taipy.core import Orchestrator, taipy
|
|
from taipy.core._init_version import _read_version
|
|
from taipy.core._init_version import _read_version
|
|
from taipy.core.config.core_section import CoreSection
|
|
from taipy.core.config.core_section import CoreSection
|
|
from taipy.core.exceptions import ConfigCoreVersionMismatched
|
|
from taipy.core.exceptions import ConfigCoreVersionMismatched
|
|
|
|
+from taipy.core.scenario._scenario_manager import _ScenarioManager
|
|
from tests.core.utils.named_temporary_file import NamedTemporaryFile
|
|
from tests.core.utils.named_temporary_file import NamedTemporaryFile
|
|
|
|
|
|
_MOCK_CORE_VERSION = "3.1.1"
|
|
_MOCK_CORE_VERSION = "3.1.1"
|
|
|
|
|
|
|
|
|
|
|
|
+def patch_core_version(mock_core_version: str):
|
|
|
|
+ with mock.patch("taipy.core.config.core_section._read_version") as mock_read_version:
|
|
|
|
+ mock_read_version.return_value = mock_core_version
|
|
|
|
+
|
|
|
|
+ CoreSection._CURRENT_CORE_VERSION = mock_core_version
|
|
|
|
+ Config._default_config._unique_sections[CoreSection.name] = CoreSection.default_config()
|
|
|
|
+ Config._python_config._unique_sections[CoreSection.name] = CoreSection.default_config()
|
|
|
|
+
|
|
|
|
+
|
|
@pytest.fixture(scope="function", autouse=True)
|
|
@pytest.fixture(scope="function", autouse=True)
|
|
def mock_core_version():
|
|
def mock_core_version():
|
|
- with mock.patch("taipy.core.config.core_section._read_version") as mock_read_version:
|
|
|
|
- mock_read_version.return_value = _MOCK_CORE_VERSION
|
|
|
|
- CoreSection._CURRENT_CORE_VERSION = _MOCK_CORE_VERSION
|
|
|
|
- Config.unique_sections[CoreSection.name] = CoreSection.default_config()
|
|
|
|
- Config._default_config._unique_sections[CoreSection.name] = CoreSection.default_config()
|
|
|
|
- Config._python_config._unique_sections[CoreSection.name] = CoreSection.default_config()
|
|
|
|
|
|
+ patch_core_version(_MOCK_CORE_VERSION)
|
|
|
|
|
|
- yield
|
|
|
|
|
|
+ yield
|
|
|
|
|
|
CoreSection._CURRENT_CORE_VERSION = _read_version()
|
|
CoreSection._CURRENT_CORE_VERSION = _read_version()
|
|
|
|
|
|
@@ -137,3 +143,57 @@ class TestCoreVersionInCoreSectionConfig:
|
|
)
|
|
)
|
|
Config.load(file_config.filename)
|
|
Config.load(file_config.filename)
|
|
assert Config.unique_sections[CoreSection.name]._core_version == _MOCK_CORE_VERSION
|
|
assert Config.unique_sections[CoreSection.name]._core_version == _MOCK_CORE_VERSION
|
|
|
|
+
|
|
|
|
+ def test_run_core_app_with_different_taipy_core_version_in_development_mode(self):
|
|
|
|
+ with mock.patch("sys.argv", ["prog", "--development"]):
|
|
|
|
+ run_application()
|
|
|
|
+
|
|
|
|
+ # Run the application with a compatible version should NOT raise any error
|
|
|
|
+ patch_core_version(f"{self.major}.{self.minor}.{self.patch}.dev0")
|
|
|
|
+ with mock.patch("sys.argv", ["prog", "--development"]):
|
|
|
|
+ run_application()
|
|
|
|
+
|
|
|
|
+ # Run the application with an incompatible version in development mode should NOT raise an error
|
|
|
|
+ patch_core_version(f"{self.major}.{int(self.minor) + 1}.{self.patch}.dev0")
|
|
|
|
+ with mock.patch("sys.argv", ["prog", "--development"]):
|
|
|
|
+ run_application()
|
|
|
|
+
|
|
|
|
+ def test_run_core_app_with_different_taipy_core_version_in_experiment_mode(self, caplog):
|
|
|
|
+ with mock.patch("sys.argv", ["prog", "--experiment", "1.0"]):
|
|
|
|
+ run_application()
|
|
|
|
+
|
|
|
|
+ # Run the application with a compatible version should not raise any error
|
|
|
|
+ patch_core_version(f"{self.major}.{self.minor}.{int(self.patch) + 1}.dev0")
|
|
|
|
+ with mock.patch("sys.argv", ["prog", "--experiment", "1.0"]):
|
|
|
|
+ run_application()
|
|
|
|
+
|
|
|
|
+ # Run the application with an incompatible version in experiment mode should raise SystemExit and log the error
|
|
|
|
+ patch_core_version(f"{self.major}.{int(self.minor) + 1}.{self.patch}.dev0")
|
|
|
|
+ with mock.patch("sys.argv", ["prog", "--experiment", "1.0"]):
|
|
|
|
+ with pytest.raises(SystemExit):
|
|
|
|
+ run_application()
|
|
|
|
+ assert (
|
|
|
|
+ f"The version {self.major}.{self.minor}.{self.patch} of Taipy's entities does not match version "
|
|
|
|
+ f"of the Taipy Version management {self.major}.{int(self.minor) + 1}.{self.patch}.dev0"
|
|
|
|
+ ) in caplog.text
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+def twice(a):
|
|
|
|
+ return [a * 2]
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+def run_application():
|
|
|
|
+ Config.configure_data_node(id="d0")
|
|
|
|
+ data_node_1_config = Config.configure_data_node(id="d1", storage_type="pickle", default_data="abc")
|
|
|
|
+ data_node_2_config = Config.configure_data_node(id="d2", storage_type="csv")
|
|
|
|
+ task_config = Config.configure_task("my_task", twice, data_node_1_config, data_node_2_config)
|
|
|
|
+ scenario_config = Config.configure_scenario("my_scenario", [task_config])
|
|
|
|
+ scenario_config.add_sequences({"my_sequence": [task_config]})
|
|
|
|
+
|
|
|
|
+ orchestrator = Orchestrator()
|
|
|
|
+ orchestrator.run()
|
|
|
|
+
|
|
|
|
+ scenario = _ScenarioManager._create(scenario_config)
|
|
|
|
+ taipy.submit(scenario)
|
|
|
|
+
|
|
|
|
+ orchestrator.stop()
|