AssetBuilder_test.py 3.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  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. def detect_product(sql_connection, platform, target):
  21. cur = sql_connection.cursor()
  22. product_target = f'{platform}/{target}'
  23. print(f'Detecting {product_target} in assetdb.sqlite')
  24. hits = 0
  25. for row in cur.execute(f'select ProductID from Products where ProductName is "{product_target}"'):
  26. hits = hits + 1
  27. assert hits == 1
  28. def find_products(cache_folder, platform):
  29. con = sqlite3.connect(os.path.join(cache_folder, 'assetdb.sqlite'))
  30. detect_product(con, platform, 'gem/pythontests/pythonassetbuilder/test_asset.mock_asset')
  31. detect_product(con, platform, 'gem/pythontests/pythonassetbuilder/geom_group_fbx_cube_100cm_z_positive_1.azmodel')
  32. detect_product(con, platform, 'gem/pythontests/pythonassetbuilder/geom_group_fbx_cube_100cm_z_negative_1.azmodel')
  33. detect_product(con, platform, 'gem/pythontests/pythonassetbuilder/geom_group_fbx_cube_100cm_y_positive_1.azmodel')
  34. detect_product(con, platform, 'gem/pythontests/pythonassetbuilder/geom_group_fbx_cube_100cm_y_negative_1.azmodel')
  35. detect_product(con, platform, 'gem/pythontests/pythonassetbuilder/geom_group_fbx_cube_100cm_x_positive_1.azmodel')
  36. detect_product(con, platform, 'gem/pythontests/pythonassetbuilder/geom_group_fbx_cube_100cm_x_negative_1.azmodel')
  37. detect_product(con, platform, 'gem/pythontests/pythonassetbuilder/geom_group_fbx_cube_100cm_center_1.azmodel')
  38. con.close()
  39. @pytest.mark.SUITE_periodic
  40. @pytest.mark.parametrize('launcher_platform', ['windows_editor'])
  41. @pytest.mark.parametrize('project', ['AutomatedTesting'])
  42. @pytest.mark.parametrize('level', ['auto_test'])
  43. class TestPythonAssetProcessing(object):
  44. def test_DetectPythonCreatedAsset(self, request, editor, level, launcher_platform):
  45. unexpected_lines = []
  46. expected_lines = []
  47. timeout = 180
  48. halt_on_unexpected = False
  49. test_directory = os.path.join(os.path.dirname(__file__))
  50. testFile = os.path.join(test_directory, 'AssetBuilder_test_case.py')
  51. test_case_prefix = "::".join(str.split(request.node.nodeid, "::")[:2])
  52. compiled_test_case_name = "::".join([test_case_prefix, request.node.originalname])
  53. editor.args.extend(['-NullRenderer', '-rhi=Null', "--skipWelcomeScreenDialog", "--autotest_mode", "--runpythontest", testFile, f"-pythontestcase={compiled_test_case_name}"])
  54. with editor.start():
  55. editorlog_file = os.path.join(editor.workspace.paths.project_log(), 'Editor.log')
  56. log_monitor = ly_test_tools.log.log_monitor.LogMonitor(editor, editorlog_file)
  57. waiter.wait_for(
  58. lambda: editor.is_alive(),
  59. timeout,
  60. exc=("Log file '{}' was never opened by another process.".format(editorlog_file)),
  61. interval=1)
  62. log_monitor.monitor_log_for_lines(expected_lines, unexpected_lines, halt_on_unexpected, timeout)
  63. cache_folder = editor.workspace.paths.cache()
  64. platform = editor.workspace.asset_processor_platform
  65. if platform == 'windows':
  66. platform = 'pc'
  67. find_products(cache_folder, platform)