From cee194f44d3a6fc0e25836132b33680a47deb4a0 Mon Sep 17 00:00:00 2001 From: Romulo Quidute Filho Date: Wed, 29 Nov 2023 13:29:22 +0000 Subject: [PATCH] Code changed after code review --- app/chip_tool/chip_tool.py | 21 +++++++++++-------- app/chip_tool/test_suite.py | 1 - app/tests/chip_tool/test_chip_tool.py | 1 - .../python_tests/test_python_test_suite.py | 11 ---------- .../models/python_test_models.py | 4 +++- .../models/python_test_parser.py | 3 ++- .../models/python_testing_hooks_proxy.py | 2 +- .../models/rpc_client/test_harness_client.py | 8 ++++--- .../python_testing/models/test_case.py | 12 +++++------ .../python_testing/models/test_suite.py | 16 -------------- .../yaml_tests/models/yaml_test_models.py | 2 +- 11 files changed, 30 insertions(+), 51 deletions(-) diff --git a/app/chip_tool/chip_tool.py b/app/chip_tool/chip_tool.py index d2198eb4..35d5a588 100644 --- a/app/chip_tool/chip_tool.py +++ b/app/chip_tool/chip_tool.py @@ -108,14 +108,16 @@ "sdk_runner/specifications/chip/" ) # Python Testing Folder -# LOCAL_PYTHON_TESTING_PATH = TEST_COLLECTION_SDK_CHECKOUT_PATH / Path( -# "python_testing/scripts/sdk" -# ) -# DOCKER_PYTHON_TESTING_PATH = "/root/python_testing" +LOCAL_TEST_COLLECTIONS_PATH = "/home/ubuntu/certification-tool/backend/test_collections" +LOCAL_PYTHON_TESTING_PATH = Path( + LOCAL_TEST_COLLECTIONS_PATH + "/sdk_tests/sdk_checkout/python_testing/scripts/sdk" +) +DOCKER_PYTHON_TESTING_PATH = "/root/python_testing" # RPC Client Running on SDK Container LOCAL_RPC_PYTHON_TESTING_PATH = Path( - "/home/ubuntu/certification-tool/backend/test_collections/sdk_tests/support/python_testing/models/rpc_client/test_harness_client.py" + LOCAL_TEST_COLLECTIONS_PATH + "/sdk_tests/support/python_testing/models/rpc_client/" + "test_harness_client.py" ) DOCKER_RPC_PYTHON_TESTING_PATH = "/root/python_testing/test_harness_client.py" @@ -143,7 +145,6 @@ class ChipToolUnknownTestType(Exception): class ChipToolTestType(str, Enum): CHIP_TOOL = "chip-tool" CHIP_APP = "chip-app" - PYTHON_TEST = "python-test" class ChipTool(metaclass=Singleton): @@ -180,6 +181,10 @@ class ChipTool(metaclass=Singleton): "bind": DOCKER_CREDENTIALS_DEVELOPMENT_PATH, "mode": "ro", }, + LOCAL_PYTHON_TESTING_PATH: { + "bind": DOCKER_PYTHON_TESTING_PATH, + "mode": "rw", + }, LOCAL_RPC_PYTHON_TESTING_PATH: { "bind": DOCKER_RPC_PYTHON_TESTING_PATH, "mode": "rw", @@ -412,8 +417,6 @@ async def start_server( async def destroy_device(self) -> None: """Destroy the device container.""" - await self.stop_chip_tool_server() - if self.__chip_tool_container is not None: container_manager.destroy(self.__chip_tool_container) self.__chip_tool_container = None @@ -607,7 +610,7 @@ async def run_test( if test_type == ChipToolTestType.CHIP_TOOL: test_path = f"{YAML_TESTS_PATH}/{test_id}.yaml" - elif test_type == ChipToolTestType.CHIP_APP: + else: test_path = f"{YAML_TESTS_PATH}/{test_id}_Simulated.yaml" parser_config = TestParserConfig(pics_path, self.specifications, test_options) diff --git a/app/chip_tool/test_suite.py b/app/chip_tool/test_suite.py index bed94057..e548427d 100644 --- a/app/chip_tool/test_suite.py +++ b/app/chip_tool/test_suite.py @@ -280,4 +280,3 @@ async def __prompt_user_to_perform_decommission(self) -> None: f"Received unknown prompt option for \ decommissioning step: {prompt_response.response}" ) - diff --git a/app/tests/chip_tool/test_chip_tool.py b/app/tests/chip_tool/test_chip_tool.py index 2c64a843..ae8f522d 100644 --- a/app/tests/chip_tool/test_chip_tool.py +++ b/app/tests/chip_tool/test_chip_tool.py @@ -988,4 +988,3 @@ async def test_pairing_ble_thread_command_params() -> None: # clean up: chip_tool._ChipTool__chip_tool_container = None settings.CHIP_TOOL_TRACE = original_trace_setting_value - diff --git a/app/tests/python_tests/test_python_test_suite.py b/app/tests/python_tests/test_python_test_suite.py index 5a230bab..acdbaccb 100644 --- a/app/tests/python_tests/test_python_test_suite.py +++ b/app/tests/python_tests/test_python_test_suite.py @@ -24,7 +24,6 @@ from app.models.test_suite_execution import TestSuiteExecution from app.test_engine.logger import test_engine_logger from test_collections.sdk_tests.support.python_testing.models.test_suite import ( - ChipToolPythonTestSuite, PythonTestSuite, SuiteType, ) @@ -58,16 +57,6 @@ def test_python_test_suite_python_version() -> None: assert suite_class.python_test_version == python_test_version -def test_automated_suite_subclass() -> None: - """Test that for suite type automated class factory creates a subclass of - ChipToolPythonTestSuite, and that test_type is set to CHIP_TOOL""" - type = SuiteType.AUTOMATED - # Create a subclass of PythonTestSuite - suite_class: Type[PythonTestSuite] = PythonTestSuite.class_factory( - suite_type=type, name="SomeSuite", python_test_version="some_version" - ) - - @pytest.mark.asyncio async def test_suite_setup_log_python_version() -> None: """Test that test suite python version is logged to test engine logger in setup.""" diff --git a/test_collections/sdk_tests/support/python_testing/models/python_test_models.py b/test_collections/sdk_tests/support/python_testing/models/python_test_models.py index a8e8bc4d..26c52cf8 100644 --- a/test_collections/sdk_tests/support/python_testing/models/python_test_models.py +++ b/test_collections/sdk_tests/support/python_testing/models/python_test_models.py @@ -23,6 +23,8 @@ class PythonTest(MatterTest): + description: str + def __init__(self, **kwargs: Any) -> None: super().__init__(**kwargs) - self.type: MatterTestType.AUTOMATED # type: ignore + self.type = MatterTestType.AUTOMATED diff --git a/test_collections/sdk_tests/support/python_testing/models/python_test_parser.py b/test_collections/sdk_tests/support/python_testing/models/python_test_parser.py index 3c048492..455cd025 100644 --- a/test_collections/sdk_tests/support/python_testing/models/python_test_parser.py +++ b/test_collections/sdk_tests/support/python_testing/models/python_test_parser.py @@ -82,7 +82,8 @@ def __parse_test_case_from_class( ) from si return PythonTest( - name=tc_desc, + name=tc_name, + description=tc_desc, steps=tc_steps, config=tc_config, PICS=tc_pics, diff --git a/test_collections/sdk_tests/support/python_testing/models/python_testing_hooks_proxy.py b/test_collections/sdk_tests/support/python_testing/models/python_testing_hooks_proxy.py index 5dce6255..1f563839 100644 --- a/test_collections/sdk_tests/support/python_testing/models/python_testing_hooks_proxy.py +++ b/test_collections/sdk_tests/support/python_testing/models/python_testing_hooks_proxy.py @@ -42,7 +42,7 @@ def start(self, count: int) -> None: def stop(self, duration: int) -> None: self.results.put({"stop": {"duration": duration}}) - self.is_finished = True + SDKPythonTestRunnerHooks.finished = True def test_start(self, filename: str, name: str, count: int) -> None: self.results.put( diff --git a/test_collections/sdk_tests/support/python_testing/models/rpc_client/test_harness_client.py b/test_collections/sdk_tests/support/python_testing/models/rpc_client/test_harness_client.py index 415083cf..43c70cbf 100644 --- a/test_collections/sdk_tests/support/python_testing/models/rpc_client/test_harness_client.py +++ b/test_collections/sdk_tests/support/python_testing/models/rpc_client/test_harness_client.py @@ -19,7 +19,7 @@ import sys from multiprocessing.managers import BaseManager -from matter_testing_support import MatterTestConfig, run_tests +import matter_testing_support try: from matter_yamltests.hooks import TestRunnerHooks @@ -33,7 +33,7 @@ class TestRunnerHooks: # Pre-computed param list for each Python Test as defined in Verification Steps. test_params = { - "TC_ACE_1_3": MatterTestConfig( + "TC_ACE_1_3": matter_testing_support.MatterTestConfig( tests=["test_TC_ACE_1_3"], commissioning_method="on-network", discriminators=[3840], @@ -46,6 +46,8 @@ class TestRunnerHooks: def main(): + sys.path.append("/root/python_testing") + if len(sys.argv) != 2: raise Exception("Python test id should be provided as the only parameter.") @@ -64,7 +66,7 @@ def main(): manager.connect() test_runner_hooks = manager.TestRunnerHooks() # shared object proxy - run_tests(TestClassReference, config, test_runner_hooks) + matter_testing_support.run_tests(TestClassReference, config, test_runner_hooks) if __name__ == "__main__": diff --git a/test_collections/sdk_tests/support/python_testing/models/test_case.py b/test_collections/sdk_tests/support/python_testing/models/test_case.py index 83fd8f3e..ea1ce989 100644 --- a/test_collections/sdk_tests/support/python_testing/models/test_case.py +++ b/test_collections/sdk_tests/support/python_testing/models/test_case.py @@ -39,7 +39,7 @@ # Command line params RUNNER_CLASS = "test_harness_client.py" -RUNNER_CLASS_PATH = "/root/python_testing/rpc_client/" +RUNNER_CLASS_PATH = "/root/python_testing/" EXECUTABLE = "python3" @@ -59,6 +59,7 @@ class PythonTestCase(TestCase): def __init__(self, test_case_execution: TestCaseExecution) -> None: super().__init__(test_case_execution=test_case_execution) self.chip_tool: ChipTool + self.__runned = 0 def start(self, count: int) -> None: pass @@ -177,7 +178,7 @@ def class_factory(cls, test: PythonTest, python_test_version: str) -> Type[T]: @classmethod def __class_factory(cls, test: PythonTest, python_test_version: str) -> Type[T]: """Common class factory method for all subclasses of PythonTestCase.""" - identifier = cls.__test_identifier(test.name) + identifier = test.name class_name = cls.__class_name(identifier) title = identifier @@ -189,10 +190,10 @@ def __class_factory(cls, test: PythonTest, python_test_version: str) -> Type[T]: "python_test_version": python_test_version, "chip_tool_test_identifier": class_name, "metadata": { - "public_id": identifier, + "public_id": test.name, "version": "0.0.1", "title": title, - "description": test.name, + "description": test.description, }, }, ) @@ -239,7 +240,7 @@ async def execute(self) -> None: continue self.__handle_update(update) - await sleep(0.1) + await sleep(0.001) finally: pass @@ -257,7 +258,6 @@ def __call_function_from_name(self, obj, func_name, kwargs) -> None: # type: ig async def cleanup(self) -> None: logger.info("Test Cleanup") - self.chip_tool.destroy_device() class PythonChipToolTestCase(PythonTestCase): diff --git a/test_collections/sdk_tests/support/python_testing/models/test_suite.py b/test_collections/sdk_tests/support/python_testing/models/test_suite.py index f2c25b95..9b3753f6 100644 --- a/test_collections/sdk_tests/support/python_testing/models/test_suite.py +++ b/test_collections/sdk_tests/support/python_testing/models/test_suite.py @@ -47,16 +47,6 @@ def class_factory( cls, suite_type: SuiteType, name: str, python_test_version: str ) -> Type[T]: """Dynamically declares a subclass based on the type of test suite.""" - suite_class = ChipToolPythonTestSuite - - return suite_class.__class_factory( - name=name, python_test_version=python_test_version - ) - - @classmethod - def __class_factory(cls, name: str, python_test_version: str) -> Type[T]: - """Common class factory method for all subclasses of PythonTestSuite.""" - return type( name, (cls,), @@ -71,9 +61,3 @@ def __class_factory(cls, name: str, python_test_version: str) -> Type[T]: }, }, ) - - -class ChipToolPythonTestSuite(PythonTestSuite): - async def setup(self) -> None: - """Due top multi inheritance, we need to call setup on both super classes.""" - await PythonTestSuite.setup(self) diff --git a/test_collections/sdk_tests/support/yaml_tests/models/yaml_test_models.py b/test_collections/sdk_tests/support/yaml_tests/models/yaml_test_models.py index be5208d2..e1d43e37 100644 --- a/test_collections/sdk_tests/support/yaml_tests/models/yaml_test_models.py +++ b/test_collections/sdk_tests/support/yaml_tests/models/yaml_test_models.py @@ -27,4 +27,4 @@ class YamlTest(YamlModelMixin, MatterTest): def __init__(self, **kwargs: Any) -> None: super().__init__(steps=kwargs["tests"], **kwargs) - self.type: MatterTestType.MANUAL # type: ignore + self.type = MatterTestType.MANUAL