from datetime import datetime  from time import sleep    from src.taipy.core._version._version_manager_factory import _VersionManagerFactory  from src.taipy.core.submission._submission_manager_factory import _SubmissionManagerFactory  from src.taipy.core.submission.submission import Submission  from src.taipy.core.submission.submission_status import SubmissionStatus  from src.taipy.core.task.task import Task      def test_create_submission(scenario):      submission_1 = _SubmissionManagerFactory._build_manager()._create(scenario.id, scenario._ID_PREFIX)        assert submission_1.id is not None      assert submission_1.entity_id == scenario.id      assert submission_1.jobs == []      assert isinstance(submission_1.creation_date, datetime)      assert submission_1._submission_status == SubmissionStatus.SUBMITTED      def test_get_submission():      submission_manager = _SubmissionManagerFactory._build_manager()        assert submission_manager._get("random_submission_id") is None        submission_1 = submission_manager._create("entity_id", "ENTITY_TYPE")      submission_2 = submission_manager._get(submission_1.id)        assert submission_1.id == submission_2.id      assert submission_1.entity_id == submission_2.entity_id == "entity_id"      assert submission_1.jobs == submission_2.jobs      assert submission_1.creation_date == submission_2.creation_date      assert submission_1.submission_status == submission_2.submission_status      def test_get_all_submission():      submission_manager = _SubmissionManagerFactory._build_manager()      version_manager = _VersionManagerFactory._build_manager()        submission_manager._set(Submission("entity_id", "submission_id", version=version_manager._get_latest_version()))      for version_name in ["abc", "xyz"]:          for i in range(10):              submission_manager._set(                  Submission("entity_id", f"submission_{version_name}_{i}", version=f"{version_name}")              )        assert len(submission_manager._get_all()) == 1        version_manager._set_experiment_version("xyz")      version_manager._set_experiment_version("abc")      assert len(submission_manager._get_all()) == 10      assert len(submission_manager._get_all("abc")) == 10      assert len(submission_manager._get_all("xyz")) == 10      def test_get_latest_submission():      task_1 = Task("task_config_1", {}, print, id="task_id_1")      task_2 = Task("task_config_2", {}, print, id="task_id_2")        submission_manager = _SubmissionManagerFactory._build_manager()      submission_1 = submission_manager._create(task_1.id, task_1._ID_PREFIX)      assert submission_manager._get_latest(task_1) == submission_1      assert submission_manager._get_latest(task_2) is None        sleep(0.01)  # Comparison is based on time, precision on Windows is not enough important      submission_2 = submission_manager._create(task_2.id, task_2._ID_PREFIX)      assert submission_manager._get_latest(task_1) == submission_1      assert submission_manager._get_latest(task_2) == submission_2        sleep(0.01)  # Comparison is based on time, precision on Windows is not enough important      submission_3 = submission_manager._create(task_1.id, task_1._ID_PREFIX)      assert submission_manager._get_latest(task_1) == submission_3      assert submission_manager._get_latest(task_2) == submission_2        sleep(0.01)  # Comparison is based on time, precision on Windows is not enough important      submission_4 = submission_manager._create(task_2.id, task_2._ID_PREFIX)      assert submission_manager._get_latest(task_1) == submission_3      assert submission_manager._get_latest(task_2) == submission_4      def test_delete_submission():      submission_manager = _SubmissionManagerFactory._build_manager()        submission = Submission("entity_id", "submission_id")      submission_manager._set(submission)        for i in range(10):          submission_manager._set(Submission("entity_id", f"submission_{i}"))        assert len(submission_manager._get_all()) == 11      assert isinstance(submission_manager._get(submission.id), Submission)        submission_manager._delete(submission.id)      assert len(submission_manager._get_all()) == 10      assert submission_manager._get(submission.id) is None        submission_manager._delete_all()      assert len(submission_manager._get_all()) == 0


