AssetBuilder_test.py 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  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. #
  7. # This launches the AssetProcessor and Editor then attempts to find the expected
  8. # assets created by a Python Asset Builder and the output of a scene pipeline script
  9. #
  10. import sys
  11. import os
  12. import pytest
  13. import logging
  14. import re
  15. import sqlite3
  16. pytest.importorskip('ly_test_tools')
  17. import ly_test_tools.environment.file_system as file_system
  18. import ly_test_tools.log.log_monitor
  19. import ly_test_tools.environment.waiter as waiter
  20. from ly_test_tools.o3de.editor_test_utils import compile_test_case_name_from_request
  21. def detect_product(sql_connection, platform, target):
  22. cur = sql_connection.cursor()
  23. product_target = f'{platform}/{target}'
  24. print(f'Detecting {product_target} in assetdb.sqlite')
  25. hits = 0
  26. for row in cur.execute(f'select ProductID from Products where ProductName is "{product_target}"'):
  27. hits = hits + 1
  28. assert hits == 1
  29. def compile_test_case_name(request):
  30. """
  31. Compile a test case name for consumption by the TIAF python coverage listener gem.
  32. @param request: The fixture request.
  33. """
  34. try:
  35. test_case_prefix = "::".join(str.split(request.node.nodeid, "::")[:2])
  36. test_case_name = "::".join([test_case_prefix, request.node.originalname])
  37. callspec = request.node.callspec.id
  38. compiled_test_case_name = f"{test_case_name}[{callspec}]"
  39. except Exception as e:
  40. logging.warning(f"Error reading test case name for TIAF. {e}")
  41. compiled_test_case_name = "ERROR"
  42. return compiled_test_case_name
  43. def find_products(cache_folder, platform):
  44. con = sqlite3.connect(os.path.join(cache_folder, 'assetdb.sqlite'))
  45. detect_product(con, platform, 'gem/pythontests/pythonassetbuilder/test_asset.mock_asset')
  46. detect_product(con, platform, 'gem/pythontests/pythonassetbuilder/geom_group_fbx_cube_100cm_z_positive.fbx.azmodel')
  47. detect_product(con, platform, 'gem/pythontests/pythonassetbuilder/geom_group_fbx_cube_100cm_z_negative.fbx.azmodel')
  48. detect_product(con, platform, 'gem/pythontests/pythonassetbuilder/geom_group_fbx_cube_100cm_y_positive.fbx.azmodel')
  49. detect_product(con, platform, 'gem/pythontests/pythonassetbuilder/geom_group_fbx_cube_100cm_y_negative.fbx.azmodel')
  50. detect_product(con, platform, 'gem/pythontests/pythonassetbuilder/geom_group_fbx_cube_100cm_x_positive.fbx.azmodel')
  51. detect_product(con, platform, 'gem/pythontests/pythonassetbuilder/geom_group_fbx_cube_100cm_x_negative.fbx.azmodel')
  52. detect_product(con, platform, 'gem/pythontests/pythonassetbuilder/geom_group_fbx_cube_100cm_center.fbx.azmodel')
  53. con.close()
  54. @pytest.mark.SUITE_periodic
  55. @pytest.mark.parametrize('launcher_platform', ['windows_editor'])
  56. @pytest.mark.parametrize('project', ['AutomatedTesting'])
  57. @pytest.mark.parametrize('level', ['auto_test'])
  58. class TestPythonAssetProcessing(object):
  59. def test_DetectPythonCreatedAsset(self, request, editor, level, launcher_platform):
  60. unexpected_lines = []
  61. expected_lines = []
  62. timeout = 180
  63. halt_on_unexpected = False
  64. test_directory = os.path.join(os.path.dirname(__file__))
  65. testFile = os.path.join(test_directory, 'AssetBuilder_test_case.py')
  66. compiled_test_case_name = compile_test_case_name_from_request(request)
  67. editor.args.extend(['-NullRenderer', '-rhi=Null', "--skipWelcomeScreenDialog", "--autotest_mode", "--runpythontest", testFile, f"-pythontestcase={compiled_test_case_name}"])
  68. with editor.start():
  69. editorlog_file = os.path.join(editor.workspace.paths.project_log(), 'Editor.log')
  70. log_monitor = ly_test_tools.log.log_monitor.LogMonitor(editor, editorlog_file)
  71. waiter.wait_for(
  72. lambda: editor.is_alive(),
  73. timeout,
  74. exc=("Log file '{}' was never opened by another process.".format(editorlog_file)),
  75. interval=1)
  76. log_monitor.monitor_log_for_lines(expected_lines, unexpected_lines, halt_on_unexpected, timeout)
  77. cache_folder = editor.workspace.paths.cache()
  78. platform = editor.workspace.asset_processor_platform
  79. if platform == 'windows':
  80. platform = 'pc'
  81. find_products(cache_folder, platform)