test_scenario_mgt_template.py 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  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 os
  12. from cookiecutter.main import cookiecutter
  13. from .utils import _run_template
  14. def test_scenario_management_with_toml_config(tmpdir):
  15. cookiecutter(
  16. template="taipy/templates/sdm",
  17. output_dir=tmpdir,
  18. no_input=True,
  19. extra_context={
  20. "Application root folder name": "foo_app",
  21. "Application main Python file": "main.py",
  22. "Application title": "bar",
  23. "Does the application use TOML Config?": "yes",
  24. },
  25. )
  26. assert os.listdir(tmpdir) == ["foo_app"]
  27. assert sorted(os.listdir(os.path.join(tmpdir, "foo_app"))) == sorted(
  28. ["requirements.txt", ".taipyignore", "main.py", "algos", "config", "pages"]
  29. )
  30. assert sorted(os.listdir(os.path.join(tmpdir, "foo_app", "config"))) == sorted(
  31. ["__init__.py", "config.py", "config.toml"]
  32. )
  33. with open(os.path.join(tmpdir, "foo_app", "config", "config.py")) as config_file:
  34. assert 'Config.load("config/config.toml")' in config_file.read()
  35. taipy_path = os.getcwd()
  36. stdout = _run_template(taipy_path, os.path.join(tmpdir, "foo_app"), "main.py")
  37. # Assert the message when the application is run successfully is in the stdout
  38. assert "[Taipy][INFO] Configuration 'config/config.toml' successfully loaded." in stdout
  39. assert "[Taipy][INFO] * Server starting on" in stdout
  40. def test_scenario_management_without_toml_config(tmpdir):
  41. cookiecutter(
  42. template="taipy/templates/sdm",
  43. output_dir=tmpdir,
  44. no_input=True,
  45. extra_context={
  46. "Application root folder name": "foo_app",
  47. "Application main Python file": "main.py",
  48. "Application title": "bar",
  49. "Does the application use TOML Config?": "no",
  50. },
  51. )
  52. assert os.listdir(tmpdir) == ["foo_app"]
  53. assert sorted(os.listdir(os.path.join(tmpdir, "foo_app"))) == sorted(
  54. ["requirements.txt", ".taipyignore", "main.py", "algos", "config", "pages"]
  55. )
  56. assert sorted(os.listdir(os.path.join(tmpdir, "foo_app", "config"))) == sorted(["__init__.py", "config.py"])
  57. with open(os.path.join(tmpdir, "foo_app", "config", "config.py")) as config_file:
  58. config_content = config_file.read()
  59. assert 'Config.load("config/config.toml")' not in config_content
  60. assert all(x in config_content for x in ["Config.configure_csv_data_node", "Config.configure_task"])
  61. taipy_path = os.getcwd()
  62. stdout = _run_template(taipy_path, os.path.join(tmpdir, "foo_app"), "main.py")
  63. # Assert the message when the application is run successfully is in the stdout
  64. assert "[Taipy][INFO] * Server starting on" in stdout
  65. def test_with_git(tmpdir):
  66. cookiecutter(
  67. template="taipy/templates/sdm",
  68. output_dir=str(tmpdir),
  69. no_input=True,
  70. extra_context={
  71. "Application root folder name": "foo_app",
  72. "Do you want to initialize a new Git repository?": "y",
  73. },
  74. )
  75. assert os.listdir(tmpdir) == ["foo_app"]
  76. assert sorted(os.listdir(os.path.join(tmpdir, "foo_app"))) == sorted(
  77. ["requirements.txt", "main.py", ".git", ".gitignore", ".taipyignore", "algos", "config", "pages"]
  78. )