conftest.py 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  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. import pytest
  12. from taipy.config import _inject_section
  13. from taipy.config._config import _Config
  14. from taipy.config._config_comparator._config_comparator import _ConfigComparator
  15. from taipy.config._serializer._toml_serializer import _TomlSerializer
  16. from taipy.config.checker._checker import _Checker
  17. from taipy.config.checker.issue_collector import IssueCollector
  18. from taipy.config.config import Config
  19. from taipy.core.config import CoreSection, DataNodeConfig, JobConfig, MigrationConfig, ScenarioConfig, TaskConfig
  20. def pytest_addoption(parser):
  21. parser.addoption("--e2e-base-url", action="store", default="/", help="base url for e2e testing")
  22. parser.addoption("--e2e-port", action="store", default="5000", help="port for e2e testing")
  23. @pytest.fixture(scope="session")
  24. def e2e_base_url(request):
  25. return request.config.getoption("--e2e-base-url")
  26. @pytest.fixture(scope="session")
  27. def e2e_port(request):
  28. return request.config.getoption("--e2e-port")
  29. @pytest.fixture
  30. def reset_configuration_singleton():
  31. def _reset_configuration_singleton():
  32. Config.unblock_update()
  33. Config._default_config = _Config()._default_config()
  34. Config._python_config = _Config()
  35. Config._file_config = _Config()
  36. Config._env_file_config = _Config()
  37. Config._applied_config = _Config()
  38. Config._collector = IssueCollector()
  39. Config._serializer = _TomlSerializer()
  40. Config._comparator = _ConfigComparator()
  41. _Checker._checkers = []
  42. return _reset_configuration_singleton
  43. @pytest.fixture
  44. def inject_core_sections():
  45. def _inject_core_sections():
  46. _inject_section(
  47. JobConfig,
  48. "job_config",
  49. JobConfig("development"),
  50. [("configure_job_executions", JobConfig._configure)],
  51. True,
  52. )
  53. _inject_section(
  54. CoreSection,
  55. "core",
  56. CoreSection.default_config(),
  57. [("configure_core", CoreSection._configure)],
  58. add_to_unconflicted_sections=True,
  59. )
  60. _inject_section(
  61. DataNodeConfig,
  62. "data_nodes",
  63. DataNodeConfig.default_config(),
  64. [
  65. ("configure_data_node", DataNodeConfig._configure),
  66. ("configure_data_node_from", DataNodeConfig._configure_from),
  67. ("set_default_data_node_configuration", DataNodeConfig._set_default_configuration),
  68. ("configure_csv_data_node", DataNodeConfig._configure_csv),
  69. ("configure_json_data_node", DataNodeConfig._configure_json),
  70. ("configure_sql_table_data_node", DataNodeConfig._configure_sql_table),
  71. ("configure_sql_data_node", DataNodeConfig._configure_sql),
  72. ("configure_mongo_collection_data_node", DataNodeConfig._configure_mongo_collection),
  73. ("configure_in_memory_data_node", DataNodeConfig._configure_in_memory),
  74. ("configure_pickle_data_node", DataNodeConfig._configure_pickle),
  75. ("configure_excel_data_node", DataNodeConfig._configure_excel),
  76. ("configure_generic_data_node", DataNodeConfig._configure_generic),
  77. ("configure_s3_object_data_node", DataNodeConfig._configure_s3_object),
  78. ],
  79. )
  80. _inject_section(
  81. TaskConfig,
  82. "tasks",
  83. TaskConfig.default_config(),
  84. [
  85. ("configure_task", TaskConfig._configure),
  86. ("set_default_task_configuration", TaskConfig._set_default_configuration),
  87. ],
  88. )
  89. _inject_section(
  90. ScenarioConfig,
  91. "scenarios",
  92. ScenarioConfig.default_config(),
  93. [
  94. ("configure_scenario", ScenarioConfig._configure),
  95. ("set_default_scenario_configuration", ScenarioConfig._set_default_configuration),
  96. ],
  97. )
  98. _inject_section(
  99. MigrationConfig,
  100. "migration_functions",
  101. MigrationConfig.default_config(),
  102. [("add_migration_function", MigrationConfig._add_migration_function)],
  103. True,
  104. )
  105. return _inject_core_sections