From 017845e285e7fb58996abac4164ddcaf9d007541 Mon Sep 17 00:00:00 2001 From: evanchia Date: Wed, 16 Jun 2021 11:29:14 -0700 Subject: [PATCH] fixing project() func to read project.json --- .../managers/abstract_resource_locator.py | 15 +++++++++------ .../tests/unit/test_abstract_resource_locator.py | 5 +++-- 2 files changed, 12 insertions(+), 8 deletions(-) diff --git a/Tools/LyTestTools/ly_test_tools/_internal/managers/abstract_resource_locator.py b/Tools/LyTestTools/ly_test_tools/_internal/managers/abstract_resource_locator.py index c1a22e5641..a7a1c867f6 100755 --- a/Tools/LyTestTools/ly_test_tools/_internal/managers/abstract_resource_locator.py +++ b/Tools/LyTestTools/ly_test_tools/_internal/managers/abstract_resource_locator.py @@ -63,12 +63,15 @@ def _find_project_json(engine_root, project): # Look at the "projects" key for registered project paths try: for projects_path in json_data["projects"]: - # Only look at project directories that match our project - if project == os.path.basename(projects_path): - check_project_json = os.path.join(projects_path, 'project.json') - # Check for the project.json file inside of the project directory - if os.path.isfile(check_project_json): - project_json = check_project_json + check_project_json = os.path.join(projects_path, 'project.json') + # Check for the project.json file inside of the project directory + if os.path.isfile(check_project_json): + # Check if the "project_name" key matches our project + with open(check_project_json, "r") as project_json_file: + project_json_data = json.load(project_json_file) + if project == project_json_data["project_name"]: + project_json = check_project_json + break except KeyError: pass # No projects found in the manifest json diff --git a/Tools/LyTestTools/tests/unit/test_abstract_resource_locator.py b/Tools/LyTestTools/tests/unit/test_abstract_resource_locator.py index a96f2a0699..d8e4e5a14a 100755 --- a/Tools/LyTestTools/tests/unit/test_abstract_resource_locator.py +++ b/Tools/LyTestTools/tests/unit/test_abstract_resource_locator.py @@ -24,7 +24,8 @@ mock_engine_root = "mock_engine_root" mock_dev_path = "mock_dev_path" mock_build_directory = 'mock_build_directory' mock_project = 'mock_project' -mock_manifest_json = {'projects': [mock_project]} +mock_manifest_json_file = {'projects': [mock_project]} +mock_project_json_file = {'project_name': mock_project} mock_project_json = os.path.join(mock_project, 'project.json') @@ -54,7 +55,7 @@ class TestFindProjectJson(object): @mock.patch('os.path.isfile', mock.MagicMock(return_value=True)) @mock.patch('os.path.basename', mock.MagicMock(return_value=mock_project)) - @mock.patch('json.load', mock.MagicMock(return_value=mock_manifest_json)) + @mock.patch('json.load', mock.MagicMock(side_effect=[mock_manifest_json_file, mock_project_json_file])) def test_FindProjectJson_ManifestJson_ReturnsProjectJson(self): project = abstract_resource_locator._find_project_json(mock_engine_root, mock_project)