helpers.py 4.1 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. Helper file for assisting in building workspaces and setting up LTT with the current Lumberyard environment.
  6. """
  7. import ly_test_tools._internal.pytest_plugin as pytest_plugin
  8. import ly_test_tools._internal.managers.workspace as internal_workspace
  9. from ly_test_tools import LINUX, MAC, WINDOWS
  10. import os, stat
  11. def create_builtin_workspace(
  12. build_directory=None, # type: str
  13. project="AutomatedTesting", # type: str
  14. tmp_path=None, # type: str or None
  15. output_path=None, # type: str or None
  16. ):
  17. # type: (...) -> internal_workspace.AbstractWorkspaceManager
  18. """
  19. Create a new platform-specific workspace manager for the current lumberyard build
  20. :param build_directory: Custom path to the build directory (i.e. engine_root/dev/windows_vs2017/bin/profile)
  21. when set to None (default) it will use the value configured by pytest CLI argument --build-directory
  22. :param project: Project name to use
  23. :param tmp_path: Path to use as temporal storage, if not specified use default
  24. :param output_path: Path to use as log storage, if not specified use default
  25. :return: A workspace manager that works with the current lumberyard instance
  26. """
  27. if not build_directory:
  28. if pytest_plugin.build_directory:
  29. # cannot set argument default (which executes on import), must set here after pytest starts executing
  30. build_directory = pytest_plugin.build_directory
  31. else:
  32. raise ValueError(
  33. "Cmake build directory was not set via commandline arguments and not overridden. Please specify with "
  34. r"CLI argument --build-directory (example: --build-directory C:\lumberyard\dev\Win2019\bin\profile )")
  35. build_class = internal_workspace.AbstractWorkspaceManager
  36. if WINDOWS:
  37. from ly_test_tools._internal.managers.platforms.windows import WindowsWorkspaceManager
  38. build_class = WindowsWorkspaceManager
  39. elif MAC:
  40. from ly_test_tools._internal.managers.platforms.mac import MacWorkspaceManager
  41. build_class = MacWorkspaceManager
  42. elif LINUX:
  43. from ly_test_tools._internal.managers.platforms.linux import LinuxWorkspaceManager
  44. build_class = LinuxWorkspaceManager
  45. else:
  46. raise NotImplementedError("No workspace manager found for current Operating System")
  47. instance = build_class(
  48. build_directory=build_directory,
  49. project=project,
  50. tmp_path=tmp_path,
  51. output_path=output_path,
  52. )
  53. return instance
  54. def setup_builtin_workspace(workspace, test_name, artifact_folder_count):
  55. # type: (internal_workspace.AbstractWorkspaceManager, str, int) -> internal_workspace.AbstractWorkspaceManager
  56. """
  57. Reconfigures a workspace instance to its defaults.
  58. Usually test authors should rely on the provided "workspace" fixture, but these helpers can be used to
  59. achieve the same result.
  60. :param workspace: workspace to use
  61. :param test_name: the test name to be used by the artifact manager
  62. :param artifact_folder_count: the number of folders to create for the test_name, each one will have an index
  63. appended at the end to handle naming collisions.
  64. :return: the configured workspace object, useful for method chaining
  65. """
  66. workspace.setup()
  67. workspace.artifact_manager.set_dest_path(test_name=test_name, amount=artifact_folder_count)
  68. return workspace
  69. def teardown_builtin_workspace(workspace):
  70. # type: (internal_workspace.AbstractWorkspaceManager) -> internal_workspace.AbstractWorkspaceManager
  71. """
  72. Stop the asset processor and perform teardown on the specified workspace.
  73. Usually test authors should rely on the provided "workspace" fixture, but these helpers can be used to
  74. achieve the same result.
  75. :param workspace: workspace to use
  76. :return: the configured workspace object, useful for method chaining
  77. """
  78. workspace.teardown()
  79. return workspace