test_cli.py 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  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. from unittest.mock import patch
  12. from taipy.gui import Gui
  13. def test_cli_port(gui: Gui):
  14. with patch("sys.argv", ["prog"]):
  15. gui.run(run_server=False)
  16. assert gui._config.config.get("port") == 5000
  17. def test_cli_port_1(gui: Gui):
  18. with patch("sys.argv", ["prog", "--port", "8080"]):
  19. gui.run(run_server=False)
  20. assert gui._config.config.get("port") == 8080
  21. def test_cli_port_2(gui: Gui):
  22. with patch("sys.argv", ["prog", "-P", "9000"]):
  23. gui.run(run_server=False)
  24. assert gui._config.config.get("port") == 9000
  25. def test_cli_port_auto(gui: Gui):
  26. with patch("sys.argv", ["prog", "--port", "auto"]):
  27. gui.run(run_server=False)
  28. assert gui._config.config.get("port") == "auto"
  29. def test_cli_host(gui: Gui):
  30. with patch("sys.argv", ["prog"]):
  31. gui.run(run_server=False)
  32. assert gui._config.config.get("host") == "127.0.0.1"
  33. def test_cli_host_1(gui: Gui):
  34. with patch("sys.argv", ["prog", "--host", "localhost"]):
  35. gui.run(run_server=False)
  36. assert gui._config.config.get("host") == "localhost"
  37. def test_cli_host_2(gui: Gui):
  38. with patch("sys.argv", ["prog", "-H", "localhost"]):
  39. gui.run(run_server=False)
  40. assert gui._config.config.get("host") == "localhost"
  41. def test_taipy_debug(gui: Gui):
  42. with patch("sys.argv", ["prog", "--debug"]):
  43. gui.run(run_server=False, debug=False)
  44. assert gui._config.config.get("debug") is True
  45. def test_taipy_no_debug(gui: Gui):
  46. with patch("sys.argv", ["prog", "--no-debug"]):
  47. gui.run(run_server=False, debug=True)
  48. assert gui._config.config.get("debug") is False
  49. def test_taipy_reload(gui: Gui):
  50. with patch("sys.argv", ["prog", "--use-reloader"]):
  51. gui.run(run_server=False, use_reloader=False)
  52. assert gui._config.config.get("use_reloader") is True
  53. def test_taipy_no_reload(gui: Gui):
  54. with patch("sys.argv", ["prog", "--no-reloader"]):
  55. gui.run(run_server=False, use_reloader=True)
  56. assert gui._config.config.get("use_reloader") is False
  57. def test_ngrok_token(gui: Gui):
  58. with patch("sys.argv", ["prog", "--ngrok-token", "token"]):
  59. gui.run(run_server=False)
  60. assert gui._config.config.get("ngrok_token") == "token"
  61. def test_webapp_path(gui: Gui):
  62. with patch("sys.argv", ["prog", "--webapp-path", "path"]):
  63. gui.run(run_server=False)
  64. assert gui._config.config.get("webapp_path") == "path"
  65. def test_upload_folder(gui: Gui):
  66. with patch("sys.argv", ["prog", "--upload-folder", "folder"]):
  67. gui.run(run_server=False)
  68. assert gui._config.config.get("upload_folder") == "folder"
  69. def test_client_url(gui: Gui):
  70. with patch("sys.argv", ["prog"]):
  71. gui.run(run_server=False)
  72. assert gui._config.config.get("client_url") == "http://localhost:{port}"
  73. def test_client_url_1(gui: Gui):
  74. with patch("sys.argv", ["prog", "--client-url", "url"]):
  75. gui.run(run_server=False)
  76. assert gui._config.config.get("client_url") == "url"