Integrating github/staging through commit ab87ed9

This commit is contained in:
alexpete
2021-04-09 11:27:37 -07:00
parent ae62a97894
commit 1044dc3da1
1582 changed files with 29374 additions and 519051 deletions
@@ -32,14 +32,11 @@ class TestFindEngineRoot(object):
@mock.patch('ly_test_tools._internal.managers.abstract_resource_locator.os.path.exists')
def test_FindEngineRoot_InitialPathExists_ReturnsTuple(self, mock_path_exists, mock_abspath):
mock_path_exists.return_value = True
mock_abspath.return_value = mock_engine_root
engine_root, dev_path = abstract_resource_locator._find_engine_root(mock_initial_path)
engine_root = abstract_resource_locator._find_engine_root(mock_engine_root)
assert engine_root == mock_engine_root
assert dev_path == mock_initial_path
mock_path_exists.assert_called_once()
mock_abspath.assert_called_once()
@mock.patch('ly_test_tools._internal.managers.abstract_resource_locator.os.path.abspath')
@mock.patch('ly_test_tools._internal.managers.abstract_resource_locator.os.path.exists')
@@ -54,7 +51,7 @@ class TestFindEngineRoot(object):
@mock.patch('ly_test_tools._internal.managers.abstract_resource_locator.os.path.abspath',
mock.MagicMock(return_value=mock_initial_path))
@mock.patch('ly_test_tools._internal.managers.abstract_resource_locator._find_engine_root',
mock.MagicMock(return_value=(mock_engine_root, mock_dev_path)))
mock.MagicMock(return_value=mock_engine_root))
class TestAbstractResourceLocator(object):
def test_Init_HasEngineRoot_SetsAttrs(self):
@@ -63,7 +60,6 @@ class TestAbstractResourceLocator(object):
assert mock_abstract_resource_locator._build_directory == mock_build_directory
assert mock_abstract_resource_locator._engine_root == mock_engine_root
assert mock_abstract_resource_locator._dev_path == mock_dev_path
assert mock_abstract_resource_locator._project == mock_project
def test_BasePath_IsCalled_ReturnsBasePath(self):
@@ -72,12 +68,6 @@ class TestAbstractResourceLocator(object):
assert mock_abstract_resource_locator.engine_root() == mock_engine_root
def test_Dev_IsCalled_ReturnsDevPath(self):
mock_abstract_resource_locator = abstract_resource_locator.AbstractResourceLocator(
mock_build_directory, mock_project)
assert mock_abstract_resource_locator.dev() == mock_dev_path
@mock.patch('ly_test_tools._internal.managers.abstract_resource_locator.os.path.isfile')
def test_3rdParty_IsCalledHasTxtFile_Returns3rdPartyPath(self, mock_isfile):
mock_isfile.return_value = True
@@ -106,7 +96,7 @@ class TestAbstractResourceLocator(object):
def test_Project_IsCalled_ReturnsProjectPath(self):
mock_abstract_resource_locator = abstract_resource_locator.AbstractResourceLocator(
mock_build_directory, mock_project)
expected_path = os.path.join(mock_abstract_resource_locator.dev(), mock_project)
expected_path = os.path.join(mock_abstract_resource_locator.engine_root(), mock_project)
assert mock_abstract_resource_locator.project() == expected_path
@@ -171,21 +161,21 @@ class TestAbstractResourceLocator(object):
def test_BootstrapConfigFile_IsCalled_ReturnBootstrapConfigFilePath(self):
mock_abstract_resource_locator = abstract_resource_locator.AbstractResourceLocator(
mock_build_directory, mock_project)
expected_path = os.path.join(mock_abstract_resource_locator.dev(), 'bootstrap.cfg')
expected_path = os.path.join(mock_abstract_resource_locator.engine_root(), 'bootstrap.cfg')
assert mock_abstract_resource_locator.bootstrap_config_file() == expected_path
def test_AssetProcessorConfigFile_IsCalled_ReturnsAssetProcessorConfigFilePath(self):
mock_abstract_resource_locator = abstract_resource_locator.AbstractResourceLocator(
mock_build_directory, mock_project)
expected_path = os.path.join(mock_abstract_resource_locator.dev(), 'AssetProcessorPlatformConfig.setreg')
expected_path = os.path.join(mock_abstract_resource_locator.engine_root(), 'AssetProcessorPlatformConfig.setreg')
assert mock_abstract_resource_locator.asset_processor_config_file() == expected_path
def test_AutoexecFile_IsCalled_ReturnsAutoexecFilePath(self):
mock_abstract_resource_locator = abstract_resource_locator.AbstractResourceLocator(
mock_build_directory, mock_project)
expected_path = os.path.join(mock_abstract_resource_locator.dev(),
expected_path = os.path.join(mock_abstract_resource_locator.engine_root(),
mock_abstract_resource_locator._project,
'autoexec.cfg')
@@ -194,7 +184,7 @@ class TestAbstractResourceLocator(object):
def test_TestResults_IsCalled_TestResultsPath(self):
mock_abstract_resource_locator = abstract_resource_locator.AbstractResourceLocator(
mock_build_directory, mock_project)
expected_path = os.path.join(mock_abstract_resource_locator.dev(), 'TestResults')
expected_path = os.path.join(mock_abstract_resource_locator.engine_root(), 'TestResults')
assert mock_abstract_resource_locator.test_results() == expected_path
@@ -27,6 +27,7 @@ mock_engine_root = "mock_engine_root"
mock_dev_path = "mock_dev_path"
mock_build_directory = 'mock_build_directory'
mock_project = 'mock_project'
mock_project_path = os.path.join('some', 'dir', mock_project)
@mock.patch('ly_test_tools._internal.managers.abstract_resource_locator.os.path.abspath',
@@ -52,7 +53,8 @@ class TestAssetProcessor(object):
mock_ap_path = 'mock_ap_path'
mock_workspace.asset_processor_platform = 'foo'
mock_workspace.paths.asset_processor.return_value = mock_ap_path
mock_workspace.project = 'AutomatedTesting'
mock_workspace.project = mock_project
mock_workspace.paths.project.return_value = mock_project_path
under_test = ly_test_tools.lumberyard.asset_processor.AssetProcessor(mock_workspace)
under_test.enable_asset_processor_platform = mock.MagicMock()
under_test.wait_for_idle = mock.MagicMock()
@@ -60,7 +62,8 @@ class TestAssetProcessor(object):
under_test.start(connect_to_ap=True)
assert under_test._ap_proc is not None
mock_popen.assert_called_once_with([mock_ap_path, '--zeroAnalysisMode', '--regset="/Amazon/AzCore/Bootstrap/project_path=AutomatedTesting"',
mock_popen.assert_called_once_with([mock_ap_path, '--zeroAnalysisMode',
f'--regset="/Amazon/AzCore/Bootstrap/project_path={mock_project_path}"',
'--logDir', under_test.log_root(),
'--acceptInput', '--platforms', 'bar'], cwd=os.path.dirname(mock_ap_path))
mock_connect.assert_called()
@@ -107,20 +110,24 @@ class TestAssetProcessor(object):
@mock.patch('subprocess.run')
def test_BatchProcess_NoFastscanBatchCompletes_Success(self, mock_run, mock_workspace):
mock_workspace.project = None
mock_workspace.paths.project.return_value = mock_project_path
under_test = ly_test_tools.lumberyard.asset_processor.AssetProcessor(mock_workspace)
apb_path = mock_workspace.paths.asset_processor_batch()
mock_run.return_value.returncode = 0
result, _ = under_test.batch_process(1, False)
assert result
mock_run.assert_called_once_with([apb_path, '--logDir', under_test.log_root()],
mock_run.assert_called_once_with([apb_path,
f'--regset="/Amazon/AzCore/Bootstrap/project_path={mock_project_path}"',
'--logDir', under_test.log_root()],
close_fds=True, capture_output=False,
timeout=1)
@mock.patch('ly_test_tools._internal.managers.workspace.AbstractWorkspaceManager')
@mock.patch('subprocess.run')
def test_BatchProcess_FastscanBatchCompletes_Success(self, mock_run, mock_workspace):
mock_workspace.project = 'AutomatedTesting'
mock_workspace.project = mock_project
mock_workspace.paths.project.return_value = mock_project_path
under_test = ly_test_tools.lumberyard.asset_processor.AssetProcessor(mock_workspace)
apb_path = mock_workspace.paths.asset_processor_batch()
mock_run.return_value.returncode = 0
@@ -128,18 +135,18 @@ class TestAssetProcessor(object):
result = under_test.batch_process(1, True)
assert result
mock_run.assert_called_once_with(
[apb_path, '--zeroAnalysisMode', '--regset="/Amazon/AzCore/Bootstrap/project_path=AutomatedTesting"',
'--logDir',
under_test.log_root()],
mock_run.assert_called_once_with([apb_path, '--zeroAnalysisMode',
f'--regset="/Amazon/AzCore/Bootstrap/project_path={mock_project_path}"',
'--logDir', under_test.log_root()],
close_fds=True, capture_output=False,
timeout=1)
close_fds=True, capture_output=False,
timeout=1)
@mock.patch('ly_test_tools._internal.managers.workspace.AbstractWorkspaceManager')
@mock.patch('subprocess.run')
def test_BatchProcess_ReturnCodeFail_Failure(self, mock_run, mock_workspace):
mock_workspace.project = None
mock_workspace.paths.project.return_value = mock_project_path
under_test = ly_test_tools.lumberyard.asset_processor.AssetProcessor(mock_workspace)
apb_path = mock_workspace.paths.asset_processor_batch()
mock_run.return_value.returncode = 1
@@ -147,9 +154,12 @@ class TestAssetProcessor(object):
result, _ = under_test.batch_process(None, False)
assert not result
mock_run.assert_called_once_with([apb_path, '--logDir', under_test.log_root()],
mock_run.assert_called_once_with([apb_path,
f'--regset="/Amazon/AzCore/Bootstrap/project_path={mock_project_path}"',
'--logDir', under_test.log_root()],
close_fds=True, capture_output=False, timeout=28800.0)
@mock.patch('ly_test_tools._internal.managers.workspace.AbstractWorkspaceManager')
def test_EnableAssetProcessorPlatform_AssetProcessorObject_Updated(self, mock_workspace):
under_test = ly_test_tools.lumberyard.asset_processor.AssetProcessor(mock_workspace)
@@ -102,7 +102,7 @@ class TestBuiltinHelpers(object):
under_test = ly_test_tools._internal.managers.abstract_resource_locator._find_engine_root(
initial_path='mock_dev_dir')
assert under_test == ('mock_base_dir', 'mock_dev_dir')
assert under_test == ('mock_dev_dir')
@mock.patch('os.path.abspath', mock.MagicMock(return_value='mock_base_dir'))
@mock.patch('os.path.exists', mock.MagicMock(return_value=False))
@@ -113,7 +113,6 @@ class TestBuiltinHelpers(object):
@mock.patch('ly_test_tools._internal.managers.workspace.AbstractWorkspaceManager.setup')
@mock.patch('ly_test_tools._internal.managers.artifact_manager.NullArtifactManager', mock.MagicMock())
@mock.patch('ly_test_tools.builtin.helpers.setup_bootstrap_project', mock.MagicMock(return_value=None))
@mock.patch('os.path.exists', mock.MagicMock(return_value=True))
def test_SetupBuiltinWorkspace_ValidWorkspaceSetup_ReturnsWorkspaceObject(self, mock_setup):
mock_test_name = 'mock_test_name'
@@ -39,7 +39,7 @@ class MockedWorkspace(object):
self.shader_compiler = mock.MagicMock()
self.settings = mock.MagicMock()
self.paths.dev.return_value = 'dev_path'
self.paths.engine_root.return_value = 'engine_path'
self.paths.build_directory.return_value = 'build_directory'
self.paths.autoexec_file.return_value = 'autoexec.cfg'
@@ -45,7 +45,7 @@ class TestMacResourceLocator(object):
def test_PlatformConfigFile_HasPath_ReturnsPath(self):
expected = os.path.join(
mac_resource_locator.dev(),
mac_resource_locator.engine_root(),
CONFIG_FILE)
assert mac_resource_locator.platform_config_file() == expected
@@ -51,7 +51,7 @@ class TestWindowsResourceLocator(object):
def test_PlatformConfigFile_HasPath_ReturnsPath(self):
expected = os.path.join(
windows_resource_locator.dev(),
windows_resource_locator.engine_root(),
CONFIG_FILE)
assert windows_resource_locator.platform_config_file() == expected
@@ -158,3 +158,95 @@ class TestReplaceLineInFile(unittest.TestCase):
ly_test_tools.lumberyard.settings._edit_text_settings_file(self.file_name, 'Setting5', 'NewSetting!')
mock_stdout.assert_has_calls(expected_print_lines)
class TestJsonSettings(unittest.TestCase):
def setUp(self):
self.test_file_name = 'something.json'
self.mock_file_content = """
{
"name": "Foo",
"weight": 30,
"scale": {
"x": 1,
"y": 2,
"z": 3
},
" ":"secret",
"": 0
}"""
def test_ReadJson_RetrieveKey_Success(self,):
mock_open = mock.mock_open(read_data=self.mock_file_content)
with mock.patch('builtins.open', mock_open):
with ly_test_tools.lumberyard.settings.JsonSettings(self.test_file_name) as js:
# get the whole document
value = js.get_key('')
assert len(value) == 5
# get a nested key
value = js.get_key('/scale/x')
assert value == 1
# get the " " key ad the root level
value = js.get_key('/ ')
assert value == 'secret'
# get the "" key at the root level
value = js.get_key('/')
assert value == 0
def test_ReadJson_RetrieveMissingKey_DefaultReturned(self):
mock_open = mock.mock_open(read_data=self.mock_file_content)
default_value = -10
with mock.patch('builtins.open', mock_open):
with ly_test_tools.lumberyard.settings.JsonSettings(self.test_file_name) as js:
value = js.get_key('/scale/w', default_value)
assert value == default_value
def test_ReadJson_ModifyKey_KeyModified(self):
mock_open = mock.mock_open(read_data=self.mock_file_content)
expected = 100
with mock.patch('builtins.open', mock_open):
with ly_test_tools.lumberyard.settings.JsonSettings(self.test_file_name) as js:
js.set_key('/scale/x', expected)
value = js.get_key('/scale/x')
assert value == expected
@mock.patch('json.dump')
def test_WriteJson_ModifyKey_KeyModified(self, json_dump):
mock_open = mock.mock_open(read_data=self.mock_file_content)
expected = "this is the new value"
new_dict_content = None
def _mock_dump(content, file_path, indent):
nonlocal new_dict_content
new_dict_content = content
json_dump.side_effect = _mock_dump
with mock.patch('builtins.open', mock_open):
with ly_test_tools.lumberyard.settings.JsonSettings(self.test_file_name) as js:
js.set_key('/name', expected)
assert expected == new_dict_content['name']
@mock.patch('json.dump')
def test_WriteJson_RemoveKey_KeyRemoved(self, json_dump):
mock_open = mock.mock_open(read_data=self.mock_file_content)
new_dict_content = None
def _mock_dump(content, file_path, indent):
nonlocal new_dict_content
new_dict_content = content
json_dump.side_effect = _mock_dump
with mock.patch('builtins.open', mock_open):
with ly_test_tools.lumberyard.settings.JsonSettings(self.test_file_name) as js:
js.remove_key('/scale/z')
assert len(new_dict_content['scale']) == 2