from datetime import datetime  from functools import partial  from typing import Union  from unittest import mock  from unittest.mock import patch    import pytest    from src.taipy.core import TaskId  from src.taipy.core.job._job_manager_factory import _JobManagerFactory  from src.taipy.core.job.job import Job  from src.taipy.core.job.status import Status  from src.taipy.core.submission._submission_manager_factory import _SubmissionManagerFactory  from src.taipy.core.submission.submission import Submission  from src.taipy.core.submission.submission_status import SubmissionStatus  from src.taipy.core.task._task_manager_factory import _TaskManagerFactory  from src.taipy.core.task.task import Task      def test_create_submission(scenario, job, current_datetime):      submission_1 = Submission(scenario.id, scenario._ID_PREFIX)        assert submission_1.id is not None      assert submission_1.entity_id == scenario.id      assert submission_1.jobs == []      assert isinstance(submission_1.creation_date, datetime)      assert submission_1._submission_status == SubmissionStatus.SUBMITTED      assert submission_1._version is not None        submission_2 = Submission(          scenario.id,          scenario._ID_PREFIX,          "submission_id",          [job],          current_datetime,          SubmissionStatus.COMPLETED,          "version_id",      )        assert submission_2.id == "submission_id"      assert submission_2.entity_id == scenario.id      assert submission_2._jobs == [job]      assert submission_2.creation_date == current_datetime      assert submission_2._submission_status == SubmissionStatus.COMPLETED      assert submission_2._version == "version_id"      class MockJob:      def __init__(self, id: str, status):          self.status = status          self.id = id        def is_failed(self):          return self.status == Status.FAILED        def is_canceled(self):          return self.status == Status.CANCELED        def is_blocked(self):          return self.status == Status.BLOCKED        def is_pending(self):          return self.status == Status.PENDING        def is_running(self):          return self.status == Status.RUNNING        def is_completed(self):          return self.status == Status.COMPLETED        def is_skipped(self):          return self.status == Status.SKIPPED        def is_abandoned(self):          return self.status == Status.ABANDONED        def is_submitted(self):          return self.status == Status.SUBMITTED      def __test_update_submission_status(job_ids, expected_submission_status):      jobs = {          "job0_submitted": MockJob("job0_submitted", Status.SUBMITTED),          "job1_failed": MockJob("job1_failed", Status.FAILED),          "job2_canceled": MockJob("job2_canceled", Status.CANCELED),          "job3_blocked": MockJob("job3_blocked", Status.BLOCKED),          "job4_pending": MockJob("job4_pending", Status.PENDING),          "job5_running": MockJob("job5_running", Status.RUNNING),          "job6_completed": MockJob("job6_completed", Status.COMPLETED),          "job7_skipped": MockJob("job7_skipped", Status.SKIPPED),          "job8_abandoned": MockJob("job8_abandoned", Status.ABANDONED),      }        submission = Submission("submission_id", "ENTITY_TYPE")      submission.jobs = [jobs[job_id] for job_id in job_ids]      for job_id in job_ids:          job = jobs[job_id]          submission._update_submission_status(job)      assert submission.submission_status == expected_submission_status      @pytest.mark.parametrize(      "job_ids, expected_submission_status",      [          (["job1_failed"], SubmissionStatus.FAILED),          (["job2_canceled"], SubmissionStatus.CANCELED),          (["job3_blocked"], SubmissionStatus.BLOCKED),          (["job4_pending"], SubmissionStatus.PENDING),          (["job5_running"], SubmissionStatus.RUNNING),          (["job6_completed"], SubmissionStatus.COMPLETED),          (["job7_skipped"], SubmissionStatus.COMPLETED),          (["job8_abandoned"], SubmissionStatus.UNDEFINED),      ],  )  def test_update_single_submission_status(job_ids, expected_submission_status):      __test_update_submission_status(job_ids, expected_submission_status)      @pytest.mark.parametrize(      "job_ids, expected_submission_status",      [          (["job1_failed", "job1_failed"], SubmissionStatus.FAILED),          (["job1_failed", "job2_canceled"], SubmissionStatus.FAILED),          (["job1_failed", "job3_blocked"], SubmissionStatus.FAILED),          (["job1_failed", "job4_pending"], SubmissionStatus.FAILED),          (["job1_failed", "job5_running"], SubmissionStatus.FAILED),          (["job1_failed", "job6_completed"], SubmissionStatus.FAILED),          (["job1_failed", "job7_skipped"], SubmissionStatus.FAILED),          (["job1_failed", "job8_abandoned"], SubmissionStatus.FAILED),          (["job2_canceled", "job1_failed"], SubmissionStatus.FAILED),          (["job3_blocked", "job1_failed"], SubmissionStatus.FAILED),          (["job4_pending", "job1_failed"], SubmissionStatus.FAILED),          (["job5_running", "job1_failed"], SubmissionStatus.FAILED),          (["job6_completed", "job1_failed"], SubmissionStatus.FAILED),          (["job7_skipped", "job1_failed"], SubmissionStatus.FAILED),          (["job8_abandoned", "job1_failed"], SubmissionStatus.FAILED),      ],  )  def test_update_submission_status_with_one_failed_job_in_jobs(job_ids, expected_submission_status):      __test_update_submission_status(job_ids, expected_submission_status)      @pytest.mark.parametrize(      "job_ids, expected_submission_status",      [          (["job2_canceled", "job2_canceled"], SubmissionStatus.CANCELED),          (["job2_canceled", "job3_blocked"], SubmissionStatus.CANCELED),          (["job2_canceled", "job4_pending"], SubmissionStatus.CANCELED),          (["job2_canceled", "job5_running"], SubmissionStatus.CANCELED),          (["job2_canceled", "job6_completed"], SubmissionStatus.CANCELED),          (["job2_canceled", "job7_skipped"], SubmissionStatus.CANCELED),          (["job2_canceled", "job8_abandoned"], SubmissionStatus.CANCELED),          (["job3_blocked", "job2_canceled"], SubmissionStatus.CANCELED),          (["job4_pending", "job2_canceled"], SubmissionStatus.CANCELED),          (["job5_running", "job2_canceled"], SubmissionStatus.CANCELED),          (["job6_completed", "job2_canceled"], SubmissionStatus.CANCELED),          (["job7_skipped", "job2_canceled"], SubmissionStatus.CANCELED),          (["job8_abandoned", "job2_canceled"], SubmissionStatus.CANCELED),      ],  )  def test_update_submission_status_with_one_canceled_job_in_jobs(job_ids, expected_submission_status):      __test_update_submission_status(job_ids, expected_submission_status)      @pytest.mark.parametrize(      "job_ids, expected_submission_status",      [          (["job4_pending", "job3_blocked"], SubmissionStatus.PENDING),          (["job4_pending", "job4_pending"], SubmissionStatus.PENDING),          (["job4_pending", "job6_completed"], SubmissionStatus.PENDING),          (["job4_pending", "job7_skipped"], SubmissionStatus.PENDING),          (["job3_blocked", "job4_pending"], SubmissionStatus.PENDING),          (["job6_completed", "job4_pending"], SubmissionStatus.PENDING),          (["job7_skipped", "job4_pending"], SubmissionStatus.PENDING),      ],  )  def test_update_submission_status_with_no_failed_or_cancel_one_pending_in_jobs(job_ids, expected_submission_status):      __test_update_submission_status(job_ids, expected_submission_status)      @pytest.mark.parametrize(      "job_ids, expected_submission_status",      [          (["job5_running", "job3_blocked"], SubmissionStatus.RUNNING),          (["job5_running", "job4_pending"], SubmissionStatus.RUNNING),          (["job5_running", "job5_running"], SubmissionStatus.RUNNING),          (["job5_running", "job6_completed"], SubmissionStatus.RUNNING),          (["job5_running", "job7_skipped"], SubmissionStatus.RUNNING),          (["job3_blocked", "job5_running"], SubmissionStatus.RUNNING),          (["job4_pending", "job5_running"], SubmissionStatus.RUNNING),          (["job6_completed", "job5_running"], SubmissionStatus.RUNNING),          (["job7_skipped", "job5_running"], SubmissionStatus.RUNNING),      ],  )  def test_update_submission_status_with_no_failed_cancel_nor_pending_one_running_in_jobs(      job_ids, expected_submission_status  ):      __test_update_submission_status(job_ids, expected_submission_status)      @pytest.mark.parametrize(      "job_ids, expected_submission_status",      [          (["job3_blocked", "job3_blocked"], SubmissionStatus.BLOCKED),          (["job3_blocked", "job6_completed"], SubmissionStatus.BLOCKED),          (["job3_blocked", "job7_skipped"], SubmissionStatus.BLOCKED),          (["job6_completed", "job3_blocked"], SubmissionStatus.BLOCKED),          (["job7_skipped", "job3_blocked"], SubmissionStatus.BLOCKED),      ],  )  def test_update_submission_status_with_no_failed_cancel_pending_nor_running_one_blocked_in_jobs(      job_ids, expected_submission_status  ):      __test_update_submission_status(job_ids, expected_submission_status)      @pytest.mark.parametrize(      "job_ids, expected_submission_status",      [          (["job6_completed", "job6_completed"], SubmissionStatus.COMPLETED),          (["job6_completed", "job7_skipped"], SubmissionStatus.COMPLETED),          (["job7_skipped", "job6_completed"], SubmissionStatus.COMPLETED),          (["job7_skipped", "job7_skipped"], SubmissionStatus.COMPLETED),      ],  )  def test_update_submission_status_with_only_completed_or_skipped_in_jobs(job_ids, expected_submission_status):      __test_update_submission_status(job_ids, expected_submission_status)      @pytest.mark.parametrize(      "job_ids, expected_submission_status",      [          (["job3_blocked", "job8_abandoned"], SubmissionStatus.UNDEFINED),          (["job4_pending", "job8_abandoned"], SubmissionStatus.UNDEFINED),          (["job5_running", "job8_abandoned"], SubmissionStatus.UNDEFINED),          (["job6_completed", "job8_abandoned"], SubmissionStatus.UNDEFINED),          (["job7_skipped", "job8_abandoned"], SubmissionStatus.UNDEFINED),          (["job8_abandoned", "job8_abandoned"], SubmissionStatus.UNDEFINED),          (["job8_abandoned", "job3_blocked"], SubmissionStatus.UNDEFINED),          (["job8_abandoned", "job4_pending"], SubmissionStatus.UNDEFINED),          (["job8_abandoned", "job5_running"], SubmissionStatus.UNDEFINED),          (["job8_abandoned", "job6_completed"], SubmissionStatus.UNDEFINED),          (["job8_abandoned", "job7_skipped"], SubmissionStatus.UNDEFINED),      ],  )  def test_update_submission_status_with_wrong_case_abandoned_without_cancel_or_failed_in_jobs(      job_ids, expected_submission_status  ):      __test_update_submission_status(job_ids, expected_submission_status)      def test_auto_set_and_reload():      task = Task(config_id="name_1", properties={}, function=print, id=TaskId("task_1"))      submission_1 = Submission(task.id, task._ID_PREFIX)      job_1 = Job("job_1", task, submission_1.id, submission_1.entity_id)      job_2 = Job("job_2", task, submission_1.id, submission_1.entity_id)        _TaskManagerFactory._build_manager()._set(task)      _SubmissionManagerFactory._build_manager()._set(submission_1)      _JobManagerFactory._build_manager()._set(job_1)      _JobManagerFactory._build_manager()._set(job_2)        submission_2 = _SubmissionManagerFactory._build_manager()._get(submission_1)        assert submission_1.id == submission_2.id      assert submission_1.entity_id == submission_2.entity_id      assert submission_1.creation_date == submission_2.creation_date      assert submission_1.submission_status == submission_2.submission_status        # auto set & reload on jobs attribute      assert submission_1.jobs == []      assert submission_2.jobs == []      submission_1.jobs = [job_1]      assert submission_1.jobs == [job_1]      assert submission_2.jobs == [job_1]      submission_2.jobs = [job_2]      assert submission_1.jobs == [job_2]      assert submission_2.jobs == [job_2]      submission_1.jobs = [job_1, job_2]      assert submission_1.jobs == [job_1, job_2]      assert submission_2.jobs == [job_1, job_2]      submission_2.jobs = [job_2, job_1]      assert submission_1.jobs == [job_2, job_1]      assert submission_2.jobs == [job_2, job_1]        # auto set & reload on submission_status attribute      assert submission_1.submission_status == SubmissionStatus.SUBMITTED      assert submission_2.submission_status == SubmissionStatus.SUBMITTED      submission_1.submission_status = SubmissionStatus.BLOCKED      assert submission_1.submission_status == SubmissionStatus.BLOCKED      assert submission_2.submission_status == SubmissionStatus.BLOCKED      submission_2.submission_status = SubmissionStatus.COMPLETED      assert submission_1.submission_status == SubmissionStatus.COMPLETED      assert submission_2.submission_status == SubmissionStatus.COMPLETED        with submission_1 as submission:          assert submission.jobs == [job_2, job_1]          assert submission.submission_status == SubmissionStatus.COMPLETED            submission.jobs = [job_1]          submission.submission_status = SubmissionStatus.PENDING            assert submission.jobs == [job_2, job_1]          assert submission.submission_status == SubmissionStatus.COMPLETED        assert submission_1.jobs == [job_1]      assert submission_1.submission_status == SubmissionStatus.PENDING      assert submission_2.jobs == [job_1]      assert submission_2.submission_status == SubmissionStatus.PENDING      @pytest.mark.parametrize(      "job_statuses, expected_submission_statuses",      [          (              [Status.SUBMITTED, Status.PENDING, Status.RUNNING, Status.COMPLETED],              [SubmissionStatus.PENDING, SubmissionStatus.PENDING, SubmissionStatus.RUNNING, SubmissionStatus.COMPLETED],          ),          (              [Status.SUBMITTED, Status.PENDING, Status.RUNNING, Status.SKIPPED],              [SubmissionStatus.PENDING, SubmissionStatus.PENDING, SubmissionStatus.RUNNING, SubmissionStatus.COMPLETED],          ),          (              [Status.SUBMITTED, Status.PENDING, Status.RUNNING, Status.FAILED],              [SubmissionStatus.PENDING, SubmissionStatus.PENDING, SubmissionStatus.RUNNING, SubmissionStatus.FAILED],          ),          (              [Status.SUBMITTED, Status.PENDING, Status.CANCELED],              [SubmissionStatus.PENDING, SubmissionStatus.PENDING, SubmissionStatus.CANCELED],          ),          (              [Status.SUBMITTED, Status.PENDING, Status.RUNNING, Status.CANCELED],              [SubmissionStatus.PENDING, SubmissionStatus.PENDING, SubmissionStatus.RUNNING, SubmissionStatus.CANCELED],          ),          ([Status.SUBMITTED, Status.BLOCKED], [SubmissionStatus.PENDING, SubmissionStatus.BLOCKED]),          ([Status.SUBMITTED, Status.SKIPPED], [SubmissionStatus.PENDING, SubmissionStatus.COMPLETED]),      ],  )  def test_update_submission_status_with_single_job_completed(job_statuses, expected_submission_statuses):      job = MockJob("job_id", Status.SUBMITTED)      submission = Submission("submission_id", "ENTITY_TYPE")        assert submission.submission_status == SubmissionStatus.SUBMITTED        for job_status, submission_status in zip(job_statuses, expected_submission_statuses):          job.status = job_status          submission._update_submission_status(job)          assert submission.submission_status == submission_status      def __test_update_submission_status_with_two_jobs(job_ids, job_statuses, expected_submission_statuses):      jobs = {job_id: MockJob(job_id, Status.SUBMITTED) for job_id in job_ids}      submission = Submission("submission_id", "ENTITY_TYPE")        assert submission.submission_status == SubmissionStatus.SUBMITTED        for (job_id, job_status), submission_status in zip(job_statuses, expected_submission_statuses):          job = jobs[job_id]          job.status = job_status          submission._update_submission_status(job)          assert submission.submission_status == submission_status      @pytest.mark.parametrize(      "job_ids, job_statuses, expected_submission_statuses",      [          (              ["job_1", "job_2"],              [                  ("job_1", Status.SUBMITTED),                  ("job_2", Status.SUBMITTED),                  ("job_1", Status.PENDING),                  ("job_2", Status.PENDING),                  ("job_1", Status.RUNNING),                  ("job_2", Status.RUNNING),                  ("job_1", Status.COMPLETED),                  ("job_2", Status.COMPLETED),              ],              [                  SubmissionStatus.PENDING,                  SubmissionStatus.PENDING,                  SubmissionStatus.PENDING,                  SubmissionStatus.PENDING,                  SubmissionStatus.RUNNING,                  SubmissionStatus.RUNNING,                  SubmissionStatus.RUNNING,                  SubmissionStatus.COMPLETED,              ],          ),          (              ["job_1", "job_2"],              [                  ("job_1", Status.SUBMITTED),                  ("job_2", Status.SUBMITTED),                  ("job_1", Status.PENDING),                  ("job_1", Status.RUNNING),                  ("job_2", Status.PENDING),                  ("job_2", Status.RUNNING),                  ("job_1", Status.COMPLETED),                  ("job_2", Status.COMPLETED),              ],              [                  SubmissionStatus.PENDING,                  SubmissionStatus.PENDING,                  SubmissionStatus.PENDING,                  SubmissionStatus.RUNNING,                  SubmissionStatus.RUNNING,                  SubmissionStatus.RUNNING,                  SubmissionStatus.RUNNING,                  SubmissionStatus.COMPLETED,              ],          ),          (              ["job_1", "job_2"],              [                  ("job_1", Status.SUBMITTED),                  ("job_2", Status.SUBMITTED),                  ("job_1", Status.BLOCKED),                  ("job_2", Status.PENDING),                  ("job_2", Status.RUNNING),                  ("job_2", Status.COMPLETED),                  ("job_1", Status.PENDING),                  ("job_1", Status.RUNNING),                  ("job_1", Status.COMPLETED),              ],              [                  SubmissionStatus.PENDING,                  SubmissionStatus.PENDING,                  SubmissionStatus.PENDING,                  SubmissionStatus.PENDING,                  SubmissionStatus.RUNNING,                  SubmissionStatus.BLOCKED,                  SubmissionStatus.PENDING,                  SubmissionStatus.RUNNING,                  SubmissionStatus.COMPLETED,              ],          ),      ],  )  def test_update_submission_status_with_two_jobs_completed(job_ids, job_statuses, expected_submission_statuses):      __test_update_submission_status_with_two_jobs(job_ids, job_statuses, expected_submission_statuses)      @pytest.mark.parametrize(      "job_ids, job_statuses, expected_submission_statuses",      [          (              ["job_1", "job_2"],              [                  ("job_1", Status.SUBMITTED),                  ("job_2", Status.SUBMITTED),                  ("job_1", Status.PENDING),                  ("job_2", Status.PENDING),                  ("job_1", Status.RUNNING),                  ("job_2", Status.SKIPPED),                  ("job_1", Status.COMPLETED),              ],              [                  SubmissionStatus.PENDING,                  SubmissionStatus.PENDING,                  SubmissionStatus.PENDING,                  SubmissionStatus.PENDING,                  SubmissionStatus.RUNNING,                  SubmissionStatus.RUNNING,                  SubmissionStatus.COMPLETED,              ],          ),          (              ["job_1", "job_2"],              [                  ("job_1", Status.SUBMITTED),                  ("job_2", Status.SUBMITTED),                  ("job_1", Status.PENDING),                  ("job_1", Status.RUNNING),                  ("job_2", Status.PENDING),                  ("job_2", Status.SKIPPED),                  ("job_1", Status.COMPLETED),              ],              [                  SubmissionStatus.PENDING,                  SubmissionStatus.PENDING,                  SubmissionStatus.PENDING,                  SubmissionStatus.RUNNING,                  SubmissionStatus.RUNNING,                  SubmissionStatus.RUNNING,                  SubmissionStatus.COMPLETED,              ],          ),          (              ["job_1", "job_2"],              [                  ("job_1", Status.SUBMITTED),                  ("job_2", Status.SUBMITTED),                  ("job_1", Status.BLOCKED),                  ("job_2", Status.PENDING),                  ("job_2", Status.RUNNING),                  ("job_2", Status.COMPLETED),                  ("job_1", Status.PENDING),                  ("job_1", Status.SKIPPED),              ],              [                  SubmissionStatus.PENDING,                  SubmissionStatus.PENDING,                  SubmissionStatus.PENDING,                  SubmissionStatus.PENDING,                  SubmissionStatus.RUNNING,                  SubmissionStatus.BLOCKED,                  SubmissionStatus.PENDING,                  SubmissionStatus.COMPLETED,              ],          ),          (              ["job_1", "job_2"],              [                  ("job_1", Status.SUBMITTED),                  ("job_2", Status.SUBMITTED),                  ("job_1", Status.PENDING),                  ("job_2", Status.PENDING),                  ("job_1", Status.SKIPPED),                  ("job_2", Status.SKIPPED),              ],              [                  SubmissionStatus.PENDING,                  SubmissionStatus.PENDING,                  SubmissionStatus.PENDING,                  SubmissionStatus.PENDING,                  SubmissionStatus.PENDING,                  SubmissionStatus.COMPLETED,              ],          ),          (              ["job_1", "job_2"],              [                  ("job_1", Status.SUBMITTED),                  ("job_2", Status.SUBMITTED),                  ("job_1", Status.PENDING),                  ("job_1", Status.SKIPPED),                  ("job_2", Status.PENDING),                  ("job_2", Status.SKIPPED),              ],              [                  SubmissionStatus.PENDING,                  SubmissionStatus.PENDING,                  SubmissionStatus.PENDING,                  SubmissionStatus.PENDING,                  SubmissionStatus.PENDING,                  SubmissionStatus.COMPLETED,              ],          ),          (              ["job_1", "job_2"],              [                  ("job_1", Status.SUBMITTED),                  ("job_2", Status.SUBMITTED),                  ("job_1", Status.BLOCKED),                  ("job_2", Status.PENDING),                  ("job_2", Status.SKIPPED),                  ("job_1", Status.PENDING),                  ("job_1", Status.SKIPPED),              ],              [                  SubmissionStatus.PENDING,                  SubmissionStatus.PENDING,                  SubmissionStatus.PENDING,                  SubmissionStatus.PENDING,                  SubmissionStatus.BLOCKED,                  SubmissionStatus.PENDING,                  SubmissionStatus.COMPLETED,              ],          ),      ],  )  def test_update_submission_status_with_two_jobs_skipped(job_ids, job_statuses, expected_submission_statuses):      __test_update_submission_status_with_two_jobs(job_ids, job_statuses, expected_submission_statuses)      @pytest.mark.parametrize(      "job_ids, job_statuses, expected_submission_statuses",      [          (              ["job_1", "job_2"],              [                  ("job_1", Status.SUBMITTED),                  ("job_2", Status.SUBMITTED),                  ("job_1", Status.PENDING),                  ("job_2", Status.PENDING),                  ("job_1", Status.RUNNING),                  ("job_2", Status.RUNNING),                  ("job_1", Status.FAILED),                  ("job_2", Status.COMPLETED),              ],              [                  SubmissionStatus.PENDING,                  SubmissionStatus.PENDING,                  SubmissionStatus.PENDING,                  SubmissionStatus.PENDING,                  SubmissionStatus.RUNNING,                  SubmissionStatus.RUNNING,                  SubmissionStatus.FAILED,                  SubmissionStatus.FAILED,              ],          ),          (              ["job_1", "job_2"],              [                  ("job_1", Status.SUBMITTED),                  ("job_2", Status.SUBMITTED),                  ("job_1", Status.PENDING),                  ("job_1", Status.RUNNING),                  ("job_2", Status.PENDING),                  ("job_2", Status.RUNNING),                  ("job_1", Status.COMPLETED),                  ("job_2", Status.FAILED),              ],              [                  SubmissionStatus.PENDING,                  SubmissionStatus.PENDING,                  SubmissionStatus.PENDING,                  SubmissionStatus.RUNNING,                  SubmissionStatus.RUNNING,                  SubmissionStatus.RUNNING,                  SubmissionStatus.RUNNING,                  SubmissionStatus.FAILED,              ],          ),          (              ["job_1", "job_2"],              [                  ("job_1", Status.SUBMITTED),                  ("job_2", Status.SUBMITTED),                  ("job_1", Status.BLOCKED),                  ("job_2", Status.PENDING),                  ("job_2", Status.RUNNING),                  ("job_2", Status.FAILED),                  ("job_1", Status.ABANDONED),              ],              [                  SubmissionStatus.PENDING,                  SubmissionStatus.PENDING,                  SubmissionStatus.PENDING,                  SubmissionStatus.PENDING,                  SubmissionStatus.RUNNING,                  SubmissionStatus.FAILED,                  SubmissionStatus.FAILED,              ],          ),      ],  )  def test_update_submission_status_with_two_jobs_failed(job_ids, job_statuses, expected_submission_statuses):      __test_update_submission_status_with_two_jobs(job_ids, job_statuses, expected_submission_statuses)      @pytest.mark.parametrize(      "job_ids, job_statuses, expected_submission_statuses",      [          (              ["job_1", "job_2"],              [                  ("job_1", Status.SUBMITTED),                  ("job_2", Status.SUBMITTED),                  ("job_1", Status.PENDING),                  ("job_2", Status.PENDING),                  ("job_1", Status.RUNNING),                  ("job_2", Status.RUNNING),                  ("job_1", Status.CANCELED),                  ("job_2", Status.COMPLETED),              ],              [                  SubmissionStatus.PENDING,                  SubmissionStatus.PENDING,                  SubmissionStatus.PENDING,                  SubmissionStatus.PENDING,                  SubmissionStatus.RUNNING,                  SubmissionStatus.RUNNING,                  SubmissionStatus.CANCELED,                  SubmissionStatus.CANCELED,              ],          ),          (              ["job_1", "job_2"],              [                  ("job_1", Status.SUBMITTED),                  ("job_2", Status.SUBMITTED),                  ("job_1", Status.PENDING),                  ("job_1", Status.RUNNING),                  ("job_2", Status.PENDING),                  ("job_2", Status.RUNNING),                  ("job_1", Status.COMPLETED),                  ("job_2", Status.CANCELED),              ],              [                  SubmissionStatus.PENDING,                  SubmissionStatus.PENDING,                  SubmissionStatus.PENDING,                  SubmissionStatus.RUNNING,                  SubmissionStatus.RUNNING,                  SubmissionStatus.RUNNING,                  SubmissionStatus.RUNNING,                  SubmissionStatus.CANCELED,              ],          ),          (              ["job_1", "job_2"],              [                  ("job_1", Status.SUBMITTED),                  ("job_2", Status.SUBMITTED),                  ("job_1", Status.BLOCKED),                  ("job_2", Status.PENDING),                  ("job_2", Status.RUNNING),                  ("job_2", Status.CANCELED),                  ("job_1", Status.ABANDONED),              ],              [                  SubmissionStatus.PENDING,                  SubmissionStatus.PENDING,                  SubmissionStatus.PENDING,                  SubmissionStatus.PENDING,                  SubmissionStatus.RUNNING,                  SubmissionStatus.CANCELED,                  SubmissionStatus.CANCELED,              ],          ),      ],  )  def test_update_submission_status_with_two_jobs_canceled(job_ids, job_statuses, expected_submission_statuses):      __test_update_submission_status_with_two_jobs(job_ids, job_statuses, expected_submission_statuses)


