From e57d79b2e6d67c21643f520dca987dedcec96c92 Mon Sep 17 00:00:00 2001 From: Vivien Nicolas Date: Mon, 17 Jul 2023 14:49:46 +0200 Subject: [PATCH] [matter_yamltests] Be stricter about the response key for command targetting group and disallow the use of the endpoint key --- .../py_matter_yamltests/matter_yamltests/errors.py | 11 +++++++++++ .../matter_yamltests/yaml_loader.py | 11 +++++++---- 2 files changed, 18 insertions(+), 4 deletions(-) diff --git a/scripts/py_matter_yamltests/matter_yamltests/errors.py b/scripts/py_matter_yamltests/matter_yamltests/errors.py index b6205dad9efabb..e38cc3a4875ff1 100644 --- a/scripts/py_matter_yamltests/matter_yamltests/errors.py +++ b/scripts/py_matter_yamltests/matter_yamltests/errors.py @@ -133,6 +133,17 @@ def __init__(self, content): self.tag_key_with_error(content, 'response') +class TestStepGroupEndPointError(TestStepError): + """Raise when a test step targeting a group of nodes targets an endpoint.""" + + def __init__(self, content): + message = 'Group command should not target an endpoint' + super().__init__(message) + + self.tag_key_with_error(content, 'groupId') + self.tag_key_with_error(content, 'endpoint') + + class TestStepVerificationStandaloneError(TestStepError): """Raise when a test step with a verification key is enabled and not interactive.""" diff --git a/scripts/py_matter_yamltests/matter_yamltests/yaml_loader.py b/scripts/py_matter_yamltests/matter_yamltests/yaml_loader.py index 77bb6d78eff190..c3e668959be58c 100644 --- a/scripts/py_matter_yamltests/matter_yamltests/yaml_loader.py +++ b/scripts/py_matter_yamltests/matter_yamltests/yaml_loader.py @@ -15,7 +15,7 @@ from typing import Tuple, Union -from .errors import (TestStepError, TestStepGroupResponseError, TestStepInvalidTypeError, TestStepKeyError, +from .errors import (TestStepError, TestStepGroupResponseError, TestStepGroupEndPointError, TestStepInvalidTypeError, TestStepKeyError, TestStepNodeIdAndGroupIdError, TestStepResponseVariableError, TestStepValueAndValuesError, TestStepVerificationStandaloneError, TestStepWaitResponseError) from .fixes import add_yaml_support_for_scientific_notation_without_dot @@ -115,6 +115,7 @@ def __check_test_step(self, config: dict, content): self.__check(content, schema) self.__rule_node_id_and_group_id_are_mutually_exclusive(content) self.__rule_group_step_should_not_expect_a_response(content) + self.__rule_group_step_should_not_target_an_endpoint(content) self.__rule_step_with_verification_should_be_disabled_or_interactive( content) self.__rule_wait_should_not_expect_a_response(content) @@ -233,9 +234,11 @@ def __rule_node_id_and_group_id_are_mutually_exclusive(self, content): def __rule_group_step_should_not_expect_a_response(self, content): if 'groupId' in content and 'response' in content: - response = content.get('response') - if 'value' in response or 'values' in response: - raise TestStepGroupResponseError(content) + raise TestStepGroupResponseError(content) + + def __rule_group_step_should_not_target_an_endpoint(self, content): + if 'groupId' in content and 'endpoint' in content: + raise TestStepGroupEndPointError(content) def __rule_step_with_verification_should_be_disabled_or_interactive(self, content): if 'verification' in content: