VariableManager_ExposeVarsToComponent.py 4.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  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. # stub for when save file code is available
  7. ENTITY_NAME = "SC_Component_Variable_Entity"
  8. COMPONENT_LIST = ["Script Canvas"]
  9. VARIABLE_NAME = "Test Boolean"
  10. def VariableManager_ExposeVarsToComponent():
  11. """
  12. Summary:
  13. Test for verifying variables exposed to component can be accessed and modified in Editor
  14. Expected Behavior:
  15. Each variable type can be created and deleted in variable manager.
  16. Test Steps:
  17. 1) Open Script Canvas window (Tools > Script Canvas)
  18. 2) Get the SC window, variable manager and node inspector objects
  19. 3) Create Graph
  20. 4) Create variable of each type and change their initial value source to from component
  21. 5) Select the new variable in the variable manager so node inspector gets a target
  22. 6) change the selected variable's intial value source to from Component (on)
  23. 7) Save the file to disk
  24. 8) Create an entity w/ component in the O3DE editor and attach the file
  25. 9) Set the variable on the script canvas component to True then validate the result
  26. Note:
  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. # Preconditions
  32. from editor_python_test_tools.QtPy.QtPyO3DEEditor import QtPyO3DEEditor
  33. from editor_python_test_tools.editor_component.editor_script_canvas import ScriptCanvasComponent, VariableState
  34. import editor_python_test_tools.editor_component.editor_component_validation as Validators
  35. from editor_python_test_tools.QtPy.QtPyCommon import CheckBoxStates
  36. import azlmbr.legacy.general as general
  37. from consts.scripting import (SCRIPT_CANVAS_TEST_FILE_PATH)
  38. from editor_python_test_tools.editor_entity_utils import EditorEntity
  39. from editor_python_test_tools.utils import TestHelper
  40. import azlmbr.math as math
  41. general.idle_enable(True)
  42. # 1) Open the base level and then open Script Canvas editor
  43. TestHelper.open_level("", "Base")
  44. qtpy_o3de_editor = QtPyO3DEEditor()
  45. sc_editor = qtpy_o3de_editor.open_script_canvas()
  46. # 2) Get the SC window, variable manager and node inspector objects
  47. sc_editor.create_new_script_canvas_graph()
  48. variable_manager = sc_editor.variable_manager
  49. node_inspector = sc_editor.node_inspector
  50. # 3) Create Graph
  51. sc_editor.create_new_script_canvas_graph()
  52. # 4) Create variable of each type and change their initial value source to from component
  53. # The names of the variables will default to their type
  54. boolean_type = variable_manager.get_basic_variable_types().Boolean
  55. selection_index = variable_manager.create_new_variable(VARIABLE_NAME, boolean_type)
  56. # 5) Select the new variable in the variable manager so node inspector gets a target
  57. variable_manager.select_variable_from_table(selection_index)
  58. # 6) change the selected variable's intial value source to from Component (on)
  59. node_inspector.change_variable_initial_value_source(CheckBoxStates.On)
  60. # 7) Save the file to disk
  61. # This step requires engineering support. See github GH-12668
  62. # 8) Create an entity w/ component in the O3DE editor and attach the file
  63. position = math.Vector3(512.0, 512.0, 32.0)
  64. editor_entity = EditorEntity.create_editor_entity_at(position, ENTITY_NAME)
  65. script_canvas_component = ScriptCanvasComponent(editor_entity)
  66. script_canvas_component.set_component_graph_file_from_path(SCRIPT_CANVAS_TEST_FILE_PATH)
  67. # 9) Set the variable on the script canvas component to True then validate the result
  68. new_variable_value = True
  69. Validators.validate_script_canvas_variable_changed(script_canvas_component.get_variable_value,
  70. script_canvas_component.set_variable_value,
  71. VARIABLE_NAME, VariableState.UNUSEDVARIABLE, new_variable_value)
  72. if __name__ == "__main__":
  73. import ImportPathHelper as imports
  74. imports.init()
  75. from utils import Report
  76. Report.start_test(VariableManager_ExposeVarsToComponent)