from datetime import datetime  from time import sleep    from src.taipy.core import Task  from src.taipy.core._repository.db._sql_connection import _SQLConnection  from src.taipy.core._version._version_manager_factory import _VersionManagerFactory  from src.taipy.core.submission._submission_manager_factory import _SubmissionManagerFactory  from src.taipy.core.submission.submission import Submission  from src.taipy.core.submission.submission_status import SubmissionStatus      def init_managers():      _VersionManagerFactory._build_manager()._delete_all()      _SubmissionManagerFactory._build_manager()._delete_all()      def test_create_submission(scenario, init_sql_repo):      init_managers()        submission_1 = _SubmissionManagerFactory._build_manager()._create(scenario.id, scenario._ID_PREFIX)        assert submission_1.id is not None      assert submission_1.entity_id == scenario.id      assert submission_1.jobs == []      assert isinstance(submission_1.creation_date, datetime)      assert submission_1._submission_status == SubmissionStatus.SUBMITTED      def test_get_submission(init_sql_repo):      init_managers()        submission_manager = _SubmissionManagerFactory._build_manager()        submission_1 = submission_manager._create("entity_id", "ENTITY_TYPE")      submission_2 = submission_manager._get(submission_1.id)        assert submission_1.id == submission_2.id      assert submission_1.entity_id == submission_2.entity_id == "entity_id"      assert submission_1.jobs == submission_2.jobs      assert submission_1.creation_date == submission_2.creation_date      assert submission_1.submission_status == submission_2.submission_status      def test_get_all_submission(init_sql_repo):      init_managers()        submission_manager = _SubmissionManagerFactory._build_manager()      version_manager = _VersionManagerFactory._build_manager()        submission_manager._set(Submission("entity_id", "submission_id", version=version_manager._get_latest_version()))      for version_name in ["abc", "xyz"]:          for i in range(10):              submission_manager._set(                  Submission("entity_id", f"submission_{version_name}_{i}", version=f"{version_name}")              )      assert len(submission_manager._get_all()) == 1        version_manager._set_experiment_version("xyz")      version_manager._set_experiment_version("abc")      assert len(submission_manager._get_all()) == 10      assert len(submission_manager._get_all("abc")) == 10      assert len(submission_manager._get_all("xyz")) == 10      def test_get_latest_submission(init_sql_repo):      init_managers()        task_1 = Task("task_config_1", {}, print, id="task_id_1")      task_2 = Task("task_config_2", {}, print, id="task_id_2")        submission_manager = _SubmissionManagerFactory._build_manager()      submission_1 = submission_manager._create(task_1.id, task_1._ID_PREFIX)      assert submission_manager._get_latest(task_1) == submission_1      assert submission_manager._get_latest(task_2) is None        sleep(0.01)  # Comparison is based on time, precision on Windows is not enough important      submission_2 = submission_manager._create(task_2.id, task_2._ID_PREFIX)      assert submission_manager._get_latest(task_1) == submission_1      assert submission_manager._get_latest(task_2) == submission_2        sleep(0.01)  # Comparison is based on time, precision on Windows is not enough important      submission_3 = submission_manager._create(task_1.id, task_1._ID_PREFIX)      assert submission_manager._get_latest(task_1) == submission_3      assert submission_manager._get_latest(task_2) == submission_2        sleep(0.01)  # Comparison is based on time, precision on Windows is not enough important      submission_4 = submission_manager._create(task_2.id, task_2._ID_PREFIX)      assert submission_manager._get_latest(task_1) == submission_3      assert submission_manager._get_latest(task_2) == submission_4      def test_delete_submission(init_sql_repo):      init_managers()        submission_manager = _SubmissionManagerFactory._build_manager()        submission = Submission("entity_id", "submission_id")      submission_manager._set(submission)        for i in range(10):          submission_manager._set(Submission("entity_id", f"submission_{i}"))        assert len(submission_manager._get_all()) == 11      assert isinstance(submission_manager._get(submission.id), Submission)        submission_manager._delete(submission.id)      assert len(submission_manager._get_all()) == 10      assert submission_manager._get(submission.id) is None        submission_manager._delete_all()      assert len(submission_manager._get_all()) == 0


