ScriptCanvas_ChangingAssets_ComponentStable.py 3.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  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. class Tests:
  7. game_mode_entered = ("Game Mode successfully entered", "Game mode failed to enter")
  8. game_mode_exited = ("Game Mode successfully exited", "Game mode failed to exited")
  9. found_lines = ("Expected log lines were found", "Expected log lines were not found")
  10. def ScriptCanvas_ChangingAssets_ComponentStable():
  11. """
  12. Summary:
  13. Changing the assigned Script Canvas Asset on an entity properly updates level functionality
  14. Expected Behavior:
  15. When game mode is entered, respective strings of assigned assets should be printed
  16. Test Steps:
  17. 1) Create temp level
  18. 2) Create new entity
  19. 3) Enter and Exit Game Mode
  20. 4) Update Script Canvas file on entity's SC component
  21. 5) Enter and Exit Game Mode
  22. 6) Verify script canvas graph output
  23. Note:
  24. - This test file must be called from the Open 3D Engine Editor command terminal
  25. - Any passed and failed tests are written to the Editor.log file.
  26. Parsing the file or running a log_monitor are required to observe the test results.
  27. :return: None
  28. """
  29. from editor_python_test_tools.utils import TestHelper, Report, Tracer
  30. from editor_python_test_tools.editor_entity_utils import EditorEntity
  31. import scripting_utils.scripting_tools as scripting_tools
  32. import azlmbr.legacy.general as general
  33. from editor_python_test_tools.editor_component.editor_script_canvas import ScriptCanvasComponent
  34. import azlmbr.math as math
  35. import os
  36. import azlmbr.paths as paths
  37. TEST_ENTITY_NAME = "test_entity"
  38. ASSET_1 = os.path.join(paths.projectroot, "scriptcanvas", "ScriptCanvas_TwoComponents0.scriptcanvas")
  39. ASSET_2 = os.path.join(paths.projectroot, "scriptcanvas", "ScriptCanvas_TwoComponents1.scriptcanvas")
  40. EXPECTED_LINES = ["Greetings from the first script", "Greetings from the second script"]
  41. # Preconditions
  42. general.idle_enable(True)
  43. # 1) Create temp level
  44. TestHelper.open_level("", "Base")
  45. # 2) Create new entity
  46. position = math.Vector3(512.0, 512.0, 32.0)
  47. editor_entity = EditorEntity.create_editor_entity_at(position, TEST_ENTITY_NAME)
  48. script_canvas_component = ScriptCanvasComponent(editor_entity)
  49. script_canvas_component.set_component_graph_file_from_path(ASSET_1)
  50. with Tracer() as section_tracer:
  51. # 3) Enter and Exit Game Mode
  52. TestHelper.enter_game_mode(Tests.game_mode_entered)
  53. TestHelper.exit_game_mode(Tests.game_mode_exited)
  54. # 4) Update Script Canvas file on entity's SC component
  55. script_canvas_component.set_component_graph_file_from_path(ASSET_2)
  56. # 5) Enter and Exit Game Mode
  57. TestHelper.enter_game_mode(Tests.game_mode_entered)
  58. TestHelper.exit_game_mode(Tests.game_mode_exited)
  59. # 6) Verify script canvas graph output
  60. result = scripting_tools.located_expected_tracer_lines(section_tracer, EXPECTED_LINES)
  61. Report.result(Tests.found_lines, result)
  62. if __name__ == "__main__":
  63. import ImportPathHelper as imports
  64. imports.init()
  65. from editor_python_test_tools.utils import Report
  66. Report.start_test(ScriptCanvas_ChangingAssets_ComponentStable)