ap_setup_fixture.py 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  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. A fixture for Setting Up Asset Processor Batch workspace for tests
  6. """
  7. # Import builtin libraries
  8. import os
  9. import time
  10. import pytest
  11. from typing import Dict
  12. from ly_test_tools.o3de.asset_processor import ASSET_PROCESSOR_PLATFORM_MAP
  13. @pytest.fixture
  14. def ap_setup_fixture(request, workspace) -> Dict:
  15. """
  16. Sets up useful file locations based on the current workspace.
  17. :return: useful locations as a dictionary
  18. """
  19. test_asset_dir_name = "ap_test_assets"
  20. resources = {
  21. # Path to directory where AssetProcessor[Batch].exe lives
  22. "bin_dir": workspace.paths.build_directory(),
  23. # Name of temporary folder for assets (scope = function)
  24. "test_asset_dir_name": test_asset_dir_name,
  25. # Temporary folder within project cache for use in test
  26. "cache_test_assets": os.path.join(workspace.paths.asset_cache(ASSET_PROCESSOR_PLATFORM_MAP[workspace.asset_processor_platform]), test_asset_dir_name),
  27. # Joblog folder location
  28. "test_joblogs_dir": os.path.join(workspace.paths.build_directory(), "logs", "JobLogs", test_asset_dir_name),
  29. # Temporary folder in project for use in test
  30. "project_test_assets_dir": os.path.join(workspace.paths.project(), test_asset_dir_name),
  31. # Test-level asset folder. Directory contains a subfolder for each test (i.e. C1234567)
  32. "tests_dir": "",
  33. # Path to AP_Batch.log
  34. "ap_batch_log_file": workspace.paths.ap_batch_log(),
  35. # Path to AP_GUI.log
  36. "ap_logFile": workspace.paths.ap_gui_log(),
  37. # Path to the engine root directory
  38. "engine_dir": workspace.paths.engine_root(),
  39. # Path to the current project directory
  40. "project_dir": workspace.paths.project(),
  41. # Path to AP Batch file
  42. "ap_batch_file": workspace.paths.asset_processor_batch(),
  43. # Path to shared TestAssets folder
  44. "shared_TestAssets": os.path.join(workspace.paths.project(), "TestAssets"),
  45. # Path to the asset cache folder
  46. "asset_cache_dir": os.path.join(workspace.paths.asset_cache(ASSET_PROCESSOR_PLATFORM_MAP[workspace.asset_processor_platform])),
  47. }
  48. # Changing modtime of UserSettings.xml so it is always processed by AssetProcessorBatch
  49. # to prevent unexpected processing
  50. user_settings_file = os.path.join(workspace.paths.project(), "user", "UserSettings.xml")
  51. if os.path.exists(user_settings_file):
  52. timestamp = time.time()
  53. os.utime(user_settings_file, (timestamp, timestamp))
  54. return resources