CreatePrefab_CreationFailsWithDifferentRootEntities.py 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  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. def CreatePrefab_CreationFailsWithDifferentRootEntities():
  7. """
  8. Test description:
  9. - Creates a single entity and a nested entity hierarchy at the root level
  10. - Selects the single entity and one of the nested entities
  11. - Attempts to create a prefab from the selected entities
  12. Test is successful if prefab creation fails and error messaging matches expected
  13. """
  14. from pathlib import Path
  15. import azlmbr.math as math
  16. from editor_python_test_tools.editor_entity_utils import EditorEntity
  17. from editor_python_test_tools.prefab_utils import Prefab
  18. import Prefab.tests.PrefabTestUtils as prefab_test_utils
  19. TEST_PREFAB_FILE_NAME = Path(__file__).stem + '_prefab'
  20. SINGLE_ENTITY_NAME = "SingleEntity"
  21. NESTED_ENTITY_PREFIX = "NestedEntity_"
  22. NESTED_ENTITY_POS = math.Vector3(0.0, 0.0, 0.0)
  23. EXPECTED_ERR_STR = "Prefab operation 'CreatePrefab' failed. Error: Failed to create a prefab: Provided entities do " \
  24. "not share a common root."
  25. prefab_test_utils.open_base_tests_level()
  26. # Creates a new Entity at the root level
  27. test_entity = EditorEntity.create_editor_entity(SINGLE_ENTITY_NAME)
  28. assert test_entity.exists(), f"Failed to create entity with name {SINGLE_ENTITY_NAME}"
  29. # Creates a new Entity hierarchy at the root level
  30. nested_entity_root = prefab_test_utils.create_linear_nested_entities(NESTED_ENTITY_PREFIX, 3, NESTED_ENTITY_POS)
  31. prefab_test_utils.validate_linear_nested_entities(nested_entity_root, 3, NESTED_ENTITY_POS)
  32. child_test_entity = EditorEntity.find_editor_entity("NestedEntity_2")
  33. # Create a prefab from the single entity and a child entity of the nested entity hierarchy
  34. test_prefab_instance = None
  35. try:
  36. _, test_prefab_instance = Prefab.create_prefab([test_entity, child_test_entity], TEST_PREFAB_FILE_NAME)
  37. except AssertionError as error:
  38. prefab_creation_error = str(error)
  39. Report.info(prefab_creation_error)
  40. # Validate that the error message from create_prefab matches expected message
  41. assert not test_prefab_instance, "Prefab creation unexpectedly succeeded"
  42. assert prefab_creation_error == EXPECTED_ERR_STR, f"Expected Error: {EXPECTED_ERR_STR}, Found Error: " \
  43. f"{prefab_creation_error}"
  44. if __name__ == "__main__":
  45. from editor_python_test_tools.utils import Report
  46. Report.start_test(CreatePrefab_CreationFailsWithDifferentRootEntities)