#  # Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with  # the License. You may obtain a copy of the License at  #  #        http://www.apache.org/licenses/LICENSE-2.0  #  # Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on  # an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the  # specific language governing permissions and limitations under the License.


import os  import pathlib  from unittest import TestCase, mock    from src.taipy.logger._taipy_logger import _TaipyLogger      class TestTaipyLogger(TestCase):      def test_taipy_logger(self):          _TaipyLogger._get_logger().info("baz")          _TaipyLogger._get_logger().debug("qux")        def test_taipy_logger_configured_by_file(self):          path = os.path.join(pathlib.Path(__file__).parent.resolve(), "logger.conf")          with mock.patch.dict(os.environ, {"TAIPY_LOGGER_CONFIG_PATH": path}):              _TaipyLogger._get_logger().info("baz")              _TaipyLogger._get_logger().debug("qux")


import os    import pytest    from src.taipy.config.config import Config  from src.taipy.config.exceptions.exceptions import ConfigurationUpdateBlocked  from tests.config.utils.named_temporary_file import NamedTemporaryFile    config_from_filename = NamedTemporaryFile(      """  [TAIPY]  custom_property_not_overwritten = true  custom_property_overwritten = 10  """  )    config_from_environment = NamedTemporaryFile(      """  [TAIPY]  custom_property_overwritten = 11  """  )      def test_load_from_environment_overwrite_load_from_filename():      os.environ[Config._ENVIRONMENT_VARIABLE_NAME_WITH_CONFIG_PATH] = config_from_environment.filename      Config.load(config_from_filename.filename)        assert Config.global_config.custom_property_not_overwritten is True      assert Config.global_config.custom_property_overwritten == 11      os.environ.pop(Config._ENVIRONMENT_VARIABLE_NAME_WITH_CONFIG_PATH)      def test_block_load_from_environment_overwrite_load_from_filename():      Config.load(config_from_filename.filename)      assert Config.global_config.custom_property_not_overwritten is True      assert Config.global_config.custom_property_overwritten == 10        Config.block_update()        with pytest.raises(ConfigurationUpdateBlocked):          os.environ[Config._ENVIRONMENT_VARIABLE_NAME_WITH_CONFIG_PATH] = config_from_environment.filename          Config.load(config_from_filename.filename)        os.environ.pop(Config._ENVIRONMENT_VARIABLE_NAME_WITH_CONFIG_PATH)      assert Config.global_config.custom_property_not_overwritten is True      assert Config.global_config.custom_property_overwritten == 10  # The Config.load is failed to override


import pytest    from src.taipy.config._config import _Config  from src.taipy.config._config_comparator._config_comparator import _ConfigComparator  from src.taipy.config._serializer._toml_serializer import _TomlSerializer  from src.taipy.config.checker.issue_collector import IssueCollector  from src.taipy.config.config import Config  from src.taipy.config.section import Section  from tests.config.utils.section_for_tests import SectionForTest  from tests.config.utils.unique_section_for_tests import UniqueSectionForTest      @pytest.fixture(scope="function", autouse=True)  def reset():      reset_configuration_singleton()      register_test_sections()      def reset_configuration_singleton():      Config.unblock_update()      Config._default_config = _Config()._default_config()      Config._python_config = _Config()      Config._file_config = _Config()      Config._env_file_config = _Config()      Config._applied_config = _Config()      Config._collector = IssueCollector()      Config._serializer = _TomlSerializer()      Config._comparator = _ConfigComparator()      def register_test_sections():      Config._register_default(UniqueSectionForTest("default_attribute"))      Config.configure_unique_section_for_tests = UniqueSectionForTest._configure      Config.unique_section_name = Config.unique_sections[UniqueSectionForTest.name]        Config._register_default(SectionForTest(Section._DEFAULT_KEY, "default_attribute", prop="default_prop", prop_int=0))      Config.configure_section_for_tests = SectionForTest._configure      Config.section_name = Config.sections[SectionForTest.name]


