test_default_config.py 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  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 taipy.config.config import Config
  12. from taipy.config.global_app.global_app_config import GlobalAppConfig
  13. from taipy.config.section import Section
  14. from tests.config.utils.section_for_tests import SectionForTest
  15. from tests.config.utils.unique_section_for_tests import UniqueSectionForTest
  16. def _test_default_global_app_config(global_config: GlobalAppConfig):
  17. assert global_config is not None
  18. assert not global_config.notification
  19. assert len(global_config.properties) == 0
  20. def test_default_configuration():
  21. default_config = Config._default_config
  22. assert default_config._unique_sections is not None
  23. assert len(default_config._unique_sections) == 1
  24. assert default_config._unique_sections[UniqueSectionForTest.name] is not None
  25. assert default_config._unique_sections[UniqueSectionForTest.name].attribute == "default_attribute"
  26. assert default_config._sections is not None
  27. assert len(default_config._sections) == 1
  28. _test_default_global_app_config(default_config._global_config)
  29. _test_default_global_app_config(Config.global_config)
  30. _test_default_global_app_config(GlobalAppConfig().default_config())
  31. def test_register_default_configuration():
  32. Config._register_default(SectionForTest(Section._DEFAULT_KEY, "default_attribute", prop1="prop1"))
  33. # Replace the first default section
  34. Config._register_default(SectionForTest(Section._DEFAULT_KEY, "default_attribute", prop2="prop2"))
  35. default_section = Config.sections[SectionForTest.name][Section._DEFAULT_KEY]
  36. assert len(default_section.properties) == 1
  37. assert default_section.prop2 == "prop2"
  38. assert default_section.prop1 is None