test_file_config.py 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  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.common.config import Config
  13. from taipy.common.config.exceptions.exceptions import LoadingError
  14. from tests.common.config.utils.named_temporary_file import NamedTemporaryFile
  15. def test_node_can_not_appear_twice():
  16. config = NamedTemporaryFile(
  17. """
  18. [unique_section_name]
  19. attribute = "my_attribute"
  20. [unique_section_name]
  21. attribute = "other_attribute"
  22. """
  23. )
  24. with pytest.raises(LoadingError, match="Can not load configuration"):
  25. Config.load(config.filename)
  26. def test_skip_configuration_outside_nodes():
  27. config = NamedTemporaryFile(
  28. """
  29. foo = "bar"
  30. """
  31. )
  32. Config.load(config.filename)
  33. assert Config.global_config.foo is None