conftest.py 2.7 KB

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