conftest.py 2.1 KB

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