test_task_model.py 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  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 import Scope
  12. from taipy.core.data import InMemoryDataNode
  13. from taipy.core.data._data_manager_factory import _DataManagerFactory
  14. from taipy.core.task._task_model import _TaskModel
  15. def test_none_properties_attribute_compatible():
  16. model = _TaskModel.from_dict(
  17. {
  18. "id": "id",
  19. "config_id": "config_id",
  20. "parent_id": "owner_id",
  21. "parent_ids": ["parent_id"],
  22. "input_ids": ["input_id"],
  23. "function_name": "function_name",
  24. "function_module": "function_module",
  25. "output_ids": ["output_id"],
  26. "version": "latest",
  27. "skippable": False,
  28. }
  29. )
  30. assert len(model.properties) == 0
  31. def test_skippable_compatibility_with_non_existing_output():
  32. model = _TaskModel.from_dict(
  33. {
  34. "id": "id",
  35. "config_id": "config_id",
  36. "owner_id": "owner_id",
  37. "parent_ids": ["parent_id"],
  38. "input_ids": ["input_id"],
  39. "function_name": "function_name",
  40. "function_module": "function_module",
  41. "output_ids": ["output_id"],
  42. "version": "latest",
  43. "skippable": False,
  44. }
  45. )
  46. assert not model.skippable
  47. def test_skippable_compatibility_with_no_output():
  48. model = _TaskModel.from_dict(
  49. {
  50. "id": "id",
  51. "config_id": "config_id",
  52. "owner_id": "owner_id",
  53. "parent_ids": ["parent_id"],
  54. "input_ids": ["input_id"],
  55. "function_name": "function_name",
  56. "function_module": "function_module",
  57. "output_ids": [],
  58. "version": "latest",
  59. "skippable": False,
  60. }
  61. )
  62. assert not model.skippable
  63. def test_skippable_compatibility_with_one_output():
  64. manager = _DataManagerFactory._build_manager()
  65. manager._repository._save(InMemoryDataNode("cfg_id", Scope.SCENARIO, id="dn_id"))
  66. model = _TaskModel.from_dict(
  67. {
  68. "id": "id",
  69. "config_id": "config_id",
  70. "owner_id": "owner_id",
  71. "parent_ids": ["parent_id"],
  72. "input_ids": ["input_id"],
  73. "function_name": "function_name",
  74. "function_module": "function_module",
  75. "output_ids": ["dn_id"],
  76. "version": "latest",
  77. "skippable": True,
  78. }
  79. )
  80. assert model.skippable
  81. def test_skippable_compatibility_with_many_outputs():
  82. manager = _DataManagerFactory._build_manager()
  83. manager._repository._save(InMemoryDataNode("cfg_id", Scope.SCENARIO, id="dn_id"))
  84. manager._repository._save(InMemoryDataNode("cfg_id_2", Scope.SCENARIO, id="dn_2_id"))
  85. model = _TaskModel.from_dict(
  86. {
  87. "id": "id",
  88. "config_id": "config_id",
  89. "owner_id": "owner_id",
  90. "parent_ids": ["parent_id"],
  91. "input_ids": ["input_id"],
  92. "function_name": "function_name",
  93. "function_module": "function_module",
  94. "output_ids": ["dn_id", "dn_2_id"],
  95. "version": "latest",
  96. "skippable": True,
  97. }
  98. )
  99. assert model.skippable