1
0

test_template_cli.py 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. # Copyright 2021-2025 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 unittest.mock import patch
  13. import pytest
  14. from taipy._entrypoint import _entrypoint
  15. def test_create_cli_with_wrong_arguments(caplog):
  16. with patch("sys.argv", ["prog", "create", "--applciation", "default"]):
  17. with pytest.raises(SystemExit):
  18. _entrypoint()
  19. assert "Unknown arguments: --applciation. Did you mean: --application?" in caplog.text
  20. def test_create_cli_with_unsupported_template(capsys):
  21. with patch("sys.argv", ["prog", "create", "--application", "not-a-template"]):
  22. with pytest.raises(SystemExit):
  23. _entrypoint()
  24. _, err = capsys.readouterr()
  25. assert "invalid choice: 'not-a-template'" in err
  26. def test_create_app_on_existing_folder(tmpdir, capsys, monkeypatch):
  27. os.chdir(tmpdir)
  28. os.mkdir(os.path.join(tmpdir, "taipy_application"))
  29. # Mock the click.prompt to always return the default value
  30. monkeypatch.setattr("click.prompt", lambda *args, **kw: kw["default"] if "default" in kw else "")
  31. monkeypatch.setattr("builtins.input", lambda *args, **kw: "")
  32. with patch("sys.argv", ["prog", "create"]):
  33. with pytest.raises(SystemExit):
  34. _entrypoint()
  35. out, _ = capsys.readouterr()
  36. assert '"taipy_application" directory already exists' in out