from unittest import mock    from src.taipy.config import Config  from src.taipy.config._config import _Config  from src.taipy.config._config_comparator._comparator_result import _ComparatorResult  from src.taipy.config.global_app.global_app_config import GlobalAppConfig  from tests.config.utils.section_for_tests import SectionForTest  from tests.config.utils.unique_section_for_tests import UniqueSectionForTest      class TestConfigComparator:      unique_section_1 = UniqueSectionForTest(attribute="unique_attribute_1", prop="unique_prop_1")      unique_section_1b = UniqueSectionForTest(attribute="unique_attribute_1", prop="unique_prop_1b")      section_1 = SectionForTest("section_1", attribute="attribute_1", prop="prop_1")      section_2 = SectionForTest("section_2", attribute=2, prop="prop_2")      section_2b = SectionForTest("section_2", attribute="attribute_2", prop="prop_2b")      section_3 = SectionForTest("section_3", attribute=[1, 2, 3, 4], prop=["prop_1"])      section_3b = SectionForTest("section_3", attribute=[1, 2], prop=["prop_1", "prop_2", "prop_3"])      section_3c = SectionForTest("section_3", attribute=[2, 1], prop=["prop_3", "prop_1", "prop_2"])        def test_comparator_compare_method_call(self):          _config_1 = _Config._default_config()          _config_2 = _Config._default_config()            with mock.patch(              "src.taipy.config._config_comparator._config_comparator._ConfigComparator._find_conflict_config"          ) as mck:              Config._comparator._find_conflict_config(_config_1, _config_2)              mck.assert_called_once_with(_config_1, _config_2)        def test_comparator_without_diff(self):          _config_1 = _Config._default_config()          _config_2 = _Config._default_config()            config_diff = Config._comparator._find_conflict_config(_config_1, _config_2)          assert isinstance(config_diff, _ComparatorResult)          assert config_diff == {}        def test_comparator_with_updated_global_config(self):          _config_1 = _Config._default_config()          _config_1._global_config = GlobalAppConfig(foo="bar")            _config_2 = _Config._default_config()          _config_2._global_config = GlobalAppConfig(foo="baz", bar="foo")            config_diff = Config._comparator._find_conflict_config(_config_1, _config_2)            assert config_diff.get("unconflicted_sections") is None          assert config_diff.get("conflicted_sections") is not None            conflicted_config_diff = config_diff["conflicted_sections"]          assert len(conflicted_config_diff["modified_items"]) == 1          assert conflicted_config_diff["modified_items"][0] == (              ("Global Configuration", "foo", None),              ("bar", "baz"),          )          assert len(conflicted_config_diff["added_items"]) == 1          assert conflicted_config_diff["added_items"][0] == (              ("Global Configuration", "bar", None),              "foo",          )        def test_comparator_with_new_section(self):          _config_1 = _Config._default_config()            # The first "section_name" is added to the Config          _config_2 = _Config._default_config()          _config_2._sections[SectionForTest.name] = {"section_1": self.section_1}          config_diff = Config._comparator._find_conflict_config(_config_1, _config_2)            conflicted_config_diff = config_diff["conflicted_sections"]          assert len(conflicted_config_diff["added_items"]) == 1          assert conflicted_config_diff["added_items"][0] == (              ("section_name", None, None),              {"section_1": {"attribute": "attribute_1", "prop": "prop_1"}},          )          assert conflicted_config_diff.get("modified_items") is None          assert conflicted_config_diff.get("removed_items") is None            # A new "section_name" is added to the Config          _config_3 = _Config._default_config()          _config_3._sections[SectionForTest.name] = {"section_1": self.section_1, "section_2": self.section_2}          config_diff = Config._comparator._find_conflict_config(_config_2, _config_3)            conflicted_config_diff = config_diff["conflicted_sections"]          assert len(conflicted_config_diff["added_items"]) == 1          assert conflicted_config_diff["added_items"][0] == (              ("section_name", "section_2", None),              {"attribute": "2:int", "prop": "prop_2"},          )          assert conflicted_config_diff.get("modified_items") is None          assert conflicted_config_diff.get("removed_items") is None        def test_comparator_with_removed_section(self):          _config_1 = _Config._default_config()            # All "section_name" sections are removed from the Config          _config_2 = _Config._default_config()          _config_2._sections[SectionForTest.name] = {"section_1": self.section_1}          config_diff = Config._comparator._find_conflict_config(_config_2, _config_1)            conflicted_config_diff = config_diff["conflicted_sections"]          assert len(conflicted_config_diff["removed_items"]) == 1          assert conflicted_config_diff["removed_items"][0] == (              ("section_name", None, None),              {"section_1": {"attribute": "attribute_1", "prop": "prop_1"}},          )          assert conflicted_config_diff.get("modified_items") is None          assert conflicted_config_diff.get("added_items") is None            # Section "section_1" is removed from the Config          _config_3 = _Config._default_config()          _config_3._sections[SectionForTest.name] = {"section_1": self.section_1, "section_2": self.section_2}          config_diff = Config._comparator._find_conflict_config(_config_3, _config_2)            conflicted_config_diff = config_diff["conflicted_sections"]          assert len(conflicted_config_diff["removed_items"]) == 1          assert conflicted_config_diff["removed_items"][0] == (              ("section_name", "section_2", None),              {"attribute": "2:int", "prop": "prop_2"},          )          assert conflicted_config_diff.get("modified_items") is None          assert conflicted_config_diff.get("added_items") is None        def test_comparator_with_modified_section(self):          _config_1 = _Config._default_config()          _config_1._sections[SectionForTest.name] = {"section_2": self.section_2}            # All "section_name" sections are removed from the Config          _config_2 = _Config._default_config()          _config_2._sections[SectionForTest.name] = {"section_2": self.section_2b}          config_diff = Config._comparator._find_conflict_config(_config_1, _config_2)            conflicted_config_diff = config_diff["conflicted_sections"]          assert len(conflicted_config_diff["modified_items"]) == 2          assert conflicted_config_diff["modified_items"][0] == (              ("section_name", "section_2", "attribute"),              ("2:int", "attribute_2"),          )          assert conflicted_config_diff["modified_items"][1] == (              ("section_name", "section_2", "prop"),              ("prop_2", "prop_2b"),          )          assert conflicted_config_diff.get("removed_items") is None          assert conflicted_config_diff.get("added_items") is None        def test_comparator_with_modified_list_attribute(self):          _config_1 = _Config._default_config()          _config_1._sections[SectionForTest.name] = {"section_3": self.section_3}            # All "section_name" sections are removed from the Config          _config_2 = _Config._default_config()          _config_2._sections[SectionForTest.name] = {"section_3": self.section_3b}          config_diff = Config._comparator._find_conflict_config(_config_1, _config_2)            conflicted_config_diff = config_diff["conflicted_sections"]          assert len(conflicted_config_diff["modified_items"]) == 2          assert conflicted_config_diff["modified_items"][0] == (              ("section_name", "section_3", "prop"),              (["prop_1"], ["prop_1", "prop_2", "prop_3"]),          )          assert conflicted_config_diff["modified_items"][1] == (              ("section_name", "section_3", "attribute"),              (["1:int", "2:int", "3:int", "4:int"], ["1:int", "2:int"]),          )          assert conflicted_config_diff.get("removed_items") is None          assert conflicted_config_diff.get("added_items") is None        def test_comparator_with_different_order_list_attributes(self):          _config_1 = _Config._default_config()          _config_1._unique_sections          _config_1._sections[SectionForTest.name] = {"section_3": self.section_3b}            # Create _config_2 with different order of list attributes          _config_2 = _Config._default_config()          _config_2._sections[SectionForTest.name] = {"section_3": self.section_3c}          config_diff = Config._comparator._find_conflict_config(_config_1, _config_2)            # There should be no difference since the order of list attributes is ignored          assert config_diff == {}        def test_comparator_with_new_unique_section(self):          _config_1 = _Config._default_config()            _config_2 = _Config._default_config()          _config_2._unique_sections[UniqueSectionForTest.name] = self.unique_section_1          config_diff = Config._comparator._find_conflict_config(_config_1, _config_2)            conflicted_config_diff = config_diff["conflicted_sections"]          assert len(conflicted_config_diff["added_items"]) == 1          assert conflicted_config_diff["added_items"][0] == (              ("unique_section_name", None, None),              {"attribute": "unique_attribute_1", "prop": "unique_prop_1"},          )          assert conflicted_config_diff.get("modified_items") is None          assert conflicted_config_diff.get("removed_items") is None        def test_comparator_with_removed_unique_section(self):          _config_1 = _Config._default_config()            _config_2 = _Config._default_config()          _config_2._unique_sections[UniqueSectionForTest.name] = self.unique_section_1          config_diff = Config._comparator._find_conflict_config(_config_2, _config_1)            conflicted_config_diff = config_diff["conflicted_sections"]          assert len(conflicted_config_diff["removed_items"]) == 1          assert conflicted_config_diff["removed_items"][0] == (              ("unique_section_name", None, None),              {"attribute": "unique_attribute_1", "prop": "unique_prop_1"},          )          assert conflicted_config_diff.get("modified_items") is None          assert conflicted_config_diff.get("added_items") is None        def test_comparator_with_modified_unique_section(self):          _config_1 = _Config._default_config()          _config_1._unique_sections[UniqueSectionForTest.name] = self.unique_section_1            # All "section_name" sections are removed from the Config          _config_2 = _Config._default_config()          _config_2._unique_sections[UniqueSectionForTest.name] = self.unique_section_1b          config_diff = Config._comparator._find_conflict_config(_config_1, _config_2)            conflicted_config_diff = config_diff["conflicted_sections"]          assert len(conflicted_config_diff["modified_items"]) == 1          assert conflicted_config_diff["modified_items"][0] == (              ("unique_section_name", "prop", None),              ("unique_prop_1", "unique_prop_1b"),          )          assert conflicted_config_diff.get("removed_items") is None          assert conflicted_config_diff.get("added_items") is None        def test_unconflicted_section_name_store_statically(self):          Config._comparator._add_unconflicted_section("section_name_1")          assert Config._comparator._unconflicted_sections == {"section_name_1"}            Config._comparator._add_unconflicted_section("section_name_2")          assert Config._comparator._unconflicted_sections == {"section_name_1", "section_name_2"}            Config._comparator._add_unconflicted_section("section_name_1")          assert Config._comparator._unconflicted_sections == {"section_name_1", "section_name_2"}        def test_unconflicted_diff_is_stored_separated_from_conflicted_ones(self):          _config_1 = _Config._default_config()          _config_1._unique_sections[UniqueSectionForTest.name] = self.unique_section_1          _config_1._sections[SectionForTest.name] = {"section_2": self.section_2}            _config_2 = _Config._default_config()          _config_2._unique_sections[UniqueSectionForTest.name] = self.unique_section_1b          _config_2._sections[SectionForTest.name] = {"section_2": self.section_2b}            # Compare 2 Configuration          config_diff = Config._comparator._find_conflict_config(_config_1, _config_2)            assert config_diff.get("unconflicted_sections") is None          assert config_diff.get("conflicted_sections") is not None          assert len(config_diff["conflicted_sections"]["modified_items"]) == 3            # Ignore any diff of "section_name" and compare          Config._comparator._add_unconflicted_section("section_name")          config_diff = Config._comparator._find_conflict_config(_config_1, _config_2)          assert config_diff.get("unconflicted_sections") is not None          assert len(config_diff["unconflicted_sections"]["modified_items"]) == 2          assert config_diff.get("conflicted_sections") is not None          assert len(config_diff["conflicted_sections"]["modified_items"]) == 1            # Ignore any diff of Global Config and compare          Config._comparator._add_unconflicted_section(["unique_section_name"])          config_diff = Config._comparator._find_conflict_config(_config_1, _config_2)          assert config_diff.get("unconflicted_sections") is not None          assert len(config_diff["unconflicted_sections"]["modified_items"]) == 3          assert config_diff.get("conflicted_sections") is None        def test_comparator_log_message(self, caplog):          _config_1 = _Config._default_config()          _config_1._unique_sections[UniqueSectionForTest.name] = self.unique_section_1          _config_1._sections[SectionForTest.name] = {"section_2": self.section_2}            _config_2 = _Config._default_config()          _config_2._unique_sections[UniqueSectionForTest.name] = self.unique_section_1b          _config_2._sections[SectionForTest.name] = {"section_2": self.section_2b}            # Ignore any diff of "section_name" and compare          Config._comparator._add_unconflicted_section("section_name")          Config._comparator._find_conflict_config(_config_1, _config_2)            error_messages = caplog.text.strip().split("\n")          assert len(error_messages) == 5          assert all(              t in error_messages[0]              for t in [                  "INFO",                  "There are non-conflicting changes between the current configuration and the current configuration:",              ]          )          assert 'section_name "section_2" has attribute "attribute" modified: 2:int -> attribute_2' in error_messages[1]          assert 'section_name "section_2" has attribute "prop" modified: prop_2 -> prop_2b' in error_messages[2]          assert all(              t in error_messages[3]              for t in [                  "ERROR",                  "The current configuration conflicts with the current configuration:",              ]          )          assert 'unique_section_name "prop" was modified: unique_prop_1 -> unique_prop_1b' in error_messages[4]            caplog.clear()            Config._comparator._find_conflict_config(_config_1, _config_2, old_version_number="1.0")            error_messages = caplog.text.strip().split("\n")          assert len(error_messages) == 5          assert all(              t in error_messages[0]              for t in [                  "INFO",                  "There are non-conflicting changes between the configuration for version 1.0 and the current "                  "configuration:",              ]          )          assert all(              t in error_messages[3]              for t in [                  "ERROR",                  "The configuration for version 1.0 conflicts with the current configuration:",              ]          )            caplog.clear()            Config._comparator._compare(              _config_1,              _config_2,              version_number_1="1.0",              version_number_2="2.0",          )            error_messages = caplog.text.strip().split("\n")          assert len(error_messages) == 3          assert all(              t in error_messages[0]              for t in ["INFO", "Differences between version 1.0 Configuration and version 2.0 Configuration:"]          )            caplog.clear()


import os  from unittest import mock    import pytest    from src.taipy.config.exceptions.exceptions import InvalidConfigurationId  from tests.config.utils.section_for_tests import SectionForTest  from tests.config.utils.unique_section_for_tests import UniqueSectionForTest      class WrongUniqueSection(UniqueSectionForTest):      name = "1wrong_id"      class WrongSection(SectionForTest):      name = "correct_name"      def test_section_uses_valid_id():      with pytest.raises(InvalidConfigurationId):          WrongUniqueSection(attribute="foo")      with pytest.raises(InvalidConfigurationId):          WrongSection("wrong id", attribute="foo")      with pytest.raises(InvalidConfigurationId):          WrongSection("1wrong_id", attribute="foo")      with pytest.raises(InvalidConfigurationId):          WrongSection("wrong_@id", attribute="foo")      def test_templated_properties_are_replaced():      with mock.patch.dict(os.environ, {"foo": "bar", "baz": "1"}):          u_sect = UniqueSectionForTest(attribute="attribute", tpl_property="ENV[foo]")          assert u_sect.tpl_property == "bar"            sect = SectionForTest(id="my_id", attribute="attribute", tpl_property="ENV[baz]:int")          assert sect.tpl_property == 1


from src.taipy.config.config import Config  from src.taipy.config.global_app.global_app_config import GlobalAppConfig  from src.taipy.config.section import Section  from tests.config.utils.section_for_tests import SectionForTest  from tests.config.utils.unique_section_for_tests import UniqueSectionForTest      def _test_default_global_app_config(global_config: GlobalAppConfig):      assert global_config is not None      assert not global_config.notification      assert len(global_config.properties) == 0      def test_default_configuration():      default_config = Config._default_config      assert default_config._unique_sections is not None      assert len(default_config._unique_sections) == 1      assert default_config._unique_sections[UniqueSectionForTest.name] is not None      assert default_config._unique_sections[UniqueSectionForTest.name].attribute == "default_attribute"      assert default_config._sections is not None      assert len(default_config._sections) == 1        _test_default_global_app_config(default_config._global_config)      _test_default_global_app_config(Config.global_config)      _test_default_global_app_config(GlobalAppConfig().default_config())      def test_register_default_configuration():      Config._register_default(SectionForTest(Section._DEFAULT_KEY, "default_attribute", prop1="prop1"))        # Replace the first default section      Config._register_default(SectionForTest(Section._DEFAULT_KEY, "default_attribute", prop2="prop2"))        default_section = Config.sections[SectionForTest.name][Section._DEFAULT_KEY]      assert len(default_section.properties) == 1      assert default_section.prop2 == "prop2"      assert default_section.prop1 is None


import pytest    from src.taipy.config.config import Config  from src.taipy.config.exceptions.exceptions import LoadingError  from tests.config.utils.named_temporary_file import NamedTemporaryFile      def test_node_can_not_appear_twice():      config = NamedTemporaryFile(          """  [unique_section_name]  attribute = "my_attribute"    [unique_section_name]  attribute = "other_attribute"      """      )        with pytest.raises(LoadingError, match="Can not load configuration"):          Config.load(config.filename)      def test_skip_configuration_outside_nodes():      config = NamedTemporaryFile(          """  foo = "bar"      """      )        Config.load(config.filename)      assert Config.global_config.foo is None


