test_sequence_converter.py 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. # Copyright 2021-2025 Avaiga Private Limited
  2. #
  3. # Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
  4. # the License. You may obtain a copy of the License at
  5. #
  6. # http://www.apache.org/licenses/LICENSE-2.0
  7. #
  8. # Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
  9. # an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
  10. # specific language governing permissions and limitations under the License.
  11. from taipy.core.sequence._sequence_converter import _SequenceConverter
  12. from taipy.core.sequence.sequence import Sequence
  13. from taipy.core.task.task import Task
  14. def test_entity_to_model(sequence):
  15. sequence_model_1 = _SequenceConverter._entity_to_model(sequence)
  16. expected_sequence_model_1 = {
  17. "id": "sequence_id",
  18. "owner_id": "owner_id",
  19. "parent_ids": ["parent_id_1", "parent_id_2"],
  20. "properties": {},
  21. "tasks": [],
  22. "subscribers": [],
  23. "version": "random_version_number",
  24. }
  25. sequence_model_1["parent_ids"] = sorted(sequence_model_1["parent_ids"])
  26. assert sequence_model_1 == expected_sequence_model_1
  27. task_1 = Task("task_1", {}, print)
  28. task_2 = Task("task_2", {}, print)
  29. sequence_2 = Sequence(
  30. {"name": "sequence_2"},
  31. [task_1, task_2],
  32. "SEQUENCE_sq_1_SCENARIO_sc",
  33. "SCENARIO_sc",
  34. ["SCENARIO_sc"],
  35. [],
  36. "random_version",
  37. )
  38. sequence_model_2 = _SequenceConverter._entity_to_model(sequence_2)
  39. expected_sequence_model_2 = {
  40. "id": "SEQUENCE_sq_1_SCENARIO_sc",
  41. "owner_id": "SCENARIO_sc",
  42. "parent_ids": ["SCENARIO_sc"],
  43. "properties": {"name": "sequence_2"},
  44. "tasks": [task_1.id, task_2.id],
  45. "subscribers": [],
  46. "version": "random_version",
  47. }
  48. assert sequence_model_2 == expected_sequence_model_2