ap_setup_fixture.py 3.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. """
  2. All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or
  3. its licensors.
  4. For complete copyright and license terms please see the LICENSE at the root of this
  5. distribution (the "License"). All use of this software is governed by the License,
  6. or, if provided, by the license below or the license accompanying this file. Do not
  7. remove or modify any license notices. This file is distributed on an "AS IS" BASIS,
  8. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  9. A fixture for Setting Up Asset Processor Batch workspace for tests in lmbr_test
  10. """
  11. # Import builtin libraries
  12. import os
  13. import time
  14. import pytest
  15. from typing import Dict
  16. from ly_test_tools.lumberyard.asset_processor import ASSET_PROCESSOR_PLATFORM_MAP
  17. @pytest.fixture
  18. def ap_setup_fixture(request, workspace) -> Dict:
  19. """
  20. Sets up useful file locations based on the current workspace.
  21. :return: useful locations as a dictionary
  22. """
  23. test_asset_dir_name = "ap_test_assets"
  24. resources = {
  25. # Path to directory where AssetProcessor[Batch].exe lives
  26. "bin_dir": workspace.paths.build_directory(),
  27. # Name of temporary folder for assets (scope = function)
  28. "test_asset_dir_name": test_asset_dir_name,
  29. # Temporary folder within project cache for use in test
  30. "cache_test_assets": os.path.join(workspace.paths.asset_cache(ASSET_PROCESSOR_PLATFORM_MAP[workspace.asset_processor_platform]), test_asset_dir_name),
  31. # Joblog folder location
  32. "test_joblogs_dir": os.path.join(workspace.paths.build_directory(), "logs", "JobLogs", test_asset_dir_name),
  33. # Temporary folder in project for use in test
  34. "project_test_assets_dir": os.path.join(workspace.paths.project(), test_asset_dir_name),
  35. # Test-level asset folder. Directory contains a subfolder for each test (i.e. C1234567)
  36. "tests_dir": "",
  37. # Path to AP_Batch.log
  38. "ap_batch_log_file": workspace.paths.ap_batch_log(),
  39. # Path to AP_GUI.log
  40. "ap_logFile": workspace.paths.ap_gui_log(),
  41. # Path to the engine root directory
  42. "engine_dir": workspace.paths.engine_root(),
  43. # Path to the current project directory
  44. "project_dir": workspace.paths.project(),
  45. # Path to AP Batch file
  46. "ap_batch_file": workspace.paths.asset_processor_batch(),
  47. # Path to shared TestAssets folder
  48. "shared_TestAssets": os.path.join(workspace.paths.project(), "TestAssets"),
  49. # Path to the asset cache folder
  50. "asset_cache_dir": os.path.join(workspace.paths.asset_cache(ASSET_PROCESSOR_PLATFORM_MAP[workspace.asset_processor_platform])),
  51. }
  52. # Changing modtime of UserSettings.xml so it is always processed by AssetProcessorBatch
  53. # to prevent unexpected processing
  54. user_settings_file = os.path.join(workspace.paths.project(), "user", "UserSettings.xml")
  55. if os.path.exists(user_settings_file):
  56. timestamp = time.time()
  57. os.utime(user_settings_file, (timestamp, timestamp))
  58. return resources