ScriptEvents_Default_SendReceiveSuccessfully.py 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. """
  2. Copyright (c) Contributors to the Open 3D Engine Project.
  3. For complete copyright and license terms please see the LICENSE at the root of this distribution.
  4. SPDX-License-Identifier: Apache-2.0 OR MIT
  5. """
  6. import os
  7. import pyside_utils
  8. from editor_python_test_tools.utils import Report, Tracer
  9. from editor_python_test_tools.utils import TestHelper as helper
  10. import editor_python_test_tools.hydra_editor_utils as hydra
  11. import azlmbr.paths as paths
  12. import azlmbr.legacy.general as general
  13. import scripting_utils.scripting_tools as scripting_tools
  14. from scripting_utils.scripting_constants import (WAIT_TIME_3, BASE_LEVEL_NAME)
  15. # fmt: off
  16. class Tests():
  17. entity_created = ("Successfully created test entity", "Failed to create test entity")
  18. enter_game_mode = ("Successfully entered game mode", "Failed to enter game mode")
  19. lines_found = ("Successfully found expected message", "Failed to find expected message")
  20. exit_game_mode = ("Successfully exited game mode", "Failed to exit game mode")
  21. # fmt: on
  22. EXPECTED_LINES = ["T92567320: Message Received"]
  23. SC_ASSET_PATH = os.path.join(paths.projectroot, "ScriptCanvas", "T92567320.scriptcanvas")
  24. class ScriptEvents_Default_SendReceiveSuccessfully:
  25. """
  26. Summary:
  27. An entity exists in the level that contains a Script Canvas component. In the graph is both a Send Event
  28. and a Receive Event.
  29. Expected Behavior:
  30. After entering game mode the graph on the entity should print an expected message to the console
  31. Test Steps:
  32. 1) Create test level
  33. 2) Create test entity
  34. 3) Enter Game Mode
  35. 4) Read for line
  36. 5) Exit Game Mode
  37. Note:
  38. - This test file must be called from the Open 3D Engine Editor command terminal
  39. - Any passed and failed tests are written to the Editor.log file.
  40. Parsing the file or running a log_monitor are required to observe the test results.
  41. :return: None
  42. """
  43. def __init__(self):
  44. editor_window = None
  45. @pyside_utils.wrap_async
  46. async def run_test(self):
  47. # Preconditions
  48. general.idle_enable(True)
  49. # 1) Create temp level
  50. hydra.open_base_level()
  51. helper.wait_for_condition(lambda: general.get_current_level_name() == BASE_LEVEL_NAME, WAIT_TIME_3)
  52. general.close_pane("Error Report")
  53. # 2) Create test entity
  54. entity = scripting_tools.create_entity_with_sc_component_asset("TestEntity", SC_ASSET_PATH)
  55. helper.wait_for_condition(lambda: entity is not None, WAIT_TIME_3)
  56. Report.critical_result(Tests.entity_created, entity.id.isValid())
  57. with Tracer() as section_tracer:
  58. # 3) Enter Game Mode
  59. helper.enter_game_mode(Tests.enter_game_mode)
  60. # 4) Read for line
  61. lines_located = helper.wait_for_condition(
  62. lambda: scripting_tools.located_expected_tracer_lines(self, section_tracer, EXPECTED_LINES), WAIT_TIME_3)
  63. Report.result(Tests.lines_found, lines_located)
  64. # 5) Exit Game Mode
  65. helper.exit_game_mode(Tests.exit_game_mode)
  66. test = ScriptEvents_Default_SendReceiveSuccessfully()
  67. test.run_test()