ScriptCanvas_TwoEntities_UseSimultaneously.py 3.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  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. # fmt: off
  7. class Tests():
  8. level_created = ("New level created successfully", "New level failed to create")
  9. game_mode_entered = ("Game Mode successfully entered", "Game mode failed to enter")
  10. game_mode_exited = ("Game Mode successfully exited", "Game mode failed to exited")
  11. found_lines = ("Expected log lines were found", "Expected log lines were not found")
  12. # fmt: on
  13. def ScriptCanvas_TwoEntities_UseSimultaneously():
  14. """
  15. Summary:
  16. Two Entities can use the same Graph asset successfully at RunTime. The script canvas asset
  17. attached to the entities will print the respective entity names.
  18. Expected Behavior:
  19. When game mode is entered, respective strings of different entities should be printed.
  20. Test Steps:
  21. 1) Create temp level
  22. 2) Create two new entities with different names
  23. 3) Set ScriptCanvas asset to both the entities
  24. 4) Enter/Exit game mode and verify log lines
  25. Note:
  26. - This test file must be called from the Open 3D Engine Editor command terminal
  27. - Any passed and failed tests are written to the Editor.log file.
  28. Parsing the file or running a log_monitor are required to observe the test results.
  29. :return: None
  30. """
  31. import os
  32. from editor_python_test_tools.editor_entity_utils import EditorEntity
  33. from editor_python_test_tools.editor_component.editor_script_canvas import ScriptCanvasComponent
  34. from editor_python_test_tools.utils import TestHelper
  35. from editor_python_test_tools.utils import Tracer
  36. import azlmbr.legacy.general as general
  37. import azlmbr.math as math
  38. TEST_ENTITY_NAME_1 = "test_entity_1"
  39. TEST_ENTITY_NAME_2 = "test_entity_2"
  40. ASSET_PATH = os.path.join("scriptcanvas", "T92563191_test.scriptcanvas")
  41. EXPECTED_LINES = ["Entity Name: test_entity_1", "Entity Name: test_entity_2"]
  42. WAIT_TIME = 0.5 # SECONDS
  43. #Preconditions
  44. general.idle_enable(True)
  45. # 1) Create temp level
  46. TestHelper.open_level("", "Base")
  47. # 2) Create two new entities with different names
  48. position = math.Vector3(512.0, 512.0, 32.0)
  49. editor_entity_1 = EditorEntity.create_editor_entity_at(position, TEST_ENTITY_NAME_1)
  50. editor_entity_2 = EditorEntity.create_editor_entity_at(position, TEST_ENTITY_NAME_2)
  51. # 3) Set ScriptCanvas asset to both the entities
  52. scriptcanvas_component_1 = ScriptCanvasComponent(editor_entity_1)
  53. scriptcanvas_component_1.set_component_graph_file_from_path(ASSET_PATH)
  54. scriptcanvas_component_2 = ScriptCanvasComponent(editor_entity_2)
  55. scriptcanvas_component_2.set_component_graph_file_from_path(ASSET_PATH)
  56. # 4) Enter/Exit game mode and verify log lines
  57. with Tracer() as section_tracer:
  58. TestHelper.enter_game_mode(Tests.game_mode_entered)
  59. # wait for WAIT_TIME to let the script print strings
  60. general.idle_wait(WAIT_TIME)
  61. TestHelper.exit_game_mode(Tests.game_mode_exited)
  62. found_lines = [printInfo.message.strip() for printInfo in section_tracer.prints]
  63. result = all(line in found_lines for line in EXPECTED_LINES)
  64. Report.result(Tests.found_lines, result)
  65. if __name__ == "__main__":
  66. import ImportPathHelper as imports
  67. imports.init()
  68. from utils import Report
  69. Report.start_test(ScriptCanvas_TwoEntities_UseSimultaneously)