conftest.py 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. # Copyright 2023 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._config import _Config
  13. from taipy.config._config_comparator._config_comparator import _ConfigComparator
  14. from taipy.config._serializer._toml_serializer import _TomlSerializer
  15. from taipy.config.checker._checker import _Checker
  16. from taipy.config.checker.issue_collector import IssueCollector
  17. from taipy.config.config import Config
  18. from taipy.config.section import Section
  19. from tests.config.utils.section_for_tests import SectionForTest
  20. from tests.config.utils.unique_section_for_tests import UniqueSectionForTest
  21. @pytest.fixture(scope="function", autouse=True)
  22. def reset():
  23. reset_configuration_singleton()
  24. register_test_sections()
  25. def reset_configuration_singleton():
  26. Config.unblock_update()
  27. Config._default_config = _Config()._default_config()
  28. Config._python_config = _Config()
  29. Config._file_config = _Config()
  30. Config._env_file_config = _Config()
  31. Config._applied_config = _Config()
  32. Config._collector = IssueCollector()
  33. Config._serializer = _TomlSerializer()
  34. Config._comparator = _ConfigComparator()
  35. _Checker._checkers = []
  36. def register_test_sections():
  37. Config._register_default(UniqueSectionForTest("default_attribute"))
  38. Config.configure_unique_section_for_tests = UniqueSectionForTest._configure
  39. Config.unique_section_name = Config.unique_sections[UniqueSectionForTest.name]
  40. Config._register_default(SectionForTest(Section._DEFAULT_KEY, "default_attribute", prop="default_prop", prop_int=0))
  41. Config.configure_section_for_tests = SectionForTest._configure
  42. Config.section_name = Config.sections[SectionForTest.name]