import os  from unittest import mock    import pytest    from src.taipy.config.config import Config  from src.taipy.config.exceptions.exceptions import InconsistentEnvVariableError, MissingEnvVariableError  from tests.config.utils.named_temporary_file import NamedTemporaryFile      def test_override_default_configuration_with_code_configuration():      assert not Config.global_config.root_folder == "foo"        assert len(Config.unique_sections) == 1      assert Config.unique_sections["unique_section_name"] is not None      assert Config.unique_sections["unique_section_name"].attribute == "default_attribute"      assert Config.unique_sections["unique_section_name"].prop is None        assert len(Config.sections) == 1      assert len(Config.sections["section_name"]) == 1      assert Config.sections["section_name"] is not None      assert Config.sections["section_name"]["default"].attribute == "default_attribute"        Config.configure_global_app(root_folder="foo")      assert Config.global_config.root_folder == "foo"        Config.configure_unique_section_for_tests("foo", prop="bar")      assert len(Config.unique_sections) == 1      assert Config.unique_sections["unique_section_name"] is not None      assert Config.unique_sections["unique_section_name"].attribute == "foo"      assert Config.unique_sections["unique_section_name"].prop == "bar"        Config.configure_section_for_tests("my_id", "baz", prop="qux")      assert len(Config.unique_sections) == 1      assert Config.sections["section_name"] is not None      assert Config.sections["section_name"]["my_id"].attribute == "baz"      assert Config.sections["section_name"]["my_id"].prop == "qux"      def test_override_default_config_with_code_config_including_env_variable_values():      Config.configure_global_app()      assert Config.global_config.foo is None      Config.configure_global_app(foo="bar")      assert Config.global_config.foo == "bar"        with mock.patch.dict(os.environ, {"FOO": "foo"}):          Config.configure_global_app(foo="ENV[FOO]")          assert Config.global_config.foo == "foo"      def test_override_default_configuration_with_file_configuration():      tf = NamedTemporaryFile(          """  [TAIPY]  foo = "bar"    """      )      assert Config.global_config.foo is None        Config.load(tf.filename)        assert Config.global_config.foo == "bar"      def test_override_default_config_with_file_config_including_env_variable_values():      tf = NamedTemporaryFile(          """  [TAIPY]  foo_attribute = "ENV[FOO]:int"  bar_attribute = "ENV[BAR]:bool"  """      )      assert Config.global_config.foo_attribute is None      assert Config.global_config.bar_attribute is None        with mock.patch.dict(os.environ, {"FOO": "foo", "BAR": "true"}):          with pytest.raises(InconsistentEnvVariableError):              Config.load(tf.filename)              Config.global_config.foo_attribute        with mock.patch.dict(os.environ, {"FOO": "5"}):          with pytest.raises(MissingEnvVariableError):              Config.load(tf.filename)              Config.global_config.bar_attribute        with mock.patch.dict(os.environ, {"FOO": "6", "BAR": "TRUe"}):          Config.load(tf.filename)          assert Config.global_config.foo_attribute == 6          assert Config.global_config.bar_attribute      def test_code_configuration_does_not_override_file_configuration():      config_from_filename = NamedTemporaryFile(          """  [TAIPY]  foo = 2      """      )      Config.override(config_from_filename.filename)        Config.configure_global_app(foo=21)        assert Config.global_config.foo == 2  # From file config      def test_code_configuration_does_not_override_file_configuration_including_env_variable_values():      config_from_filename = NamedTemporaryFile(          """  [TAIPY]  foo = 2      """      )      Config.override(config_from_filename.filename)        with mock.patch.dict(os.environ, {"FOO": "21"}):          Config.configure_global_app(foo="ENV[FOO]")          assert Config.global_config.foo == 2  # From file config      def test_file_configuration_overrides_code_configuration():      config_from_filename = NamedTemporaryFile(          """  [TAIPY]  foo = 2      """      )      Config.configure_global_app(foo=21)      Config.load(config_from_filename.filename)        assert Config.global_config.foo == 2  # From file config      def test_file_configuration_overrides_code_configuration_including_env_variable_values():      config_from_filename = NamedTemporaryFile(          """  [TAIPY]  foo = "ENV[FOO]:int"      """      )      Config.configure_global_app(foo=21)        with mock.patch.dict(os.environ, {"FOO": "2"}):          Config.load(config_from_filename.filename)          assert Config.global_config.foo == 2  # From file config      def test_override_default_configuration_with_multiple_configurations():      file_config = NamedTemporaryFile(          """  [TAIPY]  foo = 10  bar = "baz"      """      )      # Default config is applied      assert Config.global_config.foo is None      assert Config.global_config.bar is None        # Code config is applied      Config.configure_global_app(foo="bar")      assert Config.global_config.foo == "bar"      assert Config.global_config.bar is None        # File config is applied      Config.load(file_config.filename)      assert Config.global_config.foo == 10      assert Config.global_config.bar == "baz"      def test_override_default_configuration_with_multiple_configurations_including_environment_variable_values():      file_config = NamedTemporaryFile(          """  [TAIPY]  att = "ENV[BAZ]"      """      )        with mock.patch.dict(os.environ, {"FOO": "bar", "BAZ": "qux"}):          # Default config is applied          assert Config.global_config.att is None            # Code config is applied          Config.configure_global_app(att="ENV[FOO]")          assert Config.global_config.att == "bar"            # File config is applied          Config.load(file_config.filename)          assert Config.global_config.att == "qux"


import pytest    from src.taipy.config import Config  from src.taipy.config.exceptions.exceptions import ConfigurationUpdateBlocked  from tests.config.utils.section_for_tests import SectionForTest  from tests.config.utils.unique_section_for_tests import UniqueSectionForTest      def test_unique_section_registration_and_usage():      assert Config.unique_sections is not None      assert Config.unique_sections[UniqueSectionForTest.name] is not None      assert Config.unique_sections[UniqueSectionForTest.name].attribute == "default_attribute"      assert Config.unique_sections[UniqueSectionForTest.name].prop is None        mySection = Config.configure_unique_section_for_tests(attribute="my_attribute", prop="my_prop")        assert Config.unique_sections is not None      assert Config.unique_sections[UniqueSectionForTest.name] is not None      assert mySection is not None      assert Config.unique_sections[UniqueSectionForTest.name].attribute == "my_attribute"      assert mySection.attribute == "my_attribute"      assert Config.unique_sections[UniqueSectionForTest.name].prop == "my_prop"      assert mySection.prop == "my_prop"        myNewSection = Config.configure_unique_section_for_tests(attribute="my_new_attribute", prop="my_new_prop")        assert Config.unique_sections is not None      assert Config.unique_sections[UniqueSectionForTest.name] is not None      assert myNewSection is not None      assert mySection is not None      assert Config.unique_sections[UniqueSectionForTest.name].attribute == "my_new_attribute"      assert myNewSection.attribute == "my_new_attribute"      assert mySection.attribute == "my_new_attribute"      assert Config.unique_sections[UniqueSectionForTest.name].prop == "my_new_prop"      assert myNewSection.prop == "my_new_prop"      assert mySection.prop == "my_new_prop"      def test_sections_exposed_as_attribute():      assert Config.unique_section_name.attribute == "default_attribute"      Config.configure_unique_section_for_tests("my_attribute")      assert Config.unique_section_name.attribute == "my_attribute"        assert Config.section_name["default"].attribute == "default_attribute"      Config.configure_section_for_tests(id="my_id", attribute="my_attribute")      assert Config.section_name["my_id"].attribute == "my_attribute"      def test_section_registration_and_usage():      assert Config.sections is not None      assert len(Config.sections) == 1      assert Config.sections[SectionForTest.name] is not None      assert len(Config.sections[SectionForTest.name]) == 1      assert Config.sections[SectionForTest.name]["default"] is not None      assert Config.sections[SectionForTest.name]["default"].attribute == "default_attribute"      assert Config.sections[SectionForTest.name]["default"].prop == "default_prop"      assert Config.sections[SectionForTest.name]["default"].foo is None        myFirstSection = Config.configure_section_for_tests(id="first", attribute="my_attribute", prop="my_prop", foo="bar")      assert Config.sections is not None      assert len(Config.sections) == 1      assert Config.sections[SectionForTest.name] is not None      assert len(Config.sections[SectionForTest.name]) == 2      assert Config.sections[SectionForTest.name]["default"] is not None      assert Config.sections[SectionForTest.name]["default"].attribute == "default_attribute"      assert Config.sections[SectionForTest.name]["default"].prop == "default_prop"      assert Config.sections[SectionForTest.name]["default"].foo is None      assert Config.sections[SectionForTest.name]["first"] is not None      assert Config.sections[SectionForTest.name]["first"].attribute == "my_attribute"      assert Config.sections[SectionForTest.name]["first"].prop == "my_prop"      assert Config.sections[SectionForTest.name]["first"].foo == "bar"      assert myFirstSection.attribute == "my_attribute"      assert myFirstSection.prop == "my_prop"      assert myFirstSection.foo == "bar"        myNewSection = Config.configure_section_for_tests(id="second", attribute="my_new_attribute", prop="my_new_prop")      assert Config.sections is not None      assert len(Config.sections) == 1      assert Config.sections[SectionForTest.name] is not None      assert len(Config.sections[SectionForTest.name]) == 3      assert Config.sections[SectionForTest.name]["default"] is not None      assert Config.sections[SectionForTest.name]["default"].attribute == "default_attribute"      assert Config.sections[SectionForTest.name]["default"].prop == "default_prop"      assert Config.sections[SectionForTest.name]["default"].foo is None      assert Config.sections[SectionForTest.name]["first"] is not None      assert Config.sections[SectionForTest.name]["first"].attribute == "my_attribute"      assert Config.sections[SectionForTest.name]["first"].prop == "my_prop"      assert Config.sections[SectionForTest.name]["first"].foo == "bar"      assert Config.sections[SectionForTest.name]["second"] is not None      assert Config.sections[SectionForTest.name]["second"].attribute == "my_new_attribute"      assert Config.sections[SectionForTest.name]["second"].prop == "my_new_prop"      assert Config.sections[SectionForTest.name]["second"].foo is None      assert myFirstSection.attribute == "my_attribute"      assert myFirstSection.prop == "my_prop"      assert myFirstSection.foo == "bar"      assert myNewSection.attribute == "my_new_attribute"      assert myNewSection.prop == "my_new_prop"      assert myNewSection.foo is None        my2ndSection = Config.configure_section_for_tests(id="second", attribute="my_2nd_attribute", prop="my_2nd_prop")      assert Config.sections is not None      assert len(Config.sections) == 1      assert Config.sections[SectionForTest.name] is not None      assert len(Config.sections[SectionForTest.name]) == 3      assert Config.sections[SectionForTest.name]["default"] is not None      assert Config.sections[SectionForTest.name]["default"].attribute == "default_attribute"      assert Config.sections[SectionForTest.name]["default"].prop == "default_prop"      assert Config.sections[SectionForTest.name]["default"].foo is None      assert Config.sections[SectionForTest.name]["first"] is not None      assert Config.sections[SectionForTest.name]["first"].attribute == "my_attribute"      assert Config.sections[SectionForTest.name]["first"].prop == "my_prop"      assert Config.sections[SectionForTest.name]["first"].foo == "bar"      assert Config.sections[SectionForTest.name]["second"] is not None      assert Config.sections[SectionForTest.name]["second"].attribute == "my_2nd_attribute"      assert Config.sections[SectionForTest.name]["second"].prop == "my_2nd_prop"      assert Config.sections[SectionForTest.name]["second"].foo is None      assert myFirstSection.attribute == "my_attribute"      assert myFirstSection.prop == "my_prop"      assert myFirstSection.foo == "bar"      assert myNewSection.attribute == "my_2nd_attribute"      assert myNewSection.prop == "my_2nd_prop"      assert myNewSection.foo is None      assert my2ndSection.attribute == "my_2nd_attribute"      assert my2ndSection.prop == "my_2nd_prop"      assert my2ndSection.foo is None      def test_block_registration():      myUniqueSection = Config.configure_unique_section_for_tests(attribute="my_unique_attribute", prop="my_unique_prop")      mySection = Config.configure_section_for_tests(id="section_id", attribute="my_attribute", prop="my_prop", foo="bar")        Config.block_update()        with pytest.raises(ConfigurationUpdateBlocked):          Config.configure_unique_section_for_tests(attribute="my_new_unique_attribute", prop="my_new_unique_prop")        with pytest.raises(ConfigurationUpdateBlocked):          Config.configure_section_for_tests(id="new", attribute="my_attribute", prop="my_prop", foo="bar")        with pytest.raises(ConfigurationUpdateBlocked):          myUniqueSection.attribute = "foo"        with pytest.raises(ConfigurationUpdateBlocked):          myUniqueSection.properties = {"foo": "bar"}        # myUniqueSection stay the same      assert myUniqueSection.attribute == "my_unique_attribute"      assert myUniqueSection.properties == {"prop": "my_unique_prop"}        with pytest.raises(ConfigurationUpdateBlocked):          mySection.attribute = "foo"        with pytest.raises(ConfigurationUpdateBlocked):          mySection.properties = {"foo": "foo"}        # mySection stay the same      assert mySection.attribute == "my_attribute"      assert mySection.properties == {"prop": "my_prop", "foo": "bar", "prop_int": 0}


