test_scenario_mgt_template.py 3.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  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/scenario-management",
  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 (
  28. os.listdir(os.path.join(tmpdir, "foo_app")).sort()
  29. == ["requirements.txt", "main.py", "algos", "config", "pages"].sort()
  30. )
  31. assert (
  32. os.listdir(os.path.join(tmpdir, "foo_app", "config")).sort()
  33. == ["__init__.py", "config.py", "config.toml"].sort()
  34. )
  35. with open(os.path.join(tmpdir, "foo_app", "config", "config.py")) as config_file:
  36. assert 'Config.load("config/config.toml")' in config_file.read()
  37. taipy_path = os.getcwd()
  38. stdout = _run_template(taipy_path, os.path.join(tmpdir, "foo_app"), "main.py")
  39. # Assert the message when the application is run successfully is in the stdout
  40. assert "[Taipy][INFO] Configuration 'config/config.toml' successfully loaded." in stdout
  41. assert "[Taipy][INFO] * Server starting on" in stdout
  42. def test_scenario_management_without_toml_config(tmpdir):
  43. cookiecutter(
  44. template="taipy/templates/scenario-management",
  45. output_dir=tmpdir,
  46. no_input=True,
  47. extra_context={
  48. "Application root folder name": "foo_app",
  49. "Application main Python file": "main.py",
  50. "Application title": "bar",
  51. "Does the application use TOML Config?": "no",
  52. },
  53. )
  54. assert os.listdir(tmpdir) == ["foo_app"]
  55. assert (
  56. os.listdir(os.path.join(tmpdir, "foo_app")).sort()
  57. == ["requirements.txt", "main.py", "algos", "config", "pages"].sort()
  58. )
  59. assert os.listdir(os.path.join(tmpdir, "foo_app", "config")).sort() == ["__init__.py", "config.py"].sort()
  60. with open(os.path.join(tmpdir, "foo_app", "config", "config.py")) as config_file:
  61. config_content = config_file.read()
  62. assert 'Config.load("config/config.toml")' not in config_content
  63. assert all(x in config_content for x in ["Config.configure_csv_data_node", "Config.configure_task"])
  64. taipy_path = os.getcwd()
  65. stdout = _run_template(taipy_path, os.path.join(tmpdir, "foo_app"), "main.py")
  66. # Assert the message when the application is run successfully is in the stdout
  67. assert "[Taipy][INFO] * Server starting on" in stdout