test_run.py 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  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 import mock
  12. from taipy._run import _run
  13. from taipy.core import Core
  14. from taipy.gui import Gui
  15. from taipy.rest import Rest
  16. @mock.patch("taipy.gui.Gui.run")
  17. def test_run_pass_with_gui(gui_run):
  18. _run(Gui())
  19. gui_run.assert_called_once()
  20. @mock.patch("taipy.core.Core.run")
  21. def test_run_pass_with_core(core_run):
  22. _run(Core())
  23. core_run.assert_called_once()
  24. @mock.patch("taipy.rest.Rest.run")
  25. @mock.patch("taipy.core.Core.run")
  26. def test_run_pass_with_rest(rest_run, core_run):
  27. _run(Rest())
  28. rest_run.assert_called_once()
  29. core_run.assert_called_once()
  30. @mock.patch("taipy.rest.Rest.run")
  31. @mock.patch("taipy.core.Core.run")
  32. def test_run_pass_with_core_and_rest(core_run, rest_run):
  33. _run(Core(), Rest())
  34. core_run.assert_called_once()
  35. rest_run.assert_called_once()
  36. @mock.patch("taipy.gui.Gui.run")
  37. @mock.patch("taipy.rest.Rest.run")
  38. @mock.patch("taipy.core.Core.run")
  39. def test_run_pass_with_gui_and_rest(core_run, rest_run, gui_run):
  40. _run(Gui(), Rest())
  41. gui_run.assert_called_once()
  42. core_run.assert_called_once()
  43. rest_run.assert_not_called()
  44. @mock.patch("taipy.gui.Gui.run")
  45. @mock.patch("taipy.core.Core.run")
  46. def test_run_pass_with_gui_and_core(core_run, gui_run):
  47. _run(Gui(), Core())
  48. gui_run.assert_called_once()
  49. core_run.assert_called_once()