import pytest    from src.taipy.config.config import Config  from src.taipy.config.section import Section  from tests.config.utils.named_temporary_file import NamedTemporaryFile  from tests.config.utils.section_for_tests import SectionForTest  from tests.config.utils.section_of_sections_list_for_tests import SectionOfSectionsListForTest      @pytest.fixture  def _init_list_section_for_test():      Config._register_default(SectionOfSectionsListForTest(Section._DEFAULT_KEY, [], prop="default_prop", prop_int=0))      Config.configure_list_section_for_tests = SectionOfSectionsListForTest._configure      Config.list_section_name = Config.sections[SectionOfSectionsListForTest.name]      def test_applied_config_compilation_does_not_change_other_configs():      assert len(Config._default_config._unique_sections) == 1      assert Config._default_config._unique_sections["unique_section_name"] is not None      assert Config._default_config._unique_sections["unique_section_name"].attribute == "default_attribute"      assert Config._default_config._unique_sections["unique_section_name"].prop is None      assert len(Config._python_config._unique_sections) == 0      assert len(Config._file_config._unique_sections) == 0      assert len(Config._env_file_config._unique_sections) == 0      assert len(Config._applied_config._unique_sections) == 1      assert Config._applied_config._unique_sections["unique_section_name"] is not None      assert Config._applied_config._unique_sections["unique_section_name"].attribute == "default_attribute"      assert Config._applied_config._unique_sections["unique_section_name"].prop is None      assert len(Config.unique_sections) == 1      assert Config.unique_sections["unique_section_name"] is not None      assert Config.unique_sections["unique_section_name"].attribute == "default_attribute"      assert Config.unique_sections["unique_section_name"].prop is None      assert (          Config._applied_config._unique_sections["unique_section_name"]          is not Config._default_config._unique_sections["unique_section_name"]      )        Config.configure_unique_section_for_tests("qwe", prop="rty")        assert len(Config._default_config._unique_sections) == 1      assert Config._default_config._unique_sections["unique_section_name"] is not None      assert Config._default_config._unique_sections["unique_section_name"].attribute == "default_attribute"      assert Config._default_config._unique_sections["unique_section_name"].prop is None      assert len(Config._python_config._unique_sections) == 1      assert Config._python_config._unique_sections["unique_section_name"] is not None      assert Config._python_config._unique_sections["unique_section_name"].attribute == "qwe"      assert Config._python_config._unique_sections["unique_section_name"].prop == "rty"      assert (          Config._python_config._unique_sections["unique_section_name"]          != Config._default_config._unique_sections["unique_section_name"]      )      assert len(Config._file_config._unique_sections) == 0      assert len(Config._env_file_config._unique_sections) == 0      assert len(Config._applied_config._unique_sections) == 1      assert Config._applied_config._unique_sections["unique_section_name"] is not None      assert Config._applied_config._unique_sections["unique_section_name"].attribute == "qwe"      assert Config._applied_config._unique_sections["unique_section_name"].prop == "rty"      assert (          Config._python_config._unique_sections["unique_section_name"]          != Config._applied_config._unique_sections["unique_section_name"]      )      assert (          Config._default_config._unique_sections["unique_section_name"]          != Config._applied_config._unique_sections["unique_section_name"]      )      assert len(Config.unique_sections) == 1      assert Config.unique_sections["unique_section_name"] is not None      assert Config.unique_sections["unique_section_name"].attribute == "qwe"      assert Config.unique_sections["unique_section_name"].prop == "rty"      def test_nested_section_instance_in_python(_init_list_section_for_test):      s1_cfg = Config.configure_section_for_tests("s1", attribute="foo")      s2_cfg = Config.configure_section_for_tests("s2", attribute="bar")      ss_cfg = Config.configure_list_section_for_tests("ss", attribute="foo", sections_list=[s1_cfg, s2_cfg])        s1_config_applied_instance = Config.section_name["s1"]      s1_config_python_instance = Config._python_config._sections[SectionForTest.name]["s1"]        s2_config_applied_instance = Config.section_name["s2"]      s2_config_python_instance = Config._python_config._sections[SectionForTest.name]["s2"]        assert ss_cfg.sections_list[0] is s1_config_applied_instance      assert ss_cfg.sections_list[0] is not s1_config_python_instance      assert ss_cfg.sections_list[1] is s2_config_applied_instance      assert ss_cfg.sections_list[1] is not s2_config_python_instance      def _configure_in_toml():      return NamedTemporaryFile(          content="""  [TAIPY]    [section_name.s1]  attribute = "foo"    [section_name.s2]  attribute = "bar"    [list_section_name.ss]  sections_list = [ "foo", "s1:SECTION", "s2:SECTION"]      """      )      def test_nested_section_instance_load_toml(_init_list_section_for_test):      toml_config = _configure_in_toml()      Config.load(toml_config)        s1_config_applied_instance = Config.section_name["s1"]      s1_config_python_instance = Config._python_config._sections[SectionForTest.name]["s1"]        s2_config_applied_instance = Config.section_name["s2"]      s2_config_python_instance = Config._python_config._sections[SectionForTest.name]["s2"]        ss_cfg = Config.list_section_name["ss"]        assert ss_cfg.sections_list[0] == "foo"      assert ss_cfg.sections_list[1] is s1_config_applied_instance      assert ss_cfg.sections_list[1] is not s1_config_python_instance      assert ss_cfg.sections_list[2] is s2_config_applied_instance      assert ss_cfg.sections_list[2] is not s2_config_python_instance      def test_nested_section_instance_override_toml(_init_list_section_for_test):      toml_config = _configure_in_toml()      Config.override(toml_config)        s1_config_applied_instance = Config.section_name["s1"]      s1_config_python_instance = Config._file_config._sections[SectionForTest.name]["s1"]        s2_config_applied_instance = Config.section_name["s2"]      s2_config_python_instance = Config._file_config._sections[SectionForTest.name]["s2"]        ss_cfg = Config.list_section_name["ss"]        assert ss_cfg.sections_list[0] == "foo"      assert ss_cfg.sections_list[1] is s1_config_applied_instance      assert ss_cfg.sections_list[1] is not s1_config_python_instance      assert ss_cfg.sections_list[2] is s2_config_applied_instance      assert ss_cfg.sections_list[1] is not s2_config_python_instance


