conftest.py 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. # Copyright 2021-2024 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 datetime import datetime
  12. from unittest.mock import patch
  13. import pytest
  14. from taipy import Frequency, Scope
  15. from taipy.core.cycle.cycle import Cycle
  16. from taipy.core.cycle.cycle_id import CycleId
  17. from taipy.core.data.in_memory import InMemoryDataNode
  18. from taipy.core.notification.notifier import Notifier
  19. from taipy.core.scenario.scenario import Scenario
  20. from taipy.core.scenario.scenario_id import ScenarioId
  21. from taipy.core.sequence.sequence import Sequence
  22. from taipy.core.sequence.sequence_id import SequenceId
  23. from taipy.core.submission.submission import Submission
  24. current_time = datetime.now()
  25. @pytest.fixture(scope="function")
  26. def current_datetime():
  27. return current_time
  28. @pytest.fixture(scope="function")
  29. def data_node():
  30. return InMemoryDataNode(
  31. "data_node",
  32. Scope.SCENARIO,
  33. version="random_version_number",
  34. properties={"default_data": "foo"},
  35. )
  36. @pytest.fixture(scope="function")
  37. def scenario(cycle):
  38. return Scenario(
  39. "sc",
  40. set(),
  41. {},
  42. set(),
  43. ScenarioId("SCENARIO_sc_id"),
  44. current_time,
  45. is_primary=False,
  46. tags={"foo"},
  47. cycle=None,
  48. version="random_version_number",
  49. )
  50. @pytest.fixture(scope="function")
  51. def cycle():
  52. example_date = datetime.fromisoformat("2021-11-11T11:11:01.000001")
  53. return Cycle(
  54. Frequency.DAILY,
  55. {},
  56. creation_date=example_date,
  57. start_date=example_date,
  58. end_date=example_date,
  59. name="cc",
  60. id=CycleId("cc_id"),
  61. )
  62. @pytest.fixture(scope="function")
  63. def sequence(scenario):
  64. return Sequence({}, [], SequenceId(f"SEQUENCE_sequence_{scenario.id}"), version="random_version_number")
  65. @pytest.fixture(scope="function")
  66. def submission():
  67. return Submission("entity_id", "entity_type")
  68. @pytest.fixture(scope="function", autouse=True)
  69. def init(init_notifier):
  70. init_notifier()
  71. with patch("sys.argv", ["prog"]):
  72. yield
  73. init_notifier()
  74. @pytest.fixture
  75. def init_notifier():
  76. def _init_notifier():
  77. Notifier._topics_registrations_list = {}
  78. return _init_notifier