test_core_section.py 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  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. from unittest.mock import patch
  12. from src.taipy.core import Core
  13. from src.taipy.core._version._version_manager_factory import _VersionManagerFactory
  14. from taipy.config import Config
  15. from tests.core.utils.named_temporary_file import NamedTemporaryFile
  16. def test_core_section():
  17. with patch("sys.argv", ["prog"]):
  18. core = Core()
  19. core.run()
  20. assert Config.core.mode == "development"
  21. assert Config.core.version_number == _VersionManagerFactory._build_manager()._get_development_version()
  22. assert not Config.core.force
  23. core.stop()
  24. with patch("sys.argv", ["prog"]):
  25. Config.configure_core(mode="experiment", version_number="test_num", force=True)
  26. core = Core()
  27. core.run()
  28. assert Config.core.mode == "experiment"
  29. assert Config.core.version_number == "test_num"
  30. assert Config.core.force
  31. core.stop()
  32. toml_config = NamedTemporaryFile(
  33. content="""
  34. [TAIPY]
  35. [CORE]
  36. mode = "production"
  37. version_number = "test_num_2"
  38. force = "true:bool"
  39. """
  40. )
  41. Config.load(toml_config.filename)
  42. with patch("sys.argv", ["prog"]):
  43. core = Core()
  44. core.run()
  45. assert Config.core.mode == "production"
  46. assert Config.core.version_number == "test_num_2"
  47. assert Config.core.force
  48. core.stop()
  49. with patch("sys.argv", ["prog", "--experiment", "test_num_3", "--no-taipy-force"]):
  50. core = Core()
  51. core.run()
  52. assert Config.core.mode == "experiment"
  53. assert Config.core.version_number == "test_num_3"
  54. assert not Config.core.force
  55. core.stop()
  56. def test_clean_config():
  57. core_config = Config.configure_core(mode="experiment", version_number="test_num", force=True)
  58. assert Config.core is core_config
  59. core_config._clean()
  60. # Check if the instance before and after _clean() is the same
  61. assert Config.core is core_config
  62. assert core_config.mode == "development"
  63. assert core_config.version_number == ""
  64. assert core_config.force is False
  65. assert core_config.properties == {}