Skip to content

Commit

Permalink
[matter_yamltests] Add an implicit rule that the key 'value' in argum… (
Browse files Browse the repository at this point in the history
#28068)

* [matter_yamltests] Add an implicit rule that the key 'value' in arguments can not be used if the command is not a 'writeAttribute'

* Update scripts/py_matter_yamltests/matter_yamltests/errors.py

---------

Co-authored-by: Boris Zbarsky <[email protected]>
  • Loading branch information
2 people authored and pull[bot] committed Mar 1, 2024
1 parent 0fd747d commit 16b83fc
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 5 deletions.
12 changes: 12 additions & 0 deletions scripts/py_matter_yamltests/matter_yamltests/errors.py
Original file line number Diff line number Diff line change
Expand Up @@ -198,3 +198,15 @@ def __init__(self, content):
super().__init__(message)

self.tag_key_with_error(content, 'response')


class TestStepArgumentsValueError(TestStepError):
"""Raise when a test step arguments use the 'value' keyword but the command is not trying to write to an attribute"""

def __init__(self, content):
message = 'The "value" key can not be used in conjuction with a command that is not "writeAttribute"'
super().__init__(message)

self.tag_key_with_error(content, 'command')
arguments = content.get('arguments')
self.tag_key_with_error(arguments, 'value')
14 changes: 11 additions & 3 deletions scripts/py_matter_yamltests/matter_yamltests/yaml_loader.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@

from typing import Tuple, Union

from .errors import (TestStepError, TestStepGroupEndPointError, TestStepGroupResponseError, TestStepInvalidTypeError,
TestStepKeyError, TestStepNodeIdAndGroupIdError, TestStepResponseVariableError, TestStepValueAndValuesError,
TestStepVerificationStandaloneError, TestStepWaitResponseError)
from .errors import (TestStepArgumentsValueError, TestStepError, TestStepGroupEndPointError, TestStepGroupResponseError,
TestStepInvalidTypeError, TestStepKeyError, TestStepNodeIdAndGroupIdError, TestStepResponseVariableError,
TestStepValueAndValuesError, TestStepVerificationStandaloneError, TestStepWaitResponseError)
from .fixes import add_yaml_support_for_scientific_notation_without_dot

try:
Expand Down Expand Up @@ -120,6 +120,7 @@ def __check_test_step(self, config: dict, content):
content)
self.__rule_wait_should_not_expect_a_response(content)
self.__rule_response_variable_should_exist_in_config(config, content)
self.__rule_argument_value_is_only_when_writing_attributes(content)

if 'arguments' in content:
arguments = content.get('arguments')
Expand Down Expand Up @@ -260,3 +261,10 @@ def __rule_response_variable_should_exist_in_config(self, config, content):
response = content.get('response')
if isinstance(response, str) and response not in config:
raise TestStepResponseVariableError(content)

def __rule_argument_value_is_only_when_writing_attributes(self, content):
if 'arguments' in content:
command = content.get('command')
arguments = content.get('arguments')
if 'value' in arguments and command != 'writeAttribute':
raise TestStepArgumentsValueError(content)
6 changes: 4 additions & 2 deletions scripts/py_matter_yamltests/test_yaml_loader.py
Original file line number Diff line number Diff line change
Expand Up @@ -267,7 +267,8 @@ def test_key_tests_step_dict_keys(self):
load = YamlLoader().load

content = ('tests:\n'
' - {key}: {value}')
' - command: writeAttribute\n'
' {key}: {value}')
keys = [
'arguments',
]
Expand All @@ -278,7 +279,8 @@ def test_key_tests_step_dict_keys(self):
for key in keys:
_, _, _, _, tests = load(
content.format(key=key, value=valid_value))
self.assertEqual(tests, [{key: {'value': True}}])
self.assertEqual(
tests, [{'command': 'writeAttribute', key: {'value': True}}])

for value in wrong_values:
x = content.format(key=key, value=value)
Expand Down

0 comments on commit 16b83fc

Please sign in to comment.