ScriptCanvas_ChangingAssets_ComponentStable.py 3.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  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. from editor_python_test_tools.utils import TestHelper as helper
  8. import azlmbr.editor as editor
  9. import azlmbr.bus as bus
  10. from editor_python_test_tools.utils import Report, Tracer
  11. import editor_python_test_tools.hydra_editor_utils as hydra
  12. import scripting_utils.scripting_tools as scripting_tools
  13. import azlmbr.legacy.general as general
  14. import azlmbr.paths as paths
  15. import pyside_utils
  16. from scripting_utils.scripting_constants import (BASE_LEVEL_NAME, WAIT_TIME_3)
  17. TEST_ENTITY_NAME = "test_entity"
  18. ASSET_1 = os.path.join(paths.projectroot, "scriptcanvas", "ScriptCanvas_TwoComponents0.scriptcanvas")
  19. ASSET_2 = os.path.join(paths.projectroot, "scriptcanvas", "ScriptCanvas_TwoComponents1.scriptcanvas")
  20. EXPECTED_LINES = ["Greetings from the first script", "Greetings from the second script"]
  21. # fmt: off
  22. class Tests:
  23. entity_created = ("Test Entity created", "Test Entity not created")
  24. game_mode_entered = ("Game Mode successfully entered", "Game mode failed to enter")
  25. game_mode_exited = ("Game Mode successfully exited", "Game mode failed to exited")
  26. script_file_update = ("Script Canvas File Updated", "Script Canvas File Not Updated")
  27. found_lines = ("Expected log lines were found", "Expected log lines were not found")
  28. # fmt: on
  29. class ScriptCanvas_ChangingAssets_ComponentStable:
  30. """
  31. Summary:
  32. Changing the assigned Script Canvas Asset on an entity properly updates level functionality
  33. Expected Behavior:
  34. When game mode is entered, respective strings of assigned assets should be printed
  35. Test Steps:
  36. 1) Create temp level
  37. 2) Create new entity
  38. 3) Start Tracer
  39. 4) Set first script and evaluate
  40. 5) Set second script and evaluate
  41. Note:
  42. - This test file must be called from the Open 3D Engine Editor command terminal
  43. - Any passed and failed tests are written to the Editor.log file.
  44. Parsing the file or running a log_monitor are required to observe the test results.
  45. :return: None
  46. """
  47. def __init__(self):
  48. editor_window = None
  49. @pyside_utils.wrap_async
  50. async def run_test(self):
  51. # Preconditions
  52. general.idle_enable(True)
  53. # 1) Create temp level
  54. hydra.open_base_level()
  55. helper.wait_for_condition(lambda: general.get_current_level_name() == BASE_LEVEL_NAME, WAIT_TIME_3)
  56. general.close_pane("Error Report")
  57. # 2) Create new entity
  58. entity = scripting_tools.create_entity_with_sc_component_asset(TEST_ENTITY_NAME, ASSET_1)
  59. result = helper.wait_for_condition(lambda: entity is not None, WAIT_TIME_3)
  60. Report.result(Tests.entity_created, result)
  61. with Tracer() as section_tracer:
  62. # 3) Enter and Exit Game Mode
  63. helper.enter_game_mode(Tests.game_mode_entered)
  64. helper.exit_game_mode(Tests.game_mode_exited)
  65. # 4) Update Script Canvas file on entity's SC component
  66. result = scripting_tools.change_entity_sc_asset(entity, ASSET_2)
  67. Report.result(Tests.script_file_update, result)
  68. # 5) Enter and Exit Game Mode
  69. helper.enter_game_mode(Tests.game_mode_entered)
  70. helper.exit_game_mode(Tests.game_mode_exited)
  71. # 6 Verify script canvas graph output
  72. result = scripting_tools.located_expected_tracer_lines(self, section_tracer, EXPECTED_LINES)
  73. Report.result(Tests.found_lines, result)
  74. test = ScriptCanvas_ChangingAssets_ComponentStable()
  75. test.run_test()