import datetime  import json  import os  from unittest import mock    from src.taipy.config import Config  from src.taipy.config._serializer._json_serializer import _JsonSerializer  from src.taipy.config.common.frequency import Frequency  from src.taipy.config.common.scope import Scope  from tests.config.utils.named_temporary_file import NamedTemporaryFile  from tests.config.utils.section_for_tests import SectionForTest  from tests.config.utils.unique_section_for_tests import UniqueSectionForTest      def add(a, b):      return a + b      class CustomClass:      a = None      b = None      class CustomEncoder(json.JSONEncoder):      def default(self, o):          if isinstance(o, datetime):              result = {"__type__": "Datetime", "__value__": o.isoformat()}          else:              result = json.JSONEncoder.default(self, o)          return result      class CustomDecoder(json.JSONDecoder):      def __init__(self, *args, **kwargs):          json.JSONDecoder.__init__(self, object_hook=self.object_hook, *args, **kwargs)        def object_hook(self, source):          if source.get("__type__") == "Datetime":              return datetime.fromisoformat(source.get("__value__"))          else:              return source      def test_write_toml_configuration_file():      expected_toml_config = """  [TAIPY]    [unique_section_name]  attribute = "my_attribute"  prop = "my_prop"  prop_int = "1:int"  prop_bool = "False:bool"  prop_list = [ "p1", "1991-01-01T00:00:00:datetime", "1d0h0m0s:timedelta",]  prop_scope = "SCENARIO:SCOPE"  prop_freq = "QUARTERLY:FREQUENCY"  baz = "ENV[QUX]"  quux = "ENV[QUUZ]:bool"  corge = [ "grault", "ENV[GARPLY]", "ENV[WALDO]:int", "3.0:float",]    [section_name.default]  attribute = "default_attribute"  prop = "default_prop"  prop_int = "0:int"    [section_name.my_id]  attribute = "my_attribute"  prop = "default_prop"  prop_int = "1:int"  prop_bool = "False:bool"  prop_list = [ "unique_section_name:SECTION",]  prop_scope = "SCENARIO"  baz = "ENV[QUX]"      """.strip()      tf = NamedTemporaryFile()      with mock.patch.dict(          os.environ, {"FOO": "in_memory", "QUX": "qux", "QUUZ": "true", "GARPLY": "garply", "WALDO": "17"}      ):          unique_section = Config.configure_unique_section_for_tests(              attribute="my_attribute",              prop="my_prop",              prop_int=1,              prop_bool=False,              prop_list=["p1", datetime.datetime(1991, 1, 1), datetime.timedelta(days=1)],              prop_scope=Scope.SCENARIO,              prop_freq=Frequency.QUARTERLY,              baz="ENV[QUX]",              quux="ENV[QUUZ]:bool",              corge=("grault", "ENV[GARPLY]", "ENV[WALDO]:int", 3.0),          )          Config.configure_section_for_tests(              "my_id",              "my_attribute",              prop_int=1,              prop_bool=False,              prop_list=[unique_section],              prop_scope="SCENARIO",              baz="ENV[QUX]",          )            Config.backup(tf.filename)          actual_config = tf.read().strip()          assert actual_config == expected_toml_config      def test_read_toml_configuration_file():      toml_config = """  [TAIPY]  foo = "bar"    [unique_section_name]  attribute = "my_attribute"  prop = "my_prop"  prop_int = "1:int"  prop_bool = "False:bool"  prop_list = [ "p1", "1991-01-01T00:00:00:datetime", "1d0h0m0s:timedelta",]  prop_scope = "SCENARIO:SCOPE"  prop_freq = "QUARTERLY:FREQUENCY"  baz = "ENV[QUX]"  quux = "ENV[QUUZ]:bool"  corge = [ "grault", "ENV[GARPLY]", "ENV[WALDO]:int", "3.0:float",]    [TAIPY.custom_properties]  bar = "baz"    [section_name.default]  attribute = "default_attribute"  prop = "default_prop"  prop_int = "0:int"    [section_name.my_id]  attribute = "my_attribute"  prop = "default_prop"  prop_int = "1:int"  prop_bool = "False:bool"  prop_list = [ "unique_section_name", "section_name.my_id",]  prop_scope = "SCENARIO:SCOPE"  baz = "ENV[QUX]"      """.strip()      tf = NamedTemporaryFile(toml_config)      with mock.patch.dict(          os.environ, {"FOO": "in_memory", "QUX": "qux", "QUUZ": "true", "GARPLY": "garply", "WALDO": "17"}      ):          Config.override(tf.filename)            assert Config.global_config.foo == "bar"          assert Config.global_config.custom_properties.get("bar") == "baz"            assert Config.unique_sections is not None          assert Config.unique_sections[UniqueSectionForTest.name] is not None          assert Config.unique_sections[UniqueSectionForTest.name].attribute == "my_attribute"          assert Config.unique_sections[UniqueSectionForTest.name].prop == "my_prop"          assert Config.unique_sections[UniqueSectionForTest.name].prop_int == 1          assert Config.unique_sections[UniqueSectionForTest.name].prop_bool is False          assert Config.unique_sections[UniqueSectionForTest.name].prop_list == [              "p1",              datetime.datetime(1991, 1, 1),              datetime.timedelta(days=1),          ]          assert Config.unique_sections[UniqueSectionForTest.name].prop_scope == Scope.SCENARIO          assert Config.unique_sections[UniqueSectionForTest.name].prop_freq == Frequency.QUARTERLY          assert Config.unique_sections[UniqueSectionForTest.name].baz == "qux"          assert Config.unique_sections[UniqueSectionForTest.name].quux is True          assert Config.unique_sections[UniqueSectionForTest.name].corge == [              "grault",              "garply",              17,              3.0,          ]            assert Config.sections is not None          assert len(Config.sections) == 1          assert Config.sections[SectionForTest.name] is not None          assert len(Config.sections[SectionForTest.name]) == 2          assert Config.sections[SectionForTest.name]["default"] is not None          assert Config.sections[SectionForTest.name]["default"].attribute == "default_attribute"          assert Config.sections[SectionForTest.name]["default"].prop == "default_prop"          assert Config.sections[SectionForTest.name]["default"].prop_int == 0          assert Config.sections[SectionForTest.name]["my_id"] is not None          assert Config.sections[SectionForTest.name]["my_id"].attribute == "my_attribute"          assert Config.sections[SectionForTest.name]["my_id"].prop == "default_prop"          assert Config.sections[SectionForTest.name]["my_id"].prop_int == 1          assert Config.sections[SectionForTest.name]["my_id"].prop_bool is False          assert Config.sections[SectionForTest.name]["my_id"].prop_list == ["unique_section_name", "section_name.my_id"]          assert Config.sections[SectionForTest.name]["my_id"].prop_scope == Scope.SCENARIO          assert Config.sections[SectionForTest.name]["my_id"].baz == "qux"            tf2 = NamedTemporaryFile()          Config.backup(tf2.filename)          actual_config_2 = tf2.read().strip()          assert actual_config_2 == toml_config      def test_read_write_toml_configuration_file_with_function_and_class():      expected_toml_config = """  [TAIPY]    [unique_section_name]  attribute = "my_attribute"  prop = "my_prop"  prop_list = [ "tests.config.test_section_serialization.CustomEncoder:class", \  "tests.config.test_section_serialization.CustomDecoder:class",]    [section_name.default]  attribute = "default_attribute"  prop = "default_prop"  prop_int = "0:int"    [section_name.my_id]  attribute = "my_attribute"  prop = "default_prop"  prop_int = "0:int"  prop_fct_list = [ "tests.config.test_section_serialization.add:function",]  prop_class_list = [ "tests.config.test_section_serialization.CustomClass:class",]    [section_name.my_id_2]  attribute = "my_attribute_2"  prop = "default_prop"  prop_int = "0:int"  prop_fct_list = [ "builtins.print:function", "builtins.pow:function",]      """.strip()        tf = NamedTemporaryFile()      Config.configure_unique_section_for_tests(          attribute="my_attribute",          prop="my_prop",          prop_list=[CustomEncoder, CustomDecoder],      )      Config.configure_section_for_tests(          "my_id",          "my_attribute",          prop_fct_list=[add],          prop_class_list=[CustomClass],      )        Config.configure_section_for_tests(          "my_id_2",          "my_attribute_2",          prop_fct_list=[print, pow],      )        Config.backup(tf.filename)      actual_exported_toml = tf.read().strip()      assert actual_exported_toml == expected_toml_config        Config.override(tf.filename)      tf2 = NamedTemporaryFile()      Config.backup(tf2.filename)        actual_exported_toml_2 = tf2.read().strip()      assert actual_exported_toml_2 == expected_toml_config      def test_write_json_configuration_file():      expected_json_config = """  {  "TAIPY": {},  "unique_section_name": {  "attribute": "my_attribute",  "prop": "my_prop",  "prop_int": "1:int",  "prop_bool": "False:bool",  "prop_list": [  "p1",  "1991-01-01T00:00:00:datetime",  "1d0h0m0s:timedelta"  ],  "prop_scope": "SCENARIO:SCOPE",  "prop_freq": "QUARTERLY:FREQUENCY"  },  "section_name": {  "default": {  "attribute": "default_attribute",  "prop": "default_prop",  "prop_int": "0:int"  },  "my_id": {  "attribute": "my_attribute",  "prop": "default_prop",  "prop_int": "1:int",  "prop_bool": "False:bool",  "prop_list": [  "unique_section_name:SECTION"  ],  "prop_scope": "SCENARIO",  "baz": "ENV[QUX]"  }  }  }      """.strip()      tf = NamedTemporaryFile()      Config._serializer = _JsonSerializer()        unique_section = Config.configure_unique_section_for_tests(          attribute="my_attribute",          prop="my_prop",          prop_int=1,          prop_bool=False,          prop_list=["p1", datetime.datetime(1991, 1, 1), datetime.timedelta(days=1)],          prop_scope=Scope.SCENARIO,          prop_freq=Frequency.QUARTERLY,      )      Config.configure_section_for_tests(          "my_id",          "my_attribute",          prop_int=1,          prop_bool=False,          prop_list=[unique_section],          prop_scope="SCENARIO",          baz="ENV[QUX]",      )      Config.backup(tf.filename)      actual_config = tf.read()      assert actual_config == expected_json_config      def test_read_json_configuration_file():      json_config = """  {  "TAIPY": {  "root_folder": "./taipy/",  "storage_folder": ".data/",  "repository_type": "filesystem"  },  "unique_section_name": {  "attribute": "my_attribute",  "prop": "my_prop",  "prop_int": "1:int",  "prop_bool": "False:bool",  "prop_list": [  "p1",  "1991-01-01T00:00:00:datetime",  "1d0h0m0s:timedelta"  ],  "prop_scope": "SCENARIO:SCOPE",  "prop_freq": "QUARTERLY:FREQUENCY"  },  "section_name": {  "default": {  "attribute": "default_attribute",  "prop": "default_prop",  "prop_int": "0:int"  },  "my_id": {  "attribute": "my_attribute",  "prop": "default_prop",  "prop_int": "1:int",  "prop_bool": "False:bool",  "prop_list": [  "unique_section_name"  ],  "prop_scope": "SCENARIO"  }  }  }      """.strip()      Config._serializer = _JsonSerializer()      tf = NamedTemporaryFile(json_config)        Config.override(tf.filename)        assert Config.unique_sections is not None      assert Config.unique_sections[UniqueSectionForTest.name] is not None      assert Config.unique_sections[UniqueSectionForTest.name].attribute == "my_attribute"      assert Config.unique_sections[UniqueSectionForTest.name].prop == "my_prop"      assert Config.unique_sections[UniqueSectionForTest.name].prop_int == 1      assert Config.unique_sections[UniqueSectionForTest.name].prop_bool is False      assert Config.unique_sections[UniqueSectionForTest.name].prop_list == [          "p1",          datetime.datetime(1991, 1, 1),          datetime.timedelta(days=1),      ]      assert Config.unique_sections[UniqueSectionForTest.name].prop_scope == Scope.SCENARIO      assert Config.unique_sections[UniqueSectionForTest.name].prop_freq == Frequency.QUARTERLY        assert Config.sections is not None      assert len(Config.sections) == 1      assert Config.sections[SectionForTest.name] is not None      assert len(Config.sections[SectionForTest.name]) == 2      assert Config.sections[SectionForTest.name]["default"] is not None      assert Config.sections[SectionForTest.name]["default"].attribute == "default_attribute"      assert Config.sections[SectionForTest.name]["default"].prop == "default_prop"      assert Config.sections[SectionForTest.name]["default"].prop_int == 0      assert Config.sections[SectionForTest.name]["my_id"] is not None      assert Config.sections[SectionForTest.name]["my_id"].attribute == "my_attribute"      assert Config.sections[SectionForTest.name]["my_id"].prop == "default_prop"      assert Config.sections[SectionForTest.name]["my_id"].prop_int == 1      assert Config.sections[SectionForTest.name]["my_id"].prop_bool is False      assert Config.sections[SectionForTest.name]["my_id"].prop_list == ["unique_section_name"]        tf2 = NamedTemporaryFile()      Config.backup(tf2.filename)      actual_config_2 = tf2.read().strip()      assert actual_config_2 == json_config      def test_read_write_json_configuration_file_with_function_and_class():      expected_json_config = """  {  "TAIPY": {},  "unique_section_name": {  "attribute": "my_attribute",  "prop": "my_prop",  "prop_list": [  "tests.config.test_section_serialization.CustomEncoder:class",  "tests.config.test_section_serialization.CustomDecoder:class"  ]  },  "section_name": {  "default": {  "attribute": "default_attribute",  "prop": "default_prop",  "prop_int": "0:int"  },  "my_id": {  "attribute": "my_attribute",  "prop": "default_prop",  "prop_int": "0:int",  "prop_fct_list": [  "tests.config.test_section_serialization.add:function"  ],  "prop_class_list": [  "tests.config.test_section_serialization.CustomClass:class"  ]  },  "my_id_2": {  "attribute": "my_attribute_2",  "prop": "default_prop",  "prop_int": "0:int",  "prop_fct_list": [  "builtins.print:function",  "builtins.pow:function"  ]  }  }  }      """.strip()        Config._serializer = _JsonSerializer()      tf = NamedTemporaryFile()      Config.configure_unique_section_for_tests(          attribute="my_attribute",          prop="my_prop",          prop_list=[CustomEncoder, CustomDecoder],      )      Config.configure_section_for_tests(          "my_id",          "my_attribute",          prop_fct_list=[add],          prop_class_list=[CustomClass],      )      Config.configure_section_for_tests(          "my_id_2",          "my_attribute_2",          prop_fct_list=[print, pow],      )        Config.backup(tf.filename)      actual_exported_json = tf.read().strip()      assert actual_exported_json == expected_json_config        Config.override(tf.filename)      tf2 = NamedTemporaryFile()      Config.backup(tf2.filename)        actual_exported_json_2 = tf2.read().strip()      assert actual_exported_json_2 == expected_json_config


from src.taipy.config._config import _Config  from src.taipy.config.checker._checker import _Checker      class TestDefaultConfigChecker:      def test_check_default_config(self):          config = _Config._default_config()          collector = _Checker._check(config)          assert len(collector._errors) == 0          assert len(collector._infos) == 0          assert len(collector._warnings) == 0