From e53dc0d8fab1e109ca62d8aae137d44e9030d72f Mon Sep 17 00:00:00 2001 From: Hilton Lima Date: Mon, 16 Sep 2024 13:32:03 +0000 Subject: [PATCH] PR review --- .../list_python_tests_classes.py | 4 +- .../models/rpc_client/test_harness_client.py | 5 +- .../python_testing/sdk_python_tests.py | 52 ++++++++++++++++++- 3 files changed, 54 insertions(+), 7 deletions(-) diff --git a/test_collections/matter/sdk_tests/support/python_testing/list_python_tests_classes.py b/test_collections/matter/sdk_tests/support/python_testing/list_python_tests_classes.py index e4276ab9..230d0885 100644 --- a/test_collections/matter/sdk_tests/support/python_testing/list_python_tests_classes.py +++ b/test_collections/matter/sdk_tests/support/python_testing/list_python_tests_classes.py @@ -25,7 +25,6 @@ ) from test_collections.matter.sdk_tests.support.sdk_container import SDKContainer -# .../test_collections/matter/sdk_tests SDK_TESTS_PATH = Path(__file__).parent.parent.parent PYTHON_TESTING_PATH = SDK_TESTS_PATH / "sdk_checkout/python_testing" JSON_OUTPUT_FILE_PATH = PYTHON_TESTING_PATH / "data.json" @@ -33,6 +32,7 @@ PYTHON_SCRIPTS_PATH = PYTHON_TESTING_PATH / "scripts/sdk" PYTHON_SCRIPTS_FOLDER = SDKTestFolder(path=PYTHON_SCRIPTS_PATH, filename_pattern="TC*") +CONTAINER_GET_TEST_INFO_COMMAND = "--get_test_info" CONTAINER_TH_CLIENT_EXEC = ( "python3 /root/python_testing/scripts/sdk/test_harness_client.py" ) @@ -71,7 +71,7 @@ def get_command_list() -> list: for test_class in test_classes: script_command = [f"{parent_folder}/{python_test_file.stem}"] script_command.append(f"{test_class.name}") - script_command.append("--get_test_info") + script_command.append(CONTAINER_GET_TEST_INFO_COMMAND) python_script_commands.append(script_command) return python_script_commands diff --git a/test_collections/matter/sdk_tests/support/python_testing/models/rpc_client/test_harness_client.py b/test_collections/matter/sdk_tests/support/python_testing/models/rpc_client/test_harness_client.py index 90fe6c9f..a1ecd652 100644 --- a/test_collections/matter/sdk_tests/support/python_testing/models/rpc_client/test_harness_client.py +++ b/test_collections/matter/sdk_tests/support/python_testing/models/rpc_client/test_harness_client.py @@ -50,7 +50,7 @@ def main() -> None: json.dump(info, f, indent=4) print(info) else: - # TODO: find a better solution. This is a temporary workaround since Python Tests + # TODO: find a better solution. This is a temporary workaround since Python Tests # are generating a big amount of log with open("/root/python_testing/test_output.txt", "w") as f: with redirect_stdout(f): @@ -65,8 +65,7 @@ def main() -> None: def get_test_info(script_path: str, class_name: str, config: MatterTestConfig): module = importlib.import_module(script_path.replace("/", ".")) TestClassReference = getattr(module, class_name) - v = get_test_info_support(TestClassReference, config) - return v + return get_test_info_support(TestClassReference, config) def run_test(script_path: str, class_name: str, config: MatterTestConfig) -> None: diff --git a/test_collections/matter/sdk_tests/support/python_testing/sdk_python_tests.py b/test_collections/matter/sdk_tests/support/python_testing/sdk_python_tests.py index 5bd9a620..2b368499 100644 --- a/test_collections/matter/sdk_tests/support/python_testing/sdk_python_tests.py +++ b/test_collections/matter/sdk_tests/support/python_testing/sdk_python_tests.py @@ -13,12 +13,18 @@ # See the License for the specific language governing permissions and # limitations under the License. # +import json from pathlib import Path from typing import Optional +from test_collections.matter.config import matter_settings +from test_collections.matter.sdk_tests.support.models.matter_test_models import ( + MatterTestStep, +) + from ..models.sdk_test_folder import SDKTestFolder -from ..paths import SDK_CHECKOUT_PATH -from .models.python_test_models import PythonTestType +from ..paths import SDK_CHECKOUT_PATH, SDK_TESTS_ROOT +from .models.python_test_models import PythonTest, PythonTestType from .models.python_test_parser import parse_python_script from .models.test_declarations import ( PythonCaseDeclaration, @@ -48,6 +54,10 @@ path=CUSTOM_PYTHON_TEST_PATH, filename_pattern="TC*" ) +PYTHON_TESTS_PARSED_FILE = ( + SDK_TESTS_ROOT / f"python_tests_{matter_settings.SDK_SHA}.json" +) + def _init_test_suites( python_test_version: str, @@ -97,6 +107,44 @@ def __parse_python_tests( ) -> list[PythonSuiteDeclaration]: suites = _init_test_suites(python_test_version) + with open(PYTHON_TESTS_PARSED_FILE, "r") as json_file: + parsed_scripts = json.load(json_file) + + python_tests: list[PythonTest] = [] + + for script in parsed_scripts: + script_info = dict(script) + test_function = script_info["function"] + test_description = script_info["desc"] + test_pics = script_info["pics"] + test_steps = [] + parsed_steps = script_info["steps"] + is_commssioning = False + for index, step in enumerate(parsed_steps): + if index == 1: + is_commssioning = step["is_commissioning"] + + test_steps.append( + MatterTestStep( + label=step["description"], + is_commissioning=is_commssioning, + ) + ) + + python_tests.append( + PythonTest( + name=test_function, + description=test_description, + steps=test_steps, + config={}, # Currently config is not configured in Python Testing + PICS=test_pics, + path=test_command[0], + type=MatterTestType.AUTOMATED, + class_name=test_command[1], + python_test_type=python_test_type, + ) + ) + for python_test_file in python_test_files: test_cases = _parse_python_script_to_test_case_declarations( python_test_path